Similar shape, different aggregation
Standard attention softmax-normalizes scores across each row. HSTU includes pointwise activated aggregation: transform biased scores with a function such as SiLU, aggregate V, then normalize and gate. Without sequence-wise softmax, the weight matrix is not a probability distribution.
Our single-head teaching equation is , followed by . The demo uses fixed sequence length N. Check official code for actual scaling, head layout, bias and normalization.
Trace four projections
Normalized [B,T,D] inputs produce U/V/Q/K projections. Q/K match positions, V supplies aggregated values and U gates the output. Q/K head dimensions can differ from U/V dimensions. Fusing projections can reduce operator overhead, but the split must match weight layout.
import torch
import torch.nn.functional as F
q, k, v = [torch.randn(1,4,8) for _ in range(3)]
mask = torch.ones(4,4,dtype=torch.bool).tril()
a = F.silu(q @ k.transpose(-2,-1)) / 4
a = a.masked_fill(~mask, 0)
y = a @ v
print(a.sum(-1)) # Not required to equal one.
SiLU can produce negative coefficients. Probability entropy cannot be applied directly to this matrix without defining a different meaningful measure.
Temporal bias is not simply fixed forgetting
Relative positions and elapsed time distinguish three consecutive events from three events spread over months. Real bias parameterization includes learned implementation-specific details. The interactive bias is deliberately simple and is not the paper's complete construction.
Increasing α can make old-position weights negative. Combined with normalization and gating, effects on outputs need not be monotonic. Inspect outputs and ablations rather than guessing recommendation behavior from heatmap colors.
Check your understanding
Question: Does replacing softmax with SiLU fully implement HSTU?
Answer
No. Data formulation, projections, gating, normalization, temporal/position bias and system optimizations also matter. The notebook is explicitly HSTU-inspired teaching code, not a complete reproduction.Primary sources and further reading
Sources checked on 2026-09-10. Teaching examples are not production benchmarks; confirm APIs and model support against the linked version.
INTERACTIVE LAB · LIVE NUMERICAL COMPUTATION
HSTU-style aggregation need not sum to one
Fixed 2D Q/K, a causal mask and teaching bias −α(i−j). Displaying SiLU(QKᵀ+bias)/4; full HSTU also includes U/V projections, normalization, gating and a residual.
| Q / K | t0 | t1 | t2 | t3 |
|---|---|---|---|---|
| t0 | 0.183 | 0.000 | 0.000 | 0.000 |
| t1 | -0.047 | 0.183 | 0.000 | 0.000 |
| t2 | 0.000 | 0.078 | 0.440 | 0.000 |
| t3 | -0.047 | -0.047 | -0.067 | 0.243 |
Row sums: 0.183 / 0.136 / 0.518 / 0.081
Increasing α can make earlier positions negative, rather than simply less probable. Softmax entropy analysis does not apply to this matrix.
Inspect tensors, run experiments, and check the stated environment and execution status in the first cell.
Open in Colab ↗Download notebook