Skip to content

Merge and Branch: One Long History, Many Independent SID Targets

THE ARGUMENT

Compressing a long history into a few learned soft tokens and letting several independent target branches share that single encoding is a workable way to cut training cost and raise supervision density without leaving the SID output space.

On this page

Three Amazon domains, long text-rich interaction histories, and yet one target per history: that is the asymmetry Merge and Branch is built to remove. The usual advice is to serialize the full item text into the prompt and fine-tune on the next item, one example per prediction. That advice quietly assumes input cost and supervision scale together, which they do not: a history of thousands of tokens produces a target of a few tokens, so the expensive part is paid once and graded once. A team deciding how to spend a fixed fine-tuning budget therefore faces a real question, namely whether one encoded history can be reused for several independent predictions without letting those predictions read each other. The paper answers with a merge step, a branch step, and matching kernels for training and constrained decoding [1].

Long input, short output: why one history grades only one answer

Generative recommendation does not pick a catalog ID directly; it generates a semantic identifier (SID, a short sequence of discrete tokens that names an item, so a correct generation is a correct recommendation) from the user's interaction history. Item text such as titles and categories is appended because it helps the model interpret preferences that SIDs alone cannot express, and that appended text is exactly where the token budget explodes.

Figure 1 in the paper places three paradigms side by side: SID-only history predicting one target, SID-plus-text history predicting one target, and merged SID-plus-text tokens predicting several targets in parallel. The middle row is the wasteful one, and the paper states the asymmetry plainly, noting that a model may process thousands of history tokens to predict a next-item SID of only a few tokens [1].

Cost is only half of the problem, because supervision is also thin. A single next-item target is one observation of preference, and that one observation has to justify gradients for the entire encoded history. The paper adds two further sources of targets, namely later observed interactions inside the training sequence and synthetic targets proposed by a trained teacher recommender such as SASRec, which transfers collaborative signal in the spirit of distillation.

These targets must remain independent, since at inference time only the history is available and no sibling target ever exists to condition on. The naive fix duplicates the example once per target and re-encodes the same history each time, which hands back most of the compute that the extra supervision was supposed to buy.

Merge: compressing each item into N_q learned tokens

The merge step shortens the history without destroying the order of interactions. Each historical item contributes a matrix of SID and text embeddings, and a single merger shared across items maps that matrix into N_q soft tokens, which are learned vectors rather than vocabulary entries. Outputs stay in chronological order, so the merger selects information within an item while the language model models dependencies across items.

Where the query comes from is the crux. The paper averages the L level embeddings of an item's SID to obtain a direct residual path, concatenates the normalized level embeddings through a small MLP to learn a correction, and adds the two into a SID anchor (the starting point of that item's compressed representation). The mean keeps the path stable while the concatenation lets the MLP distinguish SID levels; action-type and time-bucket embeddings join at this stage when metadata exists.

Cross-attention then selects content from that item's SID and text tokens. A shared learned offset combined with the item's own anchor forms the query, keys and values come from the item's tokens, field embeddings and sinusoidal position encodings are added to keys only, and the selected content is projected back and added to the anchor as a residual. Because every query depends on its own anchor, the same shared offsets can select different content for different items.

Both output projections are zero-initialized, so training starts from the mean SID embedding plus any action and time embeddings and learns corrections from there. Raising N_q yields more summary tokens without changing the merger. This differs from Q-Former, which starts from shared learned queries; LONGER merges groups of adjacent interactions, and GenRec and Token Factory map item features to soft tokens.

Branch: K_u targets per history, weighted by group rather than by count

The branch step attaches several SID sequences to one compressed history. Supervision comes from three sources:

  • The primary target, the item immediately following the history, which is ordinary next-item prediction;
  • Future targets, later observed interactions in the training sequence that reveal more of the same user's preferences;
  • Synthetic targets from a trained teacher recommender, whose checkpoint is chosen by validation ranking and frozen during training.

The branch count is K_u = 1 + |F_u| + |S_u|, covering one primary target, |F_u| future targets, and |S_u| synthetic ones. Observed target occurrences are kept, including repeats, and only synthetic targets not already present are added. Each target is predicted level by level over its own preceding SID tokens, with a cross-entropy average over the L levels and a softmax restricted to the codebook at that level.

The weighting is the part most readers skip. Auxiliary target counts vary from example to example, but that count should not decide how much influence a source has, so the paper assigns one weight to the future group and one to the synthetic group and spreads each weight uniformly inside its group. The total is divided by a normalizer that sums the active group weights, including the primary weight of one, so adding synthetic targets cannot silently amplify distillation strength.

One hard structural constraint remains: each target sees the shared prefix and its own preceding SID tokens only, and sibling branches cannot read one another. Concatenating all targets into an ordinary causal sequence would let earlier targets peek at later ones, and since those later targets do not exist at inference time, training and serving would diverge.

One tree for training and decoding: tree FlashAttention and a shared-prefix cache

The tree layout needs custom kernels to be fast. The paper implements tree FlashAttention with forward and backward passes that follow the branch visibility pattern without materializing a dense attention matrix; the shared history is computed once and gradients from every branch accumulate back into the prefix. Merger and language model therefore train end to end inside one computation graph rather than being compressed first and frozen afterwards.

Decoding reuses the same idea. Beam hypotheses under constrained search share one history and differ only in the SIDs generated so far, so a tree-structured KV cache (key and value states stored and reused instead of recomputed at every step) keeps a single copy of the history and one state per hypothesis.

Table 1 of the paper compares related methods across five columns, namely Fwd., Bwd., Cache, SFT, and Beam. Only the M&B row checks all five, while the other methods each cover a subset.

MethodCapability emphasis in Table 1 and the related-work text
SGLangKV reuse across requests that share a common prefix
DeFTIO-aware attention for tree-structured decoding
Tree TrainingPacking branching trajectories with shared forward and backward passes
AtSpeedTree masks for verifying speculative beam candidates in recommendation
UniSGR / STARKReorganizing KV states for SID beam search
M&BForward, backward, cache, SFT, and Beam all supported [1]

What the experiments show, and when this method does not apply

Experiments run on three Amazon domains drawn from public benchmarks and answer four research questions: RQ1 effect against baselines, RQ2 component ablations, RQ3 efficiency, and RQ4 convergence across backbones and pretraining. Baselines span sequential and generative recommenders, ablations cover components, token merging, and target layout, and an appendix examines auxiliary branch counts and weights separately.

The direction of the result is clear: M&B outperforms the sequential and generative baselines the authors evaluated on all three domains, ablations show that learning from multiple targets improves quality under compact history representations, and efficiency measurements show substantially lower training cost than processing uncompressed SID and text histories. Shared-prefix caching cuts beam-search latency and memory, with the largest gains at long contexts. The per-dataset accuracy numbers live in the paper's result tables, which the excerpt does not expose, so no figure is invented here.

The method fails when the following conditions do not hold:

  • Samples near the end of a sequence have no future targets, so extra branches collapse into distillation strength alone;
  • A teacher must be trained, tuned by validation ranking, and frozen, which is an extra pipeline and an extra training run;
  • Short histories or thin item text leave little to compress, so tree kernels cost more than they save;
  • The output space stays SID-based, so stacks without a hierarchical SID scheme must build one first;
  • Tree FlashAttention is a custom forward and backward kernel, so integration depends on your training framework;
  • Evidence covers three Amazon domains only, leaving cross-domain transfer, cold start, and industrial catalog scale out of scope.

A calmer reading is that M&B offers a training structure which trades one encoding for several independent supervisions and then reuses that same structure at decoding time [1]. Whether it is worth adopting depends on your history length distribution, whether you already have SIDs, and whether you will maintain a frozen teacher; if any of those fails, fix the premise before reaching for the tree.

References

  1. Merge and Branch: Efficient Tree-Structured Supervised Fine-Tuning of LLMs for Recommendation

Sign in to Padda

A code in your inbox. No password to remember.

Connecting to sign-in…