Memory-Compute Tradeoff

Memory-compute tradeoff describes techniques that reduce memory use by spending more computation, or reduce computation by spending more memory. It appears in training, inference, retrieval, and data loading.

A rough training memory budget is:

For autoregressive inference, KV cache can dominate:

where is sequence length, is the number of attention heads, and is head dimension.

The tradeoff should be judged by the actual constraint:

Optimizing one term can make another worse.

Examples

  • Activation checkpointing saves memory by recomputing activations.
  • Gradient accumulation increases effective batch size without fitting the full batch at once.
  • Quantization reduces parameter and cache memory.
  • Caching avoids recomputation but consumes memory.
  • Sharding distributes parameters, optimizer state, or activations across devices.

Technique Map

TechniqueSavesPays WithWatch
Activation checkpointingactivation memoryrecomputationlonger step time
Gradient accumulationbatch memorymore micro-stepsoptimizer-step accounting
Quantizationparameter/cache memoryaccuracy or kernel constraintscalibration and hardware support
KV cachedecode computememory capacitycontext length and concurrency
Shardingper-device memorycommunicationbandwidth and failure complexity
Caching embeddings/featuresrepeated computestorage and stale artifactsdata-version alignment

Checks

  • Is the bottleneck capacity, bandwidth, compute, or communication?
  • Are parameters, activations, optimizer state, gradients, or KV cache dominant?
  • Does the technique change numerical behavior or only resource use?
  • Is wall-clock time, cost, or maximum problem size the real constraint?
  • Does a smaller model or shorter context solve the problem more simply?
  • Are comparisons made at fixed quality, fixed latency, fixed cost, or fixed memory?
  • Does the run record state which resource tradeoff was intentionally chosen?