Knapsack RL: Compute-Efficient Reinforcement Learning via Heterogeneous Rollout Allocation

Ziniu Li, Congliang Chen, Tianyun Yang, Tian Ding, Ruoyu Sun, Ge Zhang, Wenhao Huang, Zhi-Quan LuoICML 2026

Introduction

Reinforcement Learning (RL) fine-tuning—specifically through methods like Group Relative Policy Optimization (GRPO)—has emerged as the critical "secret sauce" for enhancing the reasoning capabilities of Large Language Models (LLMs). However, this process is notoriously compute-intensive. To calculate a gradient update, the model must generate multiple responses, or "rollouts," for every prompt in a training batch.

Knapsack RL introduces a paradigm shift in how we train LLMs by abandoning the traditional "one-size-fits-all" approach to rollout generation. By treating GPU compute as a strictly limited resource and applying knapsack optimization, this framework allocates more responses to challenging prompts and fewer to easy ones. The result is a 2x improvement in compute efficiency and significant gains in mathematical reasoning performance.

The Problem: The Inefficiency of Uniform Allocation

Standard practice in RL fine-tuning relies on homogeneous allocation, where every prompt receives the exact same number of rollouts (e.g., $N=8$). The authors identify a major efficiency gap in this uniform approach, which frequently results in "zero-gradient" groups where precious GPU cycles are wasted:

  1. Oversampling Easy Prompts: If a prompt is simple and all 8 generated responses are correct, the relative advantage between them is zero. Consequently, the model learns nothing new.
  2. Undersampling Hard Prompts: If a prompt is highly difficult, the model might need 50 attempts to discover a single correct reasoning path. If all 8 responses in the uniform batch are wrong, the gradient is once again zero.

The core question the paper addresses is: How can we distribute a fixed budget of rollouts across a batch to maximize the overall learning signal?

Methodology: Rollout Allocation as a Knapsack Problem

To solve this inefficiency, the authors formulate rollout allocation as a constrained resource allocation task. Each prompt-budget pair is treated as an "item" in a knapsack. The "weight" of the item is its rollout cost, and the "value" is the expected learning benefit.

The Value Function

At the heart of Knapsack RL is a novel value function, $V(N, p)$, which estimates the utility of assigning $N$ rollouts to a prompt with a current success rate $p$:

$$V(N, p) = \text{ProbNonZeroGradient}(N, p) \times \text{InfoGain}(p)$$

  • ProbNonZeroGradient: The probability that a group of $N$ rollouts contains at least one success and one failure. This variance is the mathematical prerequisite for a non-zero GRPO gradient.
  • InfoGain: Derived via Taylor expansion, this term estimates the actual improvement in the success rate if a gradient update occurs. It naturally favors "moderately hard" tasks over those that are already nearly solved.

The Greedy Solver

Because the value function exhibits diminishing returns (it is discrete concave), the optimal allocation can be found using a lightweight, greedy "water-filling" algorithm. In each step, the system assigns one additional rollout to the prompt offering the highest marginal value until the total compute budget is exhausted. This optimization step takes less than a second, introducing negligible overhead compared to LLM inference.

Experimental Setup

The framework was primarily evaluated using models like Qwen2.5-7B and DeepSeek-R1-Distill-1.5B, trained on DAPO-Math-17K—a dataset of approximately 18,000 mathematical reasoning prompts with verifiable ground-truth answers.

Evaluation spanned several rigorous benchmarks to test both domain-specific and generalized reasoning:

  • Math Reasoning: AIME (2024/2025), AMC, MATH, MINERVA, and OLYMPIAD Bench.
  • Science/General: GPQA (out-of-domain scientific reasoning).
  • Code & Logic: PRIME-RL (code) and SynLogic (logic) to demonstrate generalizability beyond pure mathematics.

Key Findings and Insights

  • Compute Scaling and Efficiency: To match the performance of Knapsack RL using a budget of 2,048 rollouts, standard GRPO required 4,096 rollouts. This represents a 2x scaling efficiency.
  • Performance Boost: Knapsack RL improved average scores by 2–4 points, with peak gains of up to 9 points on specific benchmarks like AMC.
  • The Effective Gradient Ratio (EGR): EGR measures the percentage of rollouts that actively contribute to a non-zero gradient. Knapsack RL improves this ratio by up to 40%, drastically reducing "thrown away" compute.
  • Proactive Heterogeneity: Unlike dynamic sampling (which generates rollouts and then filters them), Knapsack RL is proactive. It decides the budget before generation. In practice, the algorithm might assign as few as 2 rollouts to "solved" prompts and up to 93 rollouts to high-value, challenging prompts within the same batch.
  • Hard-Task Bias: The underlying mathematics reveal that hard prompts (low $p$) are inherently more valuable than their "easy mirror" prompts (high $1-p$). There is simply more "room to grow" on a difficult task than on one that is already 90% solved.

Limitations and Future Directions

While highly effective, the authors note a few areas for future refinement:

  • Success Rate Estimation: The method currently relies on estimating the success rate $p$ from the previous epoch's history. Implementing online predictive models using prompt embeddings could yield more accurate, real-time estimates.
  • Token-Level Costs: The current framework treats every rollout as one unit of cost. However, harder prompts often elicit longer Chain-of-Thought (CoT) responses. Transitioning to a "token-aware" knapsack formulation is a logical next step.
  • The "Extremely Hard" Ceiling: Even with massive rollout budgets, about 20% of prompts remained "extremely hard" (0% success). Tackling these toughest cases may require combining Knapsack RL with trajectory reuse or replay buffers.

Summary updated

BibTeX
@inproceedings{li2026knapsack,
  author = {Ziniu Li and Congliang Chen and Tianyun Yang and Tian Ding and Ruoyu Sun and Ge Zhang and Wenhao Huang and Zhi-Quan Luo},
  title = {{Knapsack RL: Compute-Efficient Reinforcement Learning via Heterogeneous Rollout Allocation}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=v70fTOqer2},
}
Figure