Sequence models · Recommendation systems

From transformer parallelism to HSTU

Why transformers parallelize over sequence positions and what that has to do with the loss function; how sparse and dense features actually enter an attention mechanism in a recommender; and how Meta's Generative Recommenders framework builds both retrieval and ranking on one backbone.

Technical walkthrough Worked numeric examples throughout Math rendered with KaTeX

This page walks a single thread from one end to the other: why the transformer's training-time parallelism exists, what the per-position loss has to do with it, and how that machinery gets adapted to recommendation — a domain with billion-scale vocabularies, heterogeneous features, and a hard inference budget. The destination is HSTU, but the route matters more than the destination.

Everything is built up from first principles with concrete numbers. If you already know why attention is a matmul, skip to §2.

Part OneWhy transformers parallelize

1.1  The RNN bottleneck

A recurrent network computes its hidden state as

$$h_t = f(h_{t-1},\; x_t)$$

Position t literally cannot be computed until position t−1 exists. For a sequence of length N, the dependency chain has depth N. You may have ten thousand cores idle; it does not help. The critical path is serial by construction.

This is not a fixable implementation detail. It's the semantics of the model.

1.2  Attention as one matrix multiply

Self-attention replaces the recurrence with a direct all-pairs comparison. Given $X \in \mathbb{R}^{N \times d}$, project to queries, keys, values, then:

$$\text{Attn}(X) = \text{softmax}\!\left(\frac{QK^{\top}}{\sqrt{d_k}} + M\right)V$$

$QK^{\top}$ is a single $N \times N$ matrix multiply. Every position's score against every other position is computed in one shot. There is no loop.

Causality is restored by the mask $M$, which is $0$ on and below the diagonal and $-\infty$ above it. After softmax, the $-\infty$ entries become exactly zero.

Rows are queries (position i), columns are keys (position j). A filled cell means position i is allowed to attend to position j. Everything above the diagonal is $-\infty$ before the softmax and $0$ after it.

The whole matrix is still computed. The mask only zeroes the illegal half — it does not save work, and in a naive implementation you pay for all $N^2$ entries.

The causal mask for N = 6. Parallelism and causality coexist because the constraint is enforced inside a dense operation rather than by a loop around it.

The second ingredient is teacher forcing. During training you feed the model the true previous tokens, not its own predictions. If you fed back predictions, position t would depend on the model's output at t−1 and you'd be right back in the serial regime. Teacher forcing is what makes the inputs available up front.

Intuition

Both ingredients are necessary and neither is sufficient. The mask without teacher forcing still leaves you generating one token at a time. Teacher forcing without the mask lets position 3 peek at position 7 and the model learns nothing useful. Together they let you compute a causally-valid forward pass for all N positions simultaneously.

1.3  The loss over a sequence is the whole point

Here is the part that turns parallelism into an actual training advantage.

One forward pass emits N output vectors — one per position. Each is trained to predict the next token. So you compute cross-entropy at every position and average:

$$\mathcal{L} = -\frac{1}{N}\sum_{t=0}^{N-1} \log P_\theta\!\left(x_{t+1} \mid x_{\leq t}\right)$$

A length-2048 sequence is not one training example. It is 2048 next-token prediction examples that share computation. Backprop then flows through the entire graph in one pass, and gradients from every position accumulate into the same shared weights.

Worked example

A user's viewing history, five items:

InceptionInterstellarArrivalDuneBlade Runner 2049

Targets, position by position:

→ Interstellar→ Arrival→ Dune→ Blade Runner→ ∅

Four usable supervised signals from one forward pass. The last position has no target and is masked out of the loss. Nothing here required five separate examples, five history re-encodings, or five backward passes.

Compare the alternative. A classic two-tower recommender typically builds one (user, item) pair per training example and re-encodes the user's history from scratch for each. Same data, a fraction of the supervision per unit of compute. This gap is a large part of why sequential formulations scale so well, and we'll return to it in §4.2.

1.4  Work vs. depth: is it actually cheaper?

A natural question: if you generated tokens one at a time during training instead, would it cost more? The honest answer is roughly the same total arithmetic, dramatically different wall-clock time. This is the classic work-versus-depth distinction from parallel algorithms.

Work

Sequential generation with a KV cache: at step t you compute one query and attend to t cached keys, costing $O(t \cdot d)$. Summing over the sequence:

$$\sum_{t=0}^{N-1} t \cdot d \;=\; \frac{N(N-1)}{2}d \;=\; O(N^2 d)$$

Identical order to the parallel form's $N \times N$ score matrix. The feed-forward block is $O(d^2)$ per step times N steps, so $O(Nd^2)$ — also identical. Without a cache, recomputing every previous state at each step, you'd get $O(N^3 d)$, which is strictly worse.

Depth

Parallel training has a dependency chain of length L (the number of layers). Sequential has $N \times L$. For $N = 2048$ that's a 2048× longer critical path. But the depth argument, bad as it is, isn't even the main problem.

1.5  The real reason: arithmetic intensity

The dominant effect is hardware utilization, and it comes down to a single ratio: FLOPs performed per byte moved from memory.

Take a weight matrix $W \in \mathbb{R}^{d \times d}$ with $d = 512$, stored in bf16 (2 bytes per parameter).

RegimeFLOPsBytes read (weights)Intensity
1 token
matrix–vector
2d² = 524,2882d² = 524,2881 FLOP/byte
2048 tokens
matrix–matrix
2·2048·d² ≈ 1.07 × 10⁹2d² = 524,288
(read once, reused)
≈ 2048 FLOP/byte

Now compare against the hardware's ridge point — the intensity at which a chip transitions from memory-bound to compute-bound. For an A100 at roughly 312 TFLOP/s bf16 and about 2.0 TB/s of HBM bandwidth:

$$\text{ridge} \;=\; \frac{312 \times 10^{12}}{2.0 \times 10^{12}} \;\approx\; 156 \;\text{FLOP/byte}$$

H100 lands in a similar neighborhood. So at intensity 1, you are running at roughly $1/156 \approx 0.6\%$ of peak arithmetic throughput. At intensity 2048, you are comfortably compute-bound and actually saturating the tensor cores.

Intuition

Loading a weight matrix from HBM to multiply it by a single vector is like driving a truck across town to deliver one envelope. The trip dominates. Batching 2048 tokens fills the truck. The FLOPs are the same either way; what changes is how much of the machine you waste getting to them.

Add kernel-launch overhead — N times as many tiny kernels instead of a handful of large ones — and the practical gap between parallel and sequential training lands somewhere in the 10× to 100× range on achieved throughput, not on FLOP count.

Worked example

A 12-layer model, $d = 512$, $N = 2048$, FFN hidden width $4d$. Per layer, forward:

  • Attention scores + value aggregation: $4N^2d \approx 8.6$ GFLOP
  • Q/K/V/O projections: $8Nd^2 \approx 4.3$ GFLOP
  • FFN: $16Nd^2 \approx 8.6$ GFLOP

≈ 21.5 GFLOP per layer × 12 layers ≈ 258 GFLOP forward; roughly 3× that for forward + backward, so ≈ 775 GFLOP per sequence. Divided across 2048 supervised positions, that's about 0.38 GFLOP per training signal. The sequential version pays the same total and delivers it 2048 serial steps later at under 1% hardware efficiency.

1.6  Why inference is slow anyway

None of this applies at generation time. You don't know the next token, so you must produce one, feed it back, and repeat. Decoding is exactly the memory-bound matrix–vector regime described above — which is why generation feels slow despite being cheap in FLOPs per token, and why two mitigations exist:

Hold onto this. The ranking half of HSTU faces a structurally identical problem — one user history, many candidates to score — and solves it with the same insight (§5).

Don't conflate

Everything above is about parallelism across positions in a sequence. That is a different axis from device-level parallelism — data parallel, tensor parallel, pipeline parallel across GPUs — which is about splitting batches or weights across hardware and applies to RNNs just as well. Both are called "parallelism"; only one is what attention bought you.

Part TwoFeatures in recommendation

2.1  Sparse vs. dense

A production Deep Learning Recommendation Model (DLRM) is trained on thousands of heterogeneous features, and they come in two flavors that get treated completely differently.

Sparse (categorical)Dense (numerical)
Examplesuser_id, item_id, creator_id, category, language, joined communities, hashed feature crossesweighted/decayed counters, ratios, CTR on a topic over 7/30/90d, dwell time, price, recency
CardinalityExtreme — often billions, and growing every minuteLow — a scalar per field
EncodingEmbedding table lookupNormalize, then bucketize or project
ParametersNearly all of them. Trillion-parameter models are almost entirely embedding tables.Almost none.
Rate of changeSlow. Demographics and follows barely move.Fast. A counter can change on every single interaction.

That last row is the one that ends up mattering most, and we'll come back to it in §3.2.

The parameter asymmetry drives the standard systems design: shard the enormous embedding tables model-parallel across machines while keeping the comparatively tiny dense MLP data-parallel. Trillion-parameter counts in this domain are a sharding problem, not a FLOPs problem.

2.2  Four ways to encode a float

Whatever you do with a continuous feature, it has to end up as a d-dimensional vector before attention can touch it, because attention operates on a uniform embedding space. The options:

1. Bucketize, then embed

The most common choice. Discretize the value into bins (equal-frequency, or log-spaced when the distribution is heavy-tailed) and give each bin its own embedding. This makes floats structurally identical to sparse features, captures nonlinearity for free, and handles missing values elegantly — they get their own bucket.

Worked example

Feature: user's 30-day CTR on the "outdoors" topic = 0.037.

Population deciles: [0, .004, .009, .015, .023, .034, .048, .071, .11, .19, 1.0]

0.037 falls between .034 and .048bucket 6 → look up $e_6 \in \mathbb{R}^{d}$.

Equal-frequency bins matter here: a linear [0, 0.1, 0.2, …] binning would dump 90% of users into bucket 0 and learn nothing.

2. Linear projection

Normalize the scalar and project it to d: $e = w \cdot \tilde{v} + b$. Cheap, but weak on its own — it can only express a monotone linear relationship, and one direction in embedding space now carries the whole feature.

3. Gating / FiLM

The float doesn't become a token; it scales or shifts another representation: $e' = \gamma(v) \odot e + \beta(v)$. Good when the value modulates a relationship rather than being a thing in its own right.

4. Attention bias

The float becomes a scalar added directly to attention logits. This turns out to be the right treatment for anything relational — most importantly, time. Covered in §2.4.

Gotcha

Normalization matters more than people expect. Raw counts fed into a shared d-dimensional space destabilize training badly — a counter with range [0, 50000] next to a ratio in [0, 1] will dominate every dot product it touches. Apply log1p or a quantile transform first, always.

2.3  Three places attention appears

"Attention in a recommender" means at least three structurally different things, and they disagree about what a token even is. Getting this straight prevents a lot of confusion.

DesignA token is…Sequence lengthWhat it learnsExamples
Sequential One past interaction 10² – 10⁵ Temporal dynamics; evolution of taste SASRec, BERT4Rec, BST, HSTU
Feature-field One feature field ~50 Feature crosses, learned automatically AutoInt
Target attention History item (candidate is the query) 10² – 10³ Candidate-conditional relevance of history DIN, DIEN

Sequential

Each token is a past interaction, its embedding built by summing or concatenating that item's sparse fields with its dense features. Self-attention runs over the history. This is the direct analogue of language modeling and it's what HSTU is.

Feature-field

Every field — sparse or bucketized-float — is one token. Self-attention learns feature interactions automatically, replacing hand-designed FM or DCN cross layers. Note the "sequence" here has no temporal order at all; it's a set.

Target attention

The candidate item being scored is the query; the user's history supplies keys and values. Attention weights answer: how relevant is each past behavior to the thing I'm scoring right now?

DIN is worth a closer look because two of its choices reappear in HSTU. It replaces the dot-product score with a small MLP over $[\,q,\; k,\; q-k,\; q \odot k\,]$, and — critically — it skips softmax normalization, so total attention mass reflects the intensity of interest rather than being forced to sum to one. Remember that; it comes back in §3.4.

2.4  Dense features as attention bias

For dense quantities that describe a relationship between two positions rather than a property of one position, the natural home is not the token — it's the attention logit.

$$s_{ij} \;=\; \frac{q_i \cdot k_j}{\sqrt{d_k}} \;+\; b\!\left[\,\text{bucket}\big(\log(1 + |t_i - t_j|)\big)\,\right]$$

Bucketize the time gap, look up a learned scalar, add it to the score. Structurally this is identical to relative position bias in NLP (T5, ALiBi) — the only change is that the "distance" is measured in seconds rather than token index. The same trick handles session boundaries, recency, and any other pairwise continuous quantity.

Intuition

Ask where a feature lives. "This item cost 40 dollars" is a property of one position → it belongs in the token. "These two events happened 3 seconds apart" is a property of a pair → it belongs in the logit. Putting a pairwise quantity into a token forces the model to reconstruct the relationship through the dot product, which is possible but wasteful.

Part ThreeThe HSTU architecture

HSTU — Hierarchical Sequential Transduction Units — is the encoder proposed in Zhai et al., "Actions Speak Louder than Words: Trillion-Parameter Sequential Transducers for Generative Recommendations" (ICML 2024). It is the backbone of a framework called Generative Recommenders (GRs), and it's important to be precise about the relationship: HSTU is not "a retrieval model." It's an encoder that GR instantiates twice — once for retrieval, once for ranking — with different sequence constructions and different heads.

3.1  The reformulation

The framing claim: recommendation should be a sequential transduction task over a single time-ordered stream of user actions, not a feature-engineering problem over a snapshot. Given tokens $x_0, \ldots, x_{n-1}$ observed at times $t_0, \ldots, t_{n-1}$, transduce them to outputs $y_0, \ldots, y_{n-1}$, where $y_i = \varnothing$ marks a position with no defined target.

The paper's argument is that the DLRM feature space is approximated by this sequence as the sequence grows — with equality in the limit. Two mechanical consequences:

Sparse features get sequentialized. Pick the longest time series (typically the items the user engaged with) as the main series. The remaining categorical features are slowly-changing time series — demographics, followed creators, language, city of request. Compress each by keeping only the earliest entry per consecutive run of identical values, then merge into the main series. Because these change rarely, this barely increases sequence length.

Dense features get deleted. Which needs its own section.

3.2  Deleting dense features

HSTU's answer to "how do you encode dense features?" is unusually blunt: you mostly don't.

The argument has two legs.

The modeling leg. The dense features in a production DLRM are overwhelmingly numerical aggregations over the user's own action sequence — CTR on a topic over 30 days, decayed count of clicks on an author, ratio features. These are derived quantities. And crucially, the categorical features they aggregate over are already in the sequence. So given a long enough sequence, a sufficiently expressive sequential architecture, and a target-aware formulation, the model can learn whatever aggregation is actually useful — rather than you guessing at window sizes and decay rates by hand.

The systems leg. Categorical features change slowly, so the dedup trick above works. Dense counters change on every event. Keeping them as sequence tokens would multiply sequence length by the number of dense fields — thousands of them — which is infeasible on both compute and storage. It is genuinely remove-or-explode. They remove.

Intuition

"User's 30-day CTR on outdoors content" is a lossy summary statistic of a sequence you already have. You hand-picked the window (30 days), the aggregation (mean), and the grouping (topic = outdoors). Every one of those is a guess. Feeding in the raw events and letting attention learn its own weighting is strictly more expressive — provided you have the sequence length and the capacity to exploit it. That proviso is doing real work; see §7.

What survives is time, which enters as an attention bias (§3.5), and actions, which become tokens rather than features. Quantities you'd normally encode as floats — watch time, engagement depth — are either bucketized into the action vocabulary or moved to the output side as regression targets.

3.3  The layer, line by line

Given input $X \in \mathbb{R}^{n \times d}$, one HSTU layer is three sub-layers.

(a) Pointwise projection

$$U(X),\, V(X),\, Q(X),\, K(X) \;=\; \mathrm{Split}\big(\phi_1(f_1(X))\big)$$

A single linear map $f_1$ followed by SiLU, then split four ways. Note that $U$ is an extra output that a standard transformer doesn't have — it's a gate, and its purpose becomes clear in (c).

(b) Spatial aggregation

$$A(X)V(X) \;=\; \phi_2\!\left(Q(X)K(X)^{\top} + \text{rab}^{p,t}\right) V(X)$$

Attention — but $\phi_2$ is pointwise SiLU, not softmax, and $\text{rab}^{p,t}$ is a relative attention bias combining a positional term and a temporal term. Both choices are load-bearing and get their own sections below.

(c) Pointwise transformation

$$Y(X) \;=\; f_2\Big(\mathrm{Norm}\big(A(X)V(X)\big) \odot U(X)\Big)$$

with a residual connection around the block.

Now notice what's missing: there is no separate feed-forward block. In a standard transformer layer you pay for attention and then a 4×-width FFN. Here the $U$ gate plus $f_2$ absorb that role, in the style of Gated Attention Units. Recall from §1.5 that the FFN was 8.6 of the 21.5 GFLOP per layer — about 40%. That's a large part of why HSTU is cheaper per layer than a vanilla transformer at equal d.

Dimensions

Concretely, with $d = 512$, $h = 8$ heads, $d_{qk} = d_v = 64$ per head:

  • $f_1: \mathbb{R}^{512} \to \mathbb{R}^{2h d_v + 2h d_{qk}} = \mathbb{R}^{2048}$, split into four $n \times 512$ blocks
  • $QK^\top$ per head: $n \times n$, plus the $n \times n$ bias
  • Gated output $\to f_2: \mathbb{R}^{512} \to \mathbb{R}^{512}$

The activation-memory story matters at $n = 8192$: a single $n \times n$ score matrix per head is 64M entries. This is why fused kernels are not optional here.

3.4  Why not softmax

This is the most interesting design choice in the architecture, and the reasoning connects directly back to §2.1.

Softmax normalizes attention weights to sum to 1. That is exactly what you want when attention means "which of these do I select?" — a distribution over alternatives. But it discards magnitude. A user who interacted with a category fifty times and a user who did it twice can produce the same normalized attention pattern, because the denominator absorbs the difference.

And magnitude is precisely what the hand-built counter features were carrying. Un-normalized pointwise activation lets total attention mass grow with engagement volume, recovering that signal structurally rather than through a feature.

Softmax vs. SiLU: what happens to intensity

Suppose the user's history contains k items that all match the candidate equally well, each producing a raw attention logit of 2.0. Watch what each activation does to the total attention mass.

3
Softmax mass
1.000 SiLU mass
5.28

The arithmetic, if you want it by hand. With $\sigma(2) = 1/(1+e^{-2}) \approx 0.8808$:

$$\phi(2.0) = 2.0 \cdot \sigma(2.0) \approx 1.7616 \quad\Longrightarrow\quad \text{total mass} = 1.7616\,k$$

At $k=3$ the mass is 5.28; at $k=20$ it is 35.23 — a 6.7× difference that softmax would have flattened to exactly 1.000 in both cases.

Fine print

Equation (c) applies $\mathrm{Norm}(\cdot)$ to the aggregated output, so this is not unbounded growth in the residual stream. The claim is narrower and more careful than "magnitudes grow forever": what survives is relative intensity — across positions within a sequence and across users — in a form softmax destroys entirely at the point of aggregation. DIN reached the same conclusion from a different direction years earlier.

There is a second motivation. Softmax's denominator is a sum over the attended set, and in a domain with a non-stationary, billion-scale vocabulary that denominator is an unstable quantity. Pointwise activation sidesteps the issue.

3.5  The relative attention bias

The $\text{rab}^{p,t}$ term carries both position and time. The temporal half is the entire dense-feature story in HSTU: a continuous quantity that shapes attention weights without ever becoming an embedding.

Worked example

Log-spaced buckets over the time gap $\Delta t = |t_i - t_j|$ in seconds:

bucket:  0     1     2     3     4     5      6      7       8        9        10
edges:   0     1     5     30    60    300    1800   3600    86400    604800   2.6e6   ∞
                                 1m    5m     30m    1h      1d       1w       1mo

Two events 40 seconds apart → $\Delta t = 40$ → bucket 3 → learned scalar, say $b_3 = +1.2$. Strong boost: same session, tightly related.

Two events 3 hours apart → $\Delta t = 10{,}800$ → bucket 7 → $b_7 = -0.4$. Mild suppression: different session.

The scalars are learned, not designed. The model decides whether same-session adjacency matters more than day-scale adjacency, per dataset.

Two things worth appreciating. First, this handles irregular sampling natively — user actions do not arrive on a uniform grid, and positional index alone would treat "two clicks 3 seconds apart" and "two clicks 3 months apart" identically. Second, it costs a lookup table of ~11 scalars per head, versus an embedding table.

Part FourRetrieval

Retrieval is the stage that narrows millions of candidates to hundreds. In GR it becomes almost exactly next-token prediction.

4.1  Sequence construction

The retrieval formulation learns a distribution $p(\Phi_{i+1} \mid u_i)$ over content items $\Phi_{i+1} \in \mathbb{X}_c$, where $u_i$ is the user's representation at token i.

Note the exact input construction — this is a detail people frequently get wrong. Retrieval does not interleave item and action tokens the way ranking does. Instead each (item, action) pair is merged into a single token:

Inputs (Φ₀, a₀)(Φ₁, a₁)(Φ₂, a₂)n−1, an−1)
Targets Φ′₁Φ′₂Φ′₃
Retrieval sequence. Each input token bundles the content and the user's response to it. The target at position i is $\Phi'_{i+1}$, defined as $\Phi_{i+1}$ when the action $a_{i+1}$ was positive, and $\varnothing$ otherwise. Positions with $\varnothing$ targets are masked out of the loss.

This is a meaningful departure from plain language modeling, and the paper flags it explicitly. In an LM, the supervision at position i is always the literal next token. Here it isn't: a user can respond negatively to the item they were shown next, and you don't want to train the retrieval model to go fetch more of that. Negative-response items still appear as inputs — they're real evidence about the user — but they don't serve as targets.

Intuition

Items the user saw and disliked are informative context and terrible labels. Bundling the action into the input token lets the model see "you showed me this and I skipped it" while the masked target ensures the retrieval head is only ever asked to predict things worth retrieving.

4.2  The loss

The scoring function must stay a dot product between the position-i output embedding and a candidate item embedding, usually with a learned temperature $\tau$:

$$s(u_i, \Phi) \;=\; \frac{u_i \cdot e_\Phi}{\tau}$$

This is non-negotiable — an MLP scorer would be more expressive but would destroy the Maximum Inner Product Search property you need at serving time (§4.3).

Since the vocabulary is in the billions, a full softmax is impossible. You use sampled softmax with in-batch negatives, plus a logQ correction to debias sampling toward popular items:

$$\mathcal{L} = -\sum_{i \,:\, y_i \neq \varnothing} \log \frac{\exp\!\big(s(u_i, \Phi_{i+1}) - \log Q(\Phi_{i+1})\big)}{\sum_{\Phi' \in \mathcal{S}} \exp\!\big(s(u_i, \Phi') - \log Q(\Phi')\big)}$$

where $\mathcal{S}$ is the sampled negative set and $Q(\cdot)$ is the probability of an item appearing as a negative. Without the correction, popular items appear as negatives far more often than chance and get systematically suppressed — the model learns to avoid recommending anything popular, which is exactly backwards.

Worked example — supervision density

A user with 8,000 logged interactions, of which 5,200 were positive.

GR / HSTU: one forward + backward pass over the length-8,000 sequence yields 5,200 retrieval training signals. History encoding is shared across all of them.

Classic two-tower: one (user, item) pair per example, with the user history re-encoded from scratch each time. Getting 5,200 signals means 5,200 examples and 5,200 re-encodings of overlapping history.

This is §1.3 cashed out in the recommendation setting: the win is in supervision per unit of compute, not in FLOPs saved.

4.3  Serving via MIPS

At inference the model collapses to ordinary embedding retrieval:

  1. Run HSTU over the user's history. Take the output embedding at the final position as the query vector $u$.
  2. Item vectors come from the embedding table — often weight-tied with the input table.
  3. MIPS / ANN search over the corpus: HNSW, IVF-PQ, ScaNN, whatever index you already run.

The index infrastructure is unchanged from a two-tower system. That's a significant deployment property — you're swapping the query encoder, not rebuilding the serving stack. What changed is that the encoder is now HSTU over raw actions instead of an MLP over pooled features.

And with incremental decoding you can cache the history's keys and values, extending the sequence as new actions arrive rather than re-encoding from scratch on every request. Same KV-cache logic as §1.6.

4.4  The non-stationary vocabulary

This is the biggest genuine structural difference from language modeling, and the paper names it as a defining property of the domain.

A language model has a fixed ~100K-token vocabulary that never changes. A recommender has a billion-scale vocabulary where new content appears every minute and old content dies. A "fixed item vocabulary" is a fiction in production.

Language modelRecommender
Vocabulary size~10⁵, static~10⁹, non-stationary
New tokensEssentially neverContinuously, every minute
Training regimeFixed corpus, epochsStreaming / continuous, single pass
Cold startNot a conceptCentral problem
Output layerFull softmax feasibleSampled softmax + ANN mandatory

The mitigations are continuous streaming training, ID hashing so unseen IDs land somewhere sensible, and content-feature fallbacks so a brand-new item has a representation before it has any interaction data. None of this is unique to HSTU — it's the cost of admission for the domain.

Part FiveRanking and M-FALCON

5.1  Interleaved sequence

Ranking scores the few hundred candidates retrieval handed over. Its sequence construction is different: items and actions interleave as separate tokens.

Inputs Φ₀a₀Φ₁a₁Φcand
Targets a₀a₁â
Ranking sequence. Item positions predict the action that followed; action positions have no target. The candidate being scored is appended as an item token, and the model predicts its action distribution — multi-task heads for click, like, watch-time, share, and so on.

5.2  Target awareness, for free and at full depth

Here's the elegant part. Because the candidate sits inside the sequence rather than outside it, target-awareness is structural. DIN gets one attention layer of candidate↔history interaction. HSTU gets L layers of it. Strictly more expressive, with no extra mechanism.

5.3  M-FALCON

The obvious cost of putting the candidate in the sequence: ranking scores hundreds of candidates per request, and naively that's hundreds of forward passes over the whole history.

M-FALCON — Microbatched-Fast Attention Leveraging Cacheable OperatioNs — fixes it. Encode the user history once, cache its keys and values, then process candidates in microbatches that all attend to the shared cache, with an attention mask preventing candidates from attending to each other so each is scored independently.

Worked example — the amortization

Ranking 500 candidates against a history of n = 1024, counting attention-score units only:

Naive: 500 passes over length-1025 sequences → $500 \times 1025^2 \approx 5.25 \times 10^{8}$

M-FALCON: encode history once ($1024^2 \approx 1.05 \times 10^{6}$), then each candidate attends to 1024 cached keys ($500 \times 1024 = 5.12 \times 10^{5}$) → $\approx 1.56 \times 10^{6}$

Ratio ≈ 336× on this term.

The real-world number is smaller — per-candidate projections and the gated FFN-equivalent do not amortize, and there's a microbatch-size tradeoff against memory. But the shape of the win is right, and the history cost can also amortize across requests, not just within one.

Intuition

This is the same insight as KV caching in LLM decoding, applied to a fan-out instead of a chain. In decoding, one prefix serves many sequential steps. In ranking, one prefix serves many parallel candidates. Both times, the expensive shared prefix should be computed once.

The paper reports this enabling models roughly 285× more computationally complex than the DLRM baseline while achieving 1.50×–2.99× speedups, within the same inference budget. That combination — far more model, less latency — is what made deployment possible at all.

Part SixEfficiency and scaling

Three efficiency techniques carry most of the weight:

Stochastic Length. During training, long sequences are randomly sparsified, so cost grows sublinearly in history length while the model still sees the tail. Long user histories are heavily redundant; you don't need every token every step.

Sequence sparsification. The dedup of slowly-changing categoricals from §3.1, plus the removal of dense features, keeps n tractable.

Fused kernels. Sparse grouped GEMMs and a fused relative-attention-bias kernel, plus the absence of a separate FFN block, minimize both FLOPs and activation memory.

Reported results

MetricResult
Public + synthetic benchmarksUp to 65.8% improvement in NDCG over baselines
Encoder speed5.3×–15.2× faster than FlashAttention2-based transformers at sequence length 8192
Production A/B+12.4% topline metrics, deployed across multiple surfaces at billion-user scale
Model size1.5 trillion parameters (overwhelmingly embedding tables)
ScalingQuality follows a power law in training compute across three orders of magnitude, up to GPT-3 / LLaMa-2 scale

The scaling-law result is arguably the headline. DLRMs had been observed to scale poorly with compute — you could throw more hardware at them and get very little. Demonstrating a clean power law in a deployed, billion-user recommender was the thing the field had failed to show.

Part SevenCaveats worth holding onto

Four, in rough order of how likely they are to bite you.

The dense-feature result is validated at scale. The ablations justifying removal run with long sequences, large models, and Meta-sized data. The argument is explicitly asymptotic — the sequence approximates the DLRM feature space as length grows. At shorter histories or smaller capacity, hand-built counters are still doing real work, and dropping them because a paper did is a mistake.

The definition of "positive" does a lot of quiet lifting. Retrieval quality depends heavily on which actions count as positive for target masking (§4.1). That threshold is a modeling decision, it's dataset-specific, and it will not be in anyone's architecture diagram.

Un-normalized attention is a genuine departure. It's motivated by a specific property of engagement data — that intensity carries signal. If you port HSTU to a domain where engagement-intensity distributions look different, ablate it rather than assuming.

Trillion-parameter counts are misleading. Almost all of it is embedding tables. The dense compute is far smaller than the parameter count suggests, and the engineering challenge is sharding and memory, not arithmetic. Comparisons to LLM parameter counts are close to meaningless.

Part EightNotation and references

Notation

SymbolMeaning
N, nSequence length
dModel / embedding dimension
LNumber of layers
$\Phi_i$The i-th content item in the merged time series
$a_i$The user's action in response to $\Phi_i$ (like, skip, share, complete)
$u_i$The user's representation at token i
$\mathbb{X}$, $\mathbb{X}_c$Full token vocabulary; content sub-vocabulary
$\varnothing$Undefined target — position excluded from the loss
$\text{rab}^{p,t}$Relative attention bias (positional + temporal)
$\phi$SiLU, $\phi(x) = x \cdot \sigma(x)$

References

  1. Zhai, Liao, Liu, Wang, Li, Cao, Gao, Gong, Gu, He, Lu, Shi. Actions Speak Louder than Words: Trillion-Parameter Sequential Transducers for Generative Recommendations. ICML 2024. arXiv:2402.17152 — the HSTU / GR / M-FALCON paper. Appendices F–H cover Stochastic Length, fused kernels, and M-FALCON in detail.
  2. meta-recsys/generative-recommenders — reference implementation, with reproducible configs for MovieLens and Amazon Reviews.
  3. Zhou et al. Deep Interest Network (KDD 2018) — target attention; the original argument for dropping softmax normalization in recommendation.
  4. Kang & McAuley. SASRec (ICDM 2018) — self-attentive sequential recommendation; the academic ancestor of the sequential formulation.
  5. Song et al. AutoInt (CIKM 2019) — attention over feature fields rather than over time.
  6. Yi et al. Sampling-Bias-Corrected Neural Modeling for Large Corpus Item Recommendations (RecSys 2019) — the logQ correction.
  7. Hua et al. Transformer Quality in Linear Time (ICML 2022) — Gated Attention Units, the lineage of HSTU's gated single-block design.
On accuracy

Architectural details, equations, and reported figures here were checked against the arXiv paper. Worked numeric examples are my own constructions chosen for clarity — bucket edges, learned bias values, and layer dimensions are illustrative, not taken from the paper's configs. For anything you plan to implement, read §3 and Appendices F–H of the source directly.