Tree Training: Efficient LLM Training on Tree-Structured Trajectories

Jinghui Wang, Wang Shaojie, Can Tang, Yinghan Cui, Xuxing Chen, Xiaojiang Zhang, Chao Wang, Haotian ZhangNeurIPS 2026

TL;DR

When we train Large Language Models (LLMs) on reasoning tasks or agentic workflows, the data naturally forms a branching tree of shared conversations rather than isolated lines of text. Standard training pipelines flatten these trees into separate paths, forcing GPUs to recompute the exact same shared prefixes over and over again. Tree Training eliminates this waste entirely—processing every unique token exactly once while producing mathematically identical gradients—unlocking over a 6× end-to-end training speedup.

What Problem Does This Paper Address?

Picture an AI coding agent trying to fix a bug. It reads a file, pauses to "think," calls two search tools in parallel, and explores three different patches. Whether through multi-turn agents, beam search, or reinforcement learning (RL) sampling multiple rollouts per prompt, modern LLM training rarely produces neat, independent lines of text. Instead, it produces trees where branches share massive trunks of identical tokens.

During inference, we solved this redundancy years ago with prefix caching (reusing Key-Value states). During training, however, pipelines still flatten a tree with $K$ leaves into $K$ separate sequences. Why? Because in training, shared intermediate prefixes aren't just static prompts—they contain model outputs that actively participate in gradient updates from every downstream branch. Lacking a clean way to merge backward passes across branches, frameworks just brute-force recompute the trunk $K$ times. When "think-mode" is turned on, nearly 90% of the compute in these pipelines is pure déja vu.

Methods

The authors start with a clean algebraic observation: averaging the loss across $K$ independent branches is identical to computing each unique token's loss once and multiplying it by $g_t / K$, where $g_t$ is the number of branches passing through that token.

To turn this algebra into GPU reality, Tree Training introduces two core mechanisms:

  1. DFS Serialization & Layer Adaptations: The trajectory tree is flattened into a single sequence via Depth-First Search (DFS), visiting each node once. Trajectory tree serialized into a redundancy-free DFS sequence To prevent branches from "seeing" their siblings in this packed sequence, the authors apply three surgical fixes:

  2. Tree Attention Mask: Tokens only attend to ancestors on their own root-to-leaf path. Tree attention mask blocking cross-branch token visibility (Note: Let's look at how sibling branches like $n_3$ and $n_2$ are mutually blocked below.) Tree attention mask blocking cross-branch token visibility

  3. Depth-Based Position IDs: Sibling branches receive the exact same RoPE position offsets they would see in isolation.
  4. SSM State Routing: Modern hybrid architectures (like Qwen3.5) mix attention with recurrent State Space Models (SSMs) like Gated Delta Net. In a DFS list, recurrent states and 1D causal convolutions would bleed from the end of one branch into the start of a sibling branch. The authors route each node's initial recurrent state and convolution window directly from its parent node instead.
Figure 1: Trajectory tree and DFS serialized sequence. Left: a trajectory tree with K = 3 root- to-leaf paths. Each node n holds a token segment Tn; gn is the number of paths through n (blue nodes are shared prefixes with gn > 1). Node text in red is model output; black is user/environment input. Right: the DFS sequence places all nodes in depth-first order so that every token is computed exactly once, with no redundancy.
Figure 2: Tree attention mask. Left: the 6×6 attention matrix for the DFS sequence; a cell is filled iff the query token can attend to the key token. Tokens from different branches (e.g. n3 and n2) are mutually blocked. Right: the corresponding tree structure; the dashed red arrow shows a blocked cross-branch path.
  1. Redundancy-Free Tree Partitioning: What if a massive agentic tree exceeds GPU memory? The authors use offline bin-packing (via OR-Tools) to slice the tree along node boundaries into subtrees. At each cut, cached KV tensors and SSM states act as differentiable gateways—detached for the child's forward pass, then explicitly relaying gradients back into the parent's graph during the backward pass, much like pipeline parallelism. Peak memory stays bounded by a single root-to-leaf path, with zero boundary recomputation.

Datasets

  • Real-world Agentic Rollouts: Multi-turn RL trajectories collected from SWE-smith software engineering tasks executed via the Claude Code agentic scaffold (spanning 28.0% to 88.7% token overlap).
  • Downstream Quality Benchmark: Terminal Bench 2.0, used to evaluate training on all branch tokens vs. single-branch subsets.
  • Synthetic Trees: Controlled datasets sweeping Potential Overlap Ratio (POR) from 20% to 92% to stress-test tree shapes and partition sizes.

Key Insights and Ideas

  • Why DFS beats BFS: Breadth-First Search requires holding activations for an entire tree level in memory at once. DFS backtracks immediately, freeing completed subtrees and bounding peak activation memory to $\mathcal{O}(\text{max-path})$.
  • Packing crushes per-node caching: You could run one tiny forward pass per tree node and relay KV caches between them. However, small token chunks starve GPU matrix multiplications (GEMMs) and force SSM recurrent states back and forth to slow HBM memory. Packing whole subtrees via DFS keeps weights amortized and SSM states on-chip, running 3.88× faster.
  • Think-mode is secretly a giant prefix tree: Modern reasoning agents often drop intermediate <think> tokens from future turns' context windows, creating lopsided trees with >80% token overlap—making them prime beneficiaries of Tree Training.

Key Results

  • Massive End-to-End Speedups: On real SWE-smith rollouts (theoretical ceiling: 6.5×), Tree Training achieves 6.3× speedup on Qwen3-32B (dense) and 6.2× on Qwen3-30B (MoE) across 64 Hopper GPUs—capturing >95% of theoretical FLOP savings. On synthetic in-memory trees, speedups reach 8.7×.
  • Exact Parameter Gradients: Tested in FP32 across pure transformers (Qwen3-4B, Llama-3.2) and SSM hybrids, parameter gradients match independent per-branch baselines within $\le 9.2 \times 10^{-5}$ relative error—sitting right on the hardware's native GEMM accumulation noise floor, even when sliced into 7 partitions.
  • Tiny Memory Overhead & Better Quality: Partition gateways add just 1.2 MB per tree on Qwen3.5-35B-A3B (<0.002% of activation memory). Because it makes training on all branches affordable, it unlocks a +37% quality gain on Terminal Bench 2.0 over single-branch training.

Limitations and Future Work

  • Per-path objectives only: The loss reduction requires objectives computable from per-token log-probabilities (covering SFT, PPO, and GRPO). Objectives that jointly model probability distributions across multiple branches simultaneously are out of scope.
  • Reference models: In RL, frozen reference-model log-probabilities are still computed via standard forward passes outside this framework.
  • Future Directions: The authors highlight extending the framework to looped transformers and building prefix-aware schedulers that coordinate tree partitions across distributed devices and training steps.

Summary updated

BibTeX
@inproceedings{wang2026tree,
  author = {Jinghui Wang and Wang Shaojie and Can Tang and Yinghan Cui and Xuxing Chen and Xiaojiang Zhang and Chao Wang and Haotian Zhang},
  title = {{Tree Training: Efficient LLM Training on Tree-Structured Trajectories}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=MMS2MVw0et},
}
Figure