Predicting Task Performance with Context-aware Scaling Laws

Kyle Montgomery, David Park, Jianhong Tu, Michael Bendersky, Beliz Gunel, Dawn Song, Chenguang Wang

TL;DR

Conventional scaling laws predict pre-training loss from compute and dataset size, but they fail to capture downstream task performance where context length and in-context examples are paramount. This paper introduces an interpretable, context-aware scaling law that jointly models downstream performance as a function of training compute, prompt length, and the model's context limit. The resulting formula accurately predicts task performance and generalizes across three orders of magnitude in compute, up to 128k tokens in context, and across different context-extension techniques.

What Problem Does This Paper Address?

While traditional neural scaling laws (e.g., Kaplan et al., Chinchilla) accurately link upstream cross-entropy loss to compute, parameters, and tokens, upstream loss frequently diverges from actual downstream task performance (such as accuracy or BLEU score).

Existing attempts to predict downstream performance either rely on complex two-stage models (using upstream loss as an intermediary) or black-box neural networks (like MLPs). Critically, standard approaches treat prompt context as static, ignoring both the number of in-context demonstrations and the hard failure modes that occur when input prompts exceed a model’s maximum context window ($n_{\text{ctx}}$).

Methods

The authors propose an intuitive, closed-form scaling law that models aggregate downstream task performance $P(C, n_{\text{pmt}}, n_{\text{ctx}})$ as the product of two saturating power laws and a sharp penalty term:

$$P(C, n_{\text{pmt}}, n_{\text{ctx}}) = \underbrace{\left[ 1 - \exp\left(-A \left(\frac{C}{C^c}\right)^\alpha\right) \right]}_{\text{Saturating term in Compute } C} \times \underbrace{\left[ 1 - \exp\left(-B \left(\frac{n_{\text{pmt}}}{n_{\text{pmt}}^c}\right)^\beta\right) \right]}_{\text{Saturating term in Prompt Length } n_{\text{pmt}}} \times \underbrace{\sigma(n_{\text{pmt}} - n_{\text{ctx}})}_{\text{Penalty term}}$$

  • Complementary Multiplicative Terms: Compute $C$ and prompt length $n_{\text{pmt}}$ multiply rather than add; a deficit in model capability limits the benefit of longer context, and vice versa.
  • Saturation: Both terms saturate via exponentiation, bounding the theoretical task metric below 1.0.
  • Sigmoid Penalty: A steep sigmoid drop penalty applies once prompt length exceeds the model's context limit ($n_{\text{pmt}} > n_{\text{ctx}}$), capturing the catastrophic generation breakdown beyond positional encoding limits.
  • Fitting Strategy: A two-stage optimization combining a global evolutionary search (scipy.optimize.differential_evolution) with local non-linear least squares refinement (scipy.optimize.curve_fit).
  • Context Extension: Models (Llama-2-7B and 13B) were extended to context limits from 8k up to 128k tokens using YaRN fine-tuning on the PG-19 corpus.

Datasets

The authors evaluated 12 extended Llama-2 checkpoints across 65,500 instances packed with up to 511 in-context demonstrations:

  • Arithmetic Reasoning: 3,550 test instances sampled from GSM8K, MATH, AQUA-RAT, and DeepMind Math.
  • Commonsense Reasoning: 1,750 test instances across PIQA, SIQA, OpenBookQA, HellaSwag, WinoGrande, ARC-Easy/Challenge, and CommonSenseQA.
  • Machine Translation: 250 instances from WMT-14 across 5 translation pairs (German, French, Hindi, Czech, Russian to English), evaluated with BLEU-4.
  • Synthetic Validation: The RULER benchmark (13 needle-in-a-haystack tasks) was used to verify effective context expansion.

Key Insights and Ideas

  • Context Returns Saturate Differently by Task: In arithmetic reasoning, models benefit from many examples with sub-linear saturation ($\beta \approx 0.56$). In contrast, commonsense reasoning and translation saturate much earlier and super-linearly ($\beta = 1.12$ and $2.97$), meaning only a handful of examples are necessary to establish the output format before marginal returns hit zero.
  • Extending Context Can Degrade Unrelated Tasks: When holding prompt length fixed, models fine-tuned to larger context limits ($n_{\text{ctx}}$) performed slightly worse on translation and commonsense tasks. This was attributed to domain misalignment during context extension (PG-19 is primarily English literature).
  • Invariance to Context-Extension Method: The scaling behavior remained virtually identical whether the context window was enlarged using YaRN or Positional Interpolation (PI).

Key Results

  • In-Distribution Accuracy: The equation closely tracked real-world performance, achieving mean absolute errors of 0.010 on arithmetic reasoning, 0.037 on commonsense reasoning, and 0.007 on machine translation.
  • Compute Extrapolation: When evaluated out-of-distribution across models spanning three orders of magnitude in compute (from Qwen2.5-0.5B up to Llama-2-70B and Gemma-2-27B), prediction errors were frequently under 5 percentage points (e.g., Llama-2-70B had errors of -0.002 on arithmetic and -0.025 on translation).
  • Context Extrapolation: Holding out prompts longer than 10k tokens and predicting performance up to 128k tokens yielded low generalization errors: 0.017 (arithmetic), 0.067 (commonsense), and 0.006 (translation).
  • Ablation of Penalty Term: Removing the sigmoid penalty increased arithmetic test prediction error nearly threefold (from 0.010 to 0.029 overall, and from 0.014 to 0.104 for inputs exceeding $n_{\text{ctx}}$).

Limitations and Future Work

  • Omitted Architectural and Training Factors: The formula does not explicitly parameterize pre-training mixture variations, post-training alignment (e.g., instruction tuning or RLHF), or attention architectures.
  • Adversarial / Extreme Regimes: The monotonic saturation assumption may break under attacks like many-shot jailbreaking or extreme input lengths where attention sinks fail.
  • Fitting Base: Initial parameters were fit on a compute band centered on Llama-2 7B and 13B; expanding the initial fitting regime to broader model scales could further improve out-of-distribution precision.

Summary updated

BibTeX
@inproceedings{montgomery2025predicting,
  author = {Kyle Montgomery and David Park and Jianhong Tu and Michael Bendersky and Beliz Gunel and Dawn Song and Chenguang Wang},
  title = {{Predicting Task Performance with Context-aware Scaling Laws}},
  booktitle = {KnowFM @ ACL},
  year = {2025},
  url = {https://openreview.net/forum?id=131V12fEUR},
}

Loading related content...

Figure