← All writingHSTU, from actions to generative recommendation · 02

HSTU tensor by tensor: SiLU aggregation, temporal bias and gating

Compare softmax attention with pointwise aggregation and trace U/Q/K/V, normalization and residual paths.

阅读中文版 →

HSTU tensor by tensor: SiLU aggregation, temporal bias and gating

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?

AnswerNo. 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.

Weights may be negative; these are not probabilities
Q / Kt0t1t2t3
t00.1830.0000.0000.000
t1-0.0470.1830.0000.000
t20.0000.0780.4400.000
t3-0.047-0.047-0.0670.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.

Companion notebook

Inspect tensors, run experiments, and check the stated environment and execution status in the first cell.

Open in Colab ↗Download notebook