Skip to main content
Back

Engram's Bit-Based Formula Predicts the Right LoRA Rank Without Costly Training Runs

Engram derived a closed-form formula for the minimum LoRA rank needed to fit any SFT dataset, predicting rank within 5% error on real workloads.

Paper, Full Access
  • Engram published a theory for computing the minimum LoRA rank needed to fit any SFT dataset
  • Capacity formula: C(r) ≈ E[σ₁²+...+σᵣ²]/(2 ln 2) bits, derived from Fisher information analysis
  • Predicts rank within 5% error across real datasets including GSM8K, MATH-500, Tulu 3, SWE-bench
  • A 24-layer model stores 3.3 bits/parameter versus 1.5 for a single layer, due to super-additive stacking
  • Models forget roughly as many bits as they learn, a conservation law holding across all runs
  • Experiments use Qwen3.5-0.8B; method skips rank sweeps by sizing adapters from dataset bit-count

LoRA rank is commonly selected through repeated training runs at values such as 8, 16, 32, and 64. An Engram analysis proposes a cheaper method: estimate how much information a fine-tuning dataset contains, calculate how much a low-rank adapter can store, and choose the smallest rank with sufficient capacity. Engram tested the approach on internal workspaces and public benchmarks using Qwen3.5-0.8B.

Low-rank adaptation, or LoRA, freezes a pretrained weight matrix and learns an update factored as ΔW = BA. For an m × n weight matrix, rank r adds approximately r(m + n) trainable coefficients. Rank therefore affects adapter size, training cost, serving throughput, and the amount of dataset-specific information the update can represent.

Cross-entropy doubles as a bit counter

The method expresses both the dataset and the adapter in bits. A dataset’s information size is its negative log-likelihood under the frozen base model:

I(D | M₀) = −Σ log₂ pM₀(xₜ | x<ₜ)

Shannon’s source-coding theorem connects this quantity to compression: tokens assigned high probability require fewer bits to encode. If training loss is reported in nats, dividing by ln 2 converts it to bits. An average loss must also be multiplied by the number of scored tokens.

Supervised fine-tuning should use the same token mask for measurement and training. For instruction data, that usually means conditioning on the prompt while scoring only response tokens. The adapter’s learned information is the reduction in total negative log-likelihood relative to the base model.

Synthetic calibration datasets provide examples with controlled information content. Engram generated them by running arithmetic coding in reverse: begin with a random bitstream, decode it through the base model, and obtain text sampled from that model with a known code length. Training LoRAs on these samples reveals how many bits each rank can store while limiting confounding structure in the data.

A formula for adapter storage

Using a second-order likelihood approximation based on the Fisher information matrix, the authors estimate the capacity of a rank-r adapter as:

C(r) ≈ E[σ₁² + σ₂² + ... + σᵣ²] / (2 ln 2) bits

The σᵢ terms are singular values of a Gaussian matrix with the dimensions of the adapted weight. The expectation averages over random draws. In the low-rank regime, the expression simplifies to:

C(r) ≈ r(√m + √n)² / (2 ln 2)

At full rank, where r = min(m, n), the capacity becomes:

Cfull ≈ mn / (2 ln 2)

This full-rank result matches the asymptotic likelihood gain associated with Wilks’ theorem. For one 512 × 1024 attention value projection in Qwen3.5-0.8B, the formula predicts about 378,000 bits at full rank. That corresponds to roughly 0.48 bits per trainable LoRA coefficient at full rank and 1.3 to 1.4 bits per coefficient at low rank. Average efficiency declines as rank grows because later directions correspond to smaller singular values.

Depth changes the budget

Applying adapters across multiple transformer layers produced more capacity than summing isolated single-layer estimates. In Engram’s reported setup, a single adapted layer stored about 1.5 bits per trainable parameter, while adapters spanning 24 layers stored about 3.3 bits per parameter. The experiments establish this super-additive effect, but the single-matrix theory does not yet explain it.

Capacity measurements also require an estimate of what training would achieve near convergence. Engram fits a log-logistic curve to the trajectory of bits learned over optimization steps and extrapolates its asymptote, following an approach related to an infinite-compute study. This avoids running every calibration experiment until progress fully stops.

Learning and forgetting balance in bits

Learned bits
The decrease in negative log-likelihood on the fine-tuning dataset after applying the adapter.
Forgotten bits
The increase in negative log-likelihood on fresh samples drawn from the base model.

Across the reported runs, learned and forgotten information remained similar in magnitude:

  • Adapters forgot roughly as many bits as they learned.
  • An adapter that learned 10 KB of new information forgot about 12 KB from the base distribution.
  • The relationship persisted across tested ranks, dataset sizes, and layer counts.

The authors attribute the pattern to the base model’s expected gradient on its own samples. That gradient has mean zero, so improving likelihood on selected training examples produces an offsetting likelihood cost elsewhere under the approximation. This metric measures distributional likelihood shift; factual retention and downstream task performance require separate evaluations.

Real data puts the estimate to work

Validation on Qwen3.5-0.8B followed three steps:

  1. Measure dataset information. Score the training tokens under the frozen base model and sum their negative log-likelihoods in bits. Engram used YaRN to extend context to two million tokens, then summed scores across windows for larger datasets.
  2. Predict the required rank. Map the dataset’s bit count onto a synthetic capacity curve built for the same model, target modules, and layer placement.
  3. Measure the threshold. Train real-data adapters at several ranks, fit their capacity curve, and locate the rank that stores 95% of the dataset’s measured information.
Reported rank estimates for Qwen3.5-0.8B
Dataset Information size Reported comparison
Engram internal emails 6.8 KB Predicted threshold 3.45; fitted observed threshold 4.26
GSM8K 236 KB Predicted rank 96; observed rank 95 on the final MLP
MATH-500 and SWE-bench Django 20 KB to 550 KB Predicted ranks tracked the measured thresholds closely
Tulu 3, No Robots, and OpenThoughts3 666 KB to 1.2 MB Predictions remained close with adapters on all eligible linear layers

The information-size column reports base-model negative log-likelihood divided by eight as byte equivalents; raw file sizes can differ. Fractional ranks come from interpolation on fitted curves. Deployable LoRA ranks remain integers, so a capacity estimate should be rounded up.

Engram summarizes the full suite as achieving roughly 5% agreement between predicted and measured rank. The displayed email thresholds differ by 0.81 rank, about 19% of the observed value, making the aggregate figure an overall result rather than a per-dataset error bound.

What changes in production

A capacity curve can be reused for datasets that share the same base model, loss mask, target modules, and layer placement. Each new dataset then requires a base-model scoring pass and a curve lookup. A nearby rank check can replace a broad logarithmic sweep.

  • Training: fewer full fine-tuning runs are needed to select an initial rank.
  • Storage: the chosen adapter can avoid unused parameters at unnecessarily high ranks.
  • Serving: smaller adapters reduce transfer and memory costs in multi-tenant systems such as S-LoRA.
  • Reproducibility: rank selection follows a measured dataset property and a documented capacity target.

Limits that affect deployment

  • Capacity is asymptotic. The fitted curve estimates performance with extended training. A fixed compute budget, optimizer choice, or learning-rate schedule may prevent an adapter from reaching that ceiling.
  • Task quality needs its own metric. A rank that stores 95% of dataset information may differ from the rank that maximizes validation accuracy, preference scores, or generalization.
  • The Fisher approximation is imperfect. The derivation relies on a Kronecker-factored structure that does not hold exactly in trained neural networks.
  • Depth remains empirical. The observed super-additive capacity across layers lacks an analytical correction, so multi-layer estimates depend on calibration curves.
  • Model coverage is narrow. The reported experiments use Qwen3.5-0.8B. Larger architectures, other model families, and quantized training configurations remain unverified.
  • Calibration is configuration-specific. Changing target modules, layer count, loss masking, or the base checkpoint can require a new capacity curve.

For production use, the method provides an initial rank for a fixed model and adapter layout. Teams can score the dataset, round the predicted rank up, and evaluate a small neighborhood under the actual task metric and compute budget. This limits rank testing to a calibrated range while making the underlying capacity measurement reusable.