Cost-Aware SGD: Theory and Applications to LLM Policy Optimization

Clara Mohri, Amir Globerson, Haim Kaplan, Tomer Koren, Yishay MansourNeurIPS 2026

TL;DR

Standard optimization theory treats every gradient step like a flat-rate buffet: whether a data point is tiny or massive, we pretend it costs the same to digest. In reality—especially when training reasoning LLMs—long sequences cost exponentially more compute than short ones. This paper introduces Cost-Aware SGD, a mathematically optimal way to sample training data by balancing how much a sample teaches the model against how much compute it burns, cutting LLM reinforcement learning costs by roughly a third without losing accuracy.

What Problem Does This Paper Address?

For decades, Stochastic Gradient Descent (SGD) has been analyzed by counting iterations: how many steps does it take to get the error down? That makes sense when every data point is a uniform 224×224 image. It falls apart in modern Large Language Model (LLM) post-training.

When we use Reinforcement Learning (RL) to teach LLMs math or reasoning—using algorithms like GRPO (Group Relative Policy Optimization)—the model generates several candidate answers ("rollouts") per prompt and updates its weights based on which ones succeeded. Because compute scales linearly with sequence length, calculating the gradient on a sprawling, 4,000-token chain-of-thought trace can cost an order of magnitude more FLOPs than a crisp, 200-token answer.

Existing importance-sampling techniques try to speed up training by picking data points with the largest gradients (variance reduction), completely ignoring how expensive those points are to process. The authors ask: How should we sample data when our budget is measured in total compute rather than step count?

Methods

The authors tackle this from first principles before scaling it up to billion-parameter LLMs:

  1. Cost-Aware SGD: Instead of sampling data uniformly, the authors use importance sampling (reweighting samples so the gradient estimate stays mathematically unbiased) to minimize total expected cost. Using the Cauchy-Schwarz inequality, they prove that the optimal sampling probability $p_i^*$ for data point $i$ is proportional to its gradient norm $G_i$ divided by the square root of its compute cost $c_i$: $$p_i^* \propto \frac{G_i}{\sqrt{c_i}}$$
  2. Cost-Aware GRPO (CA-GRPO): Applying this to LLMs hits an immediate snag: you can't know a sequence's exact gradient norm $G_i$ without running the expensive backward pass you're trying to avoid! The authors' clever workaround uses the advantage magnitude $|A_i|$—a score calculated virtually for free during GRPO that measures how much better or worse a response was compared to the group average—as a proxy for $G_i$, and the prompt-plus-response token count as the cost $c_i$. During policy optimization, mini-batches are sampled according to $|A_i|/\sqrt{c_i}$ (sometimes blended with a tiny $\alpha = 0.01$ splash of uniform sampling for stability).
Figure 2: Synthetic validation. We compare the error with the total training steps and the total cost incurred by each sampling strategy. For a fixed error target, the cost-aware sampling distribution incurs the least total cost. On the other hand, the variance strategy converges the fastest in terms of iteration count. This is expected, as it minimizes the gradient estimator’s variance without regard for computational budget.

Datasets

No new datasets are introduced; the authors use established math reasoning benchmarks where answers are easily verifiable:

  • Training: The DAPO dataset (specifically curated to improve AIME-style mathematical reasoning), plus a synthetic linear least-squares dataset ($N=3000$) to validate the core theory.
  • Evaluation: AIME 1983–2024 (primary benchmark), alongside AMC, MATH500, and GSM8K.

Key Insights and Ideas

  • Why the square root of cost? It's a classic Goldilocks trade-off. Sampling purely by gradient norm ($G_i$) minimizes the number of steps, as seen in the synthetic tests above, but happily bankrupts your GPU budget on massive sequences. Dividing by $\sqrt{c_i}$ is the exact mathematical sweet spot that minimizes the product of variance (how noisy the steps are) and expected cost per step.
  • A "free" proxy that actually works: Looking at the math of the policy gradient, the gradient norm is literally the advantage $|A_i|$ multiplied by the norm of the score function. Empirically, $|A_i|$ and the true sequence gradient norm have a Pearson correlation near $1.0$ across training! You get near-oracle sampling quality for zero extra FLOPs.
  • Wait—doesn't penalizing length make the model terse? You might worry that under-sampling long responses tricks the LLM into outputting short, lazy answers. Because importance weighting scales up the gradient of the rare long sequences that do get picked, the math stays unbiased: average response lengths shift by less than 3.5% compared to standard GRPO.

Key Results

Tested across Qwen2.5-Math-1.5B-Instruct, Qwen3-4B, and Qwen3-8B, Cost-Aware GRPO consistently reaches baseline peak accuracy at a fraction of the compute, and often finishes at a higher peak accuracy:

  • Qwen3-8B: Matches standard GRPO's peak AIME accuracy while using 29.6% fewer training FLOPs, 32.2% fewer total FLOPs (which includes rollout generation!), 38.5% less wall-clock time, and 43.2% fewer training steps.
  • Smaller Scales (1.5B & 4B): Adding slight uniform smoothing ($\alpha = 0.01$) shines here, cutting training FLOPs by 32.8% on the 1.5B model (while boosting peak AIME accuracy from 61.3% to 65.3%) and 26.9% on Qwen3-4B.
  • Generalization: Swapping GRPO for a different RL objective (CISPO) on the 1.5B model yields similar wins—requiring up to 34% fewer tokens to match baseline accuracy and ultimately outperforming it by ~4 percentage points.

Limitations and Future Work

  • Generation still costs money: CA-GRPO only optimizes the training (backward/forward pass) phase after rollouts are generated. While reaching accuracy targets in fewer steps indirectly cuts total generation FLOPs too, the algorithm still discards or under-samples rollouts you already paid to generate.
  • Theory gap on extreme outliers: There is a slight gap between the authors' theoretical upper bound and their information-theoretic lower bound when sample costs are wildly non-uniform—suggesting that sometimes it's better to permanently drop ultra-expensive data points (subset selection) rather than just sampling them rarely.
  • Static hyperparameters & proxies: Smoothing ($\alpha$) is currently fixed; scheduling $\alpha$ dynamically, finding even sharper gradient norm proxies than $|A_i|$, and extending cost-aware sampling to broader RLHF pipelines are left as open avenues.

Summary updated

Abstract

We consider the problem of Cost-Aware Learning, where sampling different components of a finite-sum objective incurs different costs. The objective is to reach a target error while minimizing the total cost. We propose Cost-Aware SGD, which uses a distribution based on gradient norms and costs to sample components. We provide a thorough analysis of this algorithm, including cost-improvement bounds over baselines, a characterization of distribution proxy sub-optimality, and a lower bound. We apply our theoretical insights to reinforcement learning with language models, where the cost of including a sequence in a policy-gradient update scales with its length. We find that advantage magnitude is a high-fidelity proxy for sequence-level gradient norms, motivating Cost-Aware GRPO. Across 1.5B, 4B, and 8B LLMs, Cost-Aware GRPO matches or exceeds baseline accuracy while using up to 33\% fewer policy-optimization FLOPs and 33\% fewer total FLOPs.
BibTeX
@inproceedings{mohri2026cost,
  author = {Clara Mohri and Amir Globerson and Haim Kaplan and Tomer Koren and Yishay Mansour},
  title = {{Cost-Aware SGD: Theory and Applications to LLM Policy Optimization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=d1T390yy1T},
}
Figure