Skip to main content

Revision sheet — Compression and LLMs

Predict to code, compress a model, measure the actual cost

The distinction to remember: what exactly is being compressed? A sequence, the model parameters, or the memory used during inference? These are different budgets addressing different problems.

The mental map

flowchart TD
  A["Compression around an LLM"] --> B["Sequence / data"]
  A --> C["Model / checkpoint"]
  A --> D["Runtime memory"]
  B --> E["Conditional probabilities"]
  E --> F["Surprisal: -log₂ p(token | context)"]
  F --> G["Entropy coder: exact decoding"]
  C --> H["Quantization · pruning · distillation"]
  D --> I["KV cache · activations · buffers"]

Question Concept Mechanisms / metrics
Can a sequence be represented with fewer bits? Predictive compression Probabilities, surprisal, bits/token, code length
Can the model itself be made smaller to store or deploy? Model compression Quantization, pruning, distillation; size, memory, quality, latency
How much memory is needed during generation? Runtime memory KV cache, activations, buffers; peak memory and throughput

1. Predict to code

An autoregressive model factorizes a sequence probability:

\[ p(x_{1:T})=\prod_{t=1}^{T}p(x_t\mid x_{<t}). \]

The ideal cost of an observed token, in bits, is its surprisal:

\[ I_t=-\log_2 p(x_t\mid x_{<t}). \]

The ideal sequence length is therefore:

\[ L^*(x_{1:T})=-\sum_{t=1}^{T}\log_2 p(x_t\mid x_{<t}). \]

Interpretation: the higher the probability assigned to an observed token, the lower its ideal code cost. Average cross-entropy measures this average cost under a given data distribution and logarithm convention.

WarningA probability distribution is not enough to decompress

A compatible encoder and decoder (for example, arithmetic coders), the same model, tokenizer, symbol order, and numerical conventions are required. Decoding must reconstruct the exact sequence. Generating a plausible continuation is not decompressing the corpus. LLM weights are not a literal archive of the training corpus: they parameterize a probability model but do not provide an exact-reconstruction protocol.

NoteThe corpus is a ceiling, not a floor

For a fixed dataset, training cannot place more information about the data distribution into the parameters than the corpus and the prior choices (architecture, preprocessing) contain. Changing architecture (Transformer, Mamba, RWKV…) changes extraction efficiency, not the ceiling. Two qualifications: the thermodynamic analogy (Landauer’s limit) is an illustration, not a proof — it concerns physical irreversible erasure, not learning; and Shannon’s absolute ceiling differs from the information extractable by a given model family (predictive (V)-information): synthetic data produced by a model adds, by itself, no Shannon information beyond what the generator encodes, but it can restructure regularities to make them more extractible — at the risk of also baking in the generator’s errors. See the information-theory revision sheet.

2 bis. Entropy, surprise, and utility are not synonyms

For a given predictive distribution:

  • Predictive entropy: the model’s average uncertainty about the next token.
  • Observed surprisal: the information cost of the token that actually occurred, ( -2 p(x_tx{<t}) ).
  • Attention-weight entropy: how dispersed attention weights are across context positions.
  • KV-cache drift: the difference between a retained state and the state that would be recomputed.

These signals do not directly measure token utility. A highly predictable token can still be essential to syntax or reasoning; a rare token can be decisive. Low entropy alone does not justify pruning.

The entropy-versus-surprisal experiment illustrates the distinction with a binary source. It does not test an LLM.

Advanced direction: some methods use attention-weight entropy to allocate a KV-cache budget, while others use decoded-distribution entropy to decide whether to recompute a cache. These are different signals and protocols. See the critical synthesis on compression and inference efficiency.

2. Reduce the model

Technique What changes What must be measured
Quantization Numerical precision of weights and/or activations Size, memory, quality, latency under specific kernels and hardware
Pruning Weights or structures are removed Is the resulting sparsity actually exploited by hardware?
Distillation A student learns to imitate selected teacher behaviours Which behaviours are retained, on which tasks, and with what loss?

A smaller checkpoint is not automatically faster: format, kernels, hardware, batch size, and context length matter. For a critical review of model-compression methods and trade-offs, see the model-compression synthesis.

MDL: count the model as well as the data

The predictive-compression discussion above assumes that the model is already available. If the model must also be described or transmitted, the total cost becomes:

\[ L_{\mathrm{total}}(M,D)=L(M)+L(D\mid M). \]

  • \(L(D\mid M)\): the code length of the data when the decoder knows model \(M\); for a probabilistic model, it is related to \(-\sum_t \log_2 p(x_t\mid x_{<t},M)\).
  • \(L(M)\): the cost of describing the model in a chosen description language and model class: parameters, structure, and required side information.

The Minimum Description Length (MDL) principle seeks a trade-off between these two costs. A model that memorizes the examples may sharply reduce the residual cost \(L(D\mid M)\), but its own description cost \(L(M)\) can cancel that gain. Conversely, a very simple model is cheap to describe but leaves more regularities unexplained.

Do not conflate: \(L(M)\) is not automatically the size of the weights file alone. Specify what is shared in advance (architecture, tokenizer, decoder), what must be transmitted, numerical precision, and the model class being compared. Practical MDL therefore depends on a protocol; it is neither the generally uncomputable Kolmogorov complexity nor a guarantee that the selected model is “true” or will always generalize.

The forward/reverse and model-description-cost experiment illustrates this trade-off on synthetic data. Its fixed parameter cost is an explicit pedagogical convention, not a universally optimal code.

Questions and exercises on compression and MDL.

3. Keep the budgets separate

  • Persistent storage: checkpoint weights and related files.
  • Runtime memory: KV cache, activations, and buffers during inference.
  • Communication: cost of transmitting the model, metadata, and possibly data.

Quantizing the KV cache reduces a runtime-memory budget; it does not mean that the weight file has been reduced.

4. What the repository experiment shows

The exact predictive-coding experiment uses a synthetic bigram model over four symbols.

Measure Result
Ideal model cost 19.642 bits
Actual finite binary code 21 bits
Uniform baseline 40 bits
Exact reconstruction Yes

These numbers cover only the test message. They exclude transmission of the model trained on 40 symbols, the tokenizer, and metadata. This is neither an LLM benchmark nor evidence of net compression for a complete system.

3Blue1Brown: deriving entropy from coding

The video Reinventing Entropy — Compression is Intelligence, Part 1 builds an intuition for the link between ideal code length and information: an event with probability \(p\) corresponds to \(-\log_2 p\) bits in the ideal case. It introduces prefix-free codes, moves from the information of one event to average information, and then to the entropy rate of a sequential source.

Keep the qualifications: a prefix-codeword length is an integer, while surprisal can be fractional; Shannon’s bound concerns average length. A coded stream that looks close to random noise is a useful idealized intuition, not a universal test of optimality. Shannon’s historical estimate of roughly one bit per English character depends on his experimental protocol and is not a universal constant of the language.

The 16 July 2026 AIhub page relays the same video; it is not an independent source.

5. Two compression strategies: a hypothesis to examine

Mingdi Fan’s philosophical paper distinguishes selective, narrative compression, oriented toward causal structure, from probabilistic compression, which fits a distribution by minimizing cross-entropy. The author calls these poles “positive subjectivity” and “negative subjectivity”, and proposes a mixed, “grey” strategy.

This raises a useful question: does good prediction alone measure the quality of learned structure? No. Cross-entropy measures how well a model assigns probabilities to observations; it does not directly measure representational parsimony, recombination, understanding, or semantic grounding.

Dimension What it can measure What it does not establish by itself
Cross-entropy Average predictive quality under a specified distribution and logarithm convention Understanding, causality, consciousness
Epiplexity Structured information accessible under specified computational constraints A universal measure of intelligence
Transfer / recombination Reuse of regularities in new situations Subjective experience

Keep the qualifications: epiplexity is a recent research concept; Fan’s mapping between An/Fn algebraic structures and neural networks is an analogy, not a theorem about LLMs. The paper’s definition of understanding in terms of “structural effectiveness” is a philosophical proposal, not a scientific consensus.

The sequential-structure and predictive-compression experiment compares unigram and bigram models on synthetic data. It illustrates the use of sequential dependencies; it does not calculate epiplexity or measure understanding.

See the critical synthesis of Mingdi Fan’s paper and the detailed source review.

6. Keeping useful information is not the same as decompressing everything

In “Compression Is Intelligence”, David Chen connects feature selection, compact document representations, neural lossless coding, and short prompts. The connection is stimulating as long as we do not conflate their mechanisms.

  • Feature selection: a small set of terms may suffice for a particular ranking task. Rau, Dehghani and Kamps (2024) study document ranking; this does not demonstrate that a handful of words preserves the full meaning of a text.
  • Predictive lossless coding: Fabrice Bellard’s NNCP predicts the next symbol and then uses arithmetic coding to produce an exactly decodable bitstream. It concretely demonstrates the link between conditional probability, ideal code length, and lossless reconstruction.
  • Conditional generation: a short prompt can guide a long output, but an LLM does not invert a known lossless encoder. It does not recover one unique original message or guarantee that omitted constraints are preserved. “Decompression” is an analogy here; conditional expansion is more precise.
Question Term selection NNCP Prompt to LLM
Compact object Salient terms Shared probability model + coded stream Partial instruction
Objective Ranking / classification Exact reconstruction Plausible continuation conditioned on context
Typical failure A rare but decisive term is discarded Encoder/decoder disagreement An implicit constraint is omitted or invented

Takeaway: every compression claim is relative to a task, representation, and distortion criterion. Bits per byte, ranking quality, and generation fidelity are not interchangeable metrics. The critical source review details the limits of the references and analogy.

Reconstruct the reasoning, step by step

The pedagogical progression in 3Blue1Brown can be replayed as a chain of six questions. It complements the canonical lessons; it does not replace them.

  1. Which events are frequent? Start with a small alphabet and a frequency distribution. Ask which symbols deserve the shortest codewords.
  2. How can decoding be unambiguous? Build a binary tree and stop at leaves: no codeword may be a prefix of another. Check Kraft’s sum. The experiment below provides a testable Huffman code.
  3. What does an event cost? Derive surprisal, \(I(x)=-\log_2 p(x)\). A rarer event costs more. This ideal length can be fractional, unlike the integer length of a binary codeword.
  4. What does a source cost on average? Average surprisal under the distribution to obtain entropy. Do not confuse this expectation with the surprisal of one observed symbol.
  5. What if events depend on context? Replace \(p(x_t)\) with \(p(x_t\mid x_{<t})\). The chain rule turns the product of conditional probabilities into a sum of costs: the bridge to autoregressive prediction.
  6. How do we evaluate an imperfect model? Compare the target distribution \(q\) with the predicted distribution \(p\). Cross-entropy \(H(q,p)\) is the average coding cost under \(q\) when coding with \(p\); for a one-hot target, it becomes the observed token’s NLL. The Cross-entropy lesson formalizes this final step.

flowchart TD
  A["Symbol frequencies"] --> B["Prefix-code tree"]
  B --> C["Ideal length: -log₂ p(x)"]
  C --> D["Average: entropy H(X)"]
  D --> E["Context: p(xₜ | contexte précédent)"]
  E --> F["Sequence cost: sum of surprisals"]
  F --> G["Model p evaluated on targets q: H(q,p)"]

This sequence separates three levels: coding intuition (tree and codewords), information-theoretic identities (surprisal and entropy), and language-model evaluation (conditional cost and cross-entropy). It avoids jumping from a formula straight to a claim about “intelligence”.

7. Empirical study: predictive compression as a capability signal

Huang, Zhang, Shan, and He (COLM 2024) test whether a model’s predictive coding cost is associated with downstream task performance. Their study covers 31 public pretrained LLMs, 12 benchmarks, and three external corpora aligned with the evaluated domains: Common Crawl for knowledge and commonsense, GitHub Python repositories for coding, and arXiv mathematics papers for mathematical reasoning.

To compare models with different tokenizers, the authors measure bits per character (BPC), rather than bits per token:

\[ \mathrm{BPC}(M,C)= \frac{\sum_t -\log_2 p_M(x_t\mid x_{<t})} {\text{number of characters in }C}. \]

The numerator is the ideal code length in bits assigned to the text by the model; the denominator normalizes by the corpus character count. The protocol fixes a context window of 1,900 tokens. BPC therefore depends on the corpus, its normalization, and the evaluation protocol; it is not an intrinsic constant of a model.

The authors report the following Pearson correlations between BPC and aggregated benchmark scores:

Evaluated domain BPC / score correlation
All tasks -0.93
Knowledge and commonsense -0.935
Coding -0.937
Mathematical reasoning -0.953

The negative sign means that, in this sample, lower BPC is associated with higher scores. This is a strong empirical result within the studied protocol, not evidence that compression causes intelligence or that the two are identical.

Conditions and limitations to preserve

  • Domain alignment matters: the reported cross-domain controls weaken the relationship when the compression corpus does not match the benchmark domain. BPC measured on code is not a universal capability score.
  • Benchmark scores are proxies: the 12 benchmarks cover selected knowledge, coding, and mathematics tasks; they do not define intelligence, robustness, or real-world competence as a whole.
  • Contamination is hard to establish: the authors use MIN-K% PROB as a signal of possible benchmark exposure and exclude Qwen outliers from the mathematical fit. This indirect diagnostic is not proof of contamination.
  • The scope is base models: the results do not automatically transfer to instruction-tuned or reasoning models, whose learned distributions and behavior differ.
  • Correlation does not identify a causal mechanism: scale, data, architecture, and training may influence BPC and benchmark scores simultaneously.
  • The result is historical and bounded: it describes the models and benchmarks in the 2024 study, under a controlled context window; it is not a current model leaderboard.

How should LLM Lab use this result?

The paper provides a case study connecting cross-entropy, predictive compression, and evaluation: better probabilistic modeling of a relevant corpus can be a useful signal of capabilities measured in a related domain. It motivates studying BPC as a complementary signal, provided the corpus and protocol are documented and the result is checked against task-specific evaluations. It does not justify a single domain-independent score, replacing benchmarks, or conflating predictive compression with quantization, pruning, or distillation.

Sources: COLM 2024 paper · official repository and protocol · LLM Lab critical review · structured extraction.

From information to agency: four levels to keep distinct

Compression provides a useful thread, but it is not a sufficient definition of intelligence. Separate four levels:

Level Question Concepts and criteria
1. Information What are the uncertainty and coding cost? Entropy, surprisal, cross-entropy; specify the distribution and protocol.
2. Learning How does a model capture regularities? Conditional prediction, predictive compression, and MDL; count both model and residual costs.
3. Adaptation How does a system update its beliefs or skills? New data, model updates, transfer, and adaptation cost; measure gains on held-out situations.
4. Agency How does a system choose actions in an environment? AIXI combines universal prediction with reward maximization; active inference connects perception and action within the Free Energy Principle framework.

These levels are related but not interchangeable. Good prediction alone does not establish effective adaptation; low coding cost does not demonstrate causality or the ability to act. AIXI and active inference are distinct theoretical frameworks, not automatic consequences of MDL.

For the agentic frameworks and their limitations, see Universal artificial intelligence and the cross-source synthesis on compression, intelligence, and inference.

Go deeper