TL;DR
This paper introduces a schedule-level prefix reuse mechanism for LLM reinforcement learning (specifically GRPO) that eliminates redundant computations on shared prompts. By decoupling the training step into three distinct phases, the system executes the prefix forward and backward passes exactly once per prompt group, yielding up to a 4.4x training speedup and a 59% reduction in peak memory usage without sacrificing numerical precision.
What Problem Does This Paper Address?
In modern Reinforcement Learning from Human Feedback (RLHF) algorithms like Group Relative Policy Optimization (GRPO), a single prompt generates a group of multiple rollout trajectories (responses) to undergo policy updates. In long-context scenarios—such as Retrieval-Augmented Generation (RAG), code reasoning, or multimodal tasks—the prompt (prefix) can be massive, containing entire documents, system instructions, or video tokens.
Standard training frameworks process these trajectories as independent microbatches. Consequently, the identical prefix is redundantly recomputed forward and backward for every single trajectory in the group. While "local packing" (combining everything into one large graph) can mitigate this, long-context groups quickly exceed GPU memory limits or pipeline parallelism boundaries. Furthermore, unlike inference caching, training requires gradients to flow backward through the prefix, making simple Key/Value (KV) caching insufficient.
Methods
The authors propose a Three-Phase Schedule that elevates prefix reuse from the kernel or graph level to the training-step schedule level:
- Phase A (Prefix Forward): Runs a single forward pass on the shared prefix, captures the per-layer prefix $K_1, V_1$ tensors, and keeps the autograd graph alive. Crucially, dormant activations needed only for the prefix backward pass are offloaded to CPU memory to free up GPU headroom.
- Phase B (Suffix Microbatches): Suffixes (responses) are executed as ordinary microbatches. They read the cached prefix $K_1, V_1$ blocks to compute attention, run their respective forward/backward passes, and accumulate prefix-side coupling gradients ($gK_1, gV_1$) into a gradient cache. Suffix activations are immediately discarded after each microbatch.
- Phase C (Prefix Backward): The accumulated gradient cache is injected back into the live prefix graph, and a single prefix backward pass is executed.
This approach relies on prefix-gradient superposition: because the prefix forward trace is fixed, the backward pass is a vector-Jacobian product, which is mathematically linear. Accumulating the gradients first and running backward once is mathematically equivalent to running separate backward passes for each trajectory and summing them.
Datasets
The method was evaluated using configurations modeled after real-world, prefix-heavy GRPO workloads:
- Fixed-context RAG: Traces from MuSiQue and 2WikiMultiHopQA.
- Video/Multimodal RLVR: Traces from Video-MME and Video-R1 CLEVRER.
- Chart/Diagram QA: Traces from ChartQA and AI2D.
- Low-prefix controls: Open-R1 math traces and SWE/OpenHands agent traces.
Evaluations were executed on H20 GPU clusters using Llama3-8B, Qwen3-8B, and the Mixture-of-Experts (MoE) Qwen3-MoE-30B-A3B model.
Key Insights and Ideas
- Linearity of the Vector-Jacobian Product: The core mathematical justification is that gradient accumulation before a backward pass yields identical results to accumulating gradients after separate backward passes. This allows $N$ expensive prefix backward passes to be replaced by 1 prefix backward pass and $N$ cheap additions.
- Lifecycle-Based Memory Management: By identifying that prefix activations are "dormant" during suffix computation, the system safely offloads them to the CPU. The GPU only holds the "hot" $K/V$ and $gK/gV$ caches, turning freed memory into an allocation budget for longer sequences or larger batch sizes.
- Parallelism-Agnostic Design: Unlike prior methods tied to a single GPU or kernel, this schedule-level approach cleanly integrates with 5D parallelism (Tensor, Expert, Context, Pipeline, and Data Parallelism) by treating the prefix cache as layer-local state.
Key Results
- Speedup: On Llama3-8B, training speedups scaled with the prefix ratio and group size, reaching up to 4.395× in eager mode and 2.930× when utilizing PyTorch compilation.
- Memory Reduction: Peak High Bandwidth Memory (HBM) during the suffix phase was reduced by up to 59.1%.
- Capacity Expansion: This memory reduction allowed the maximum sequence capacity frontier on the same hardware to expand from 17,920 tokens to 29,696 total tokens (a 1.65× improvement).
- Numerical Accuracy: The framework achieved strict numerical alignment with baseline full-sequence training, matching optimizer updates across complex parallel configurations within finite-precision tolerances (maximum parameter difference near $2 \times 10^{-6}$).
Limitations and Future Work
- Workload Dependency: The framework provides minimal benefits for workloads with low prefix ratios (e.g., pure math/code reasoning) or small group sizes ($N=1$).
- MoE Routing Constraints: While compatible with token-local auxiliary-loss MoE routing via logical token accounting, it does not currently support batch-coupled routing mechanisms (such as those involving hard capacity constraints or token dropping).
- Hierarchical Prefixes: The current implementation targets flat, root-sharing prompt groups and does not yet support complex, tree-structured agentic histories.
Summary updated