Search

Search papers and lessons

Byte Latent Transformer: Patches Scale Better Than Tokens

Artidoro Pagnoni, Ram Pasunuru, Pedro Rodriguez et al. · 2024

Byte Latent Transformer reads raw bytes, groups them into variable-length patches by next-byte entropy, and runs the big Transformer once per patch, matching Llama 3 at 8B scale with up to 50% fewer inference flops.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

Byte Latent Transformer (BLT) is a language model that reads raw bytes and has no fixed vocabulary of tokens. It groups bytes into patches of varying length using a small model's next-byte entropy: a long patch where the next byte is easy to guess, a short one where it is hard. The large Transformer runs once per patch, so its cost follows the number of patches rather than the number of bytes. At up to 8B parameters and 4T training bytes, the authors report that BLT matches a Llama 3 baseline at equal training compute while using up to about 50% fewer inference flops.

Builds on: Transformer, Entropy, Neural Scaling Laws · Leads to: a byte-level alternative to Subword Tokenization, the tokenizer it replaces.

Why it mattered

BLT is a research architecture, so "why it mattered" means where its idea touches real systems and where it was tested against a deployed model.

Replacing the tokenizer in pre-training. Most large models first split text into tokens with a fixed vocabulary. The paper's baseline is a Llama 3 style model with a 128K-token vocabulary, trained on 1T tokens. BLT is trained on the same data and scored on the same benchmarks, which makes the question concrete: can a model with no tokenizer match one that has one? At 8B parameters the paper's answer is yes on average, with clear gaps on some tasks.

Cutting the cost of serving. A deployed model spends most of its inference compute in the large middle network, and that network runs once per patch. A service handling many requests can therefore get cheaper answers from longer patches. The paper reports that an 8-byte patch model would save nearly 50% of inference flops, at the price of a small loss on some metrics.

Handling noisy and low-resource text. Token vocabularies come from common text, so rare spellings, typos and uncommon scripts are split into awkward pieces. In the paper's FLORES-101 translation test, scored in BLEU, the gain is largest on low-resource languages: for Armenian to English BLT scores 6.3 where the Llama 3 baseline scores 1.7, and for Bengali to English 12.7 against 4.7.

The problem

A language model needs its input as a sequence of units. Today those units are tokens: byte groups drawn from a vocabulary fixed before training, usually by byte-pair encoding. The vocabulary is a compression heuristic that the model never learns, and it decides what the model can see. Two tokens that differ by one letter can be unrelated units, so the model has no direct access to the letters inside a token.

Tokens also tie compute to the vocabulary. A bigger vocabulary means longer tokens, fewer steps and a larger output layer, so the trade-off is locked in. The paper's Llama 3 comparison makes this concrete: going from Llama 2 to Llama 3 raised the average token size from 3.7 to 4.4 bytes, at the cost of a larger embedding table.

Byte-level models avoid the vocabulary, but they run into length. A byte sequence is several times longer than the same text in tokens, and the paper cites earlier work finding that directly training large models on bytes was prohibitively costly at scale. The open question is whether the length problem can be solved without going back to a fixed vocabulary, and whether doing so can match tokenized models at scale.

How it works

Take a tiny stream of six bytes, labelled x1 to x6. A token model would give the big network six steps. BLT decides where to spend those steps in six stages.

  1. Read the bytes. The input is raw bytes, each a number from 0 to 255, with no vocabulary merging. Suppose the stream is a b c d e f.
  2. Estimate how surprising each next byte is. A separate small byte-level language model reads the stream and gives a probability for each possible byte before each position. From those probabilities it computes the entropy H(x_i), a number in bits that is large when many outcomes are plausible and small when one outcome dominates. Suppose the values are 2.0, 0.3, 0.2, 2.5, 0.4 and 0.1 bits for x1 to x6.
  3. Start a new patch where entropy spikes. Set a threshold of 1.0 bit. A byte whose entropy is above the threshold starts a new patch, and the bytes after it stay in that patch until the next spike. Here x1 (2.0) and x4 (2.5) start patches, so the stream splits into x1 to x3 and x4 to x6. Check: those are the only two values above 1.0.
  4. Pool each patch into one vector. A lightweight local encoder reads the bytes and combines those of each patch into one patch representation. The patch is the unit the big network sees.
  5. Run the big network once per patch. The latent transformer processes two patch vectors instead of six byte vectors. Check: six bytes now cost two big-network runs, one third of the byte-by-byte cost.
  6. Decode back to bytes. A lightweight local decoder uses the patch outputs to predict the bytes one at a time, in order. The big network's output is never needed per byte, so the expensive step stays per patch.

The entropy curve for one binary choice shows why the threshold works. A fair coin is the most uncertain case, and a near-certain outcome carries almost no surprise.

0.20.40.60.800.20.40.60.81probability p of one outcomeentropy (bits)
  • entropy in bits
Entropy peaks at 1 bit when p is 0.5 and falls to about 0.08 bits when p is 0.99. Patch boundaries are placed where entropy is high.
flowchart LR
  A[Raw bytes] --> B[Small byte model: next-byte entropy]
  B --> C[Local encoder: pool bytes into patches]
  C --> D[Global latent transformer: one step per patch]
  D --> E[Local decoder: predict next bytes]
  E --> F[Output bytes]

The math

The subsections follow the walkthrough, with the step number in each heading.

Definition: Next-byte entropy

For a byte position i, with the bytes before it written as x<ix_{\lt i}, the entropy under the small byte model p_e is

H(xi)=−∑v∈Vpe(xi=v∣x<i) log⁡pe(xi=v∣x<i),H(x_i) = -\sum_{v \in \mathcal{V}} p_e(x_i = v \mid x_{\lt i}) \, \log p_e(x_i = v \mid x_{\lt i}),

where V\mathcal{V} is the set of 256 byte values. The sum runs over every possible next byte v, and H is measured in bits when the logarithm is base 2. The paper writes the sum without the leading minus sign; the minus makes the value non-negative, which is the usual convention.

Entropy of the next byte (step 2 in symbols)

Each term is a probability times its logarithm, so the sum is largest when all bytes are equally likely and near zero when one byte has probability close to 1. Two cases make this concrete. If the next choice is a fair coin, with probabilities 0.5 and 0.5, the entropy is −(0.5log⁡20.5+0.5log⁡20.5)=1-(0.5 \log_2 0.5 + 0.5 \log_2 0.5) = 1 bit. If the probabilities are 0.99 and 0.01, then log⁡20.99≈−0.0145\log_2 0.99 \approx -0.0145 and log⁡20.01≈−6.644\log_2 0.01 \approx -6.644, the sum is about −0.081-0.081, and the entropy is about 0.08 bits. A threshold of 0.5 bits would start a patch at the coin flip and continue the patch through the near-certain byte.

The model producing these probabilities is a 100M-parameter transformer with 14 layers, a hidden size of 512 and a 512-byte sliding attention window, trained on the same data as BLT. The paper notes that with a small enough receptive field the model could be stored as a lookup table.

Patch boundary (step 3 in symbols)

The paper gives two rules. The global rule starts a patch at byte i when H(xi)>θgH(x_i) \gt \theta_g, for one threshold θg\theta_g over the whole data. The approximate monotonic rule starts a patch when entropy rises sharply from the previous byte, H(xi)−H(xi−1)>θrH(x_i) - H(x_{i-1}) \gt \theta_r. The threshold is chosen so the average patch size on the training mix hits a target, such as 4.5 bytes or 8 bytes. Boundaries are computed once, in a lightweight preprocessing step during data loading, so the entropy model is not trained jointly with BLT.

Local encoder: bytes to patches (step 4 in symbols)

Each byte's input vector is its own embedding plus hashed embeddings of the byte n-grams that end at it, for n from 3 to 8:

ei=xi+∑n=3,…,8Enhash(Hash(gi,n)),gi,n={bi−n+1,…,bi}.e_i = x_i + \sum_{n=3,\ldots,8} E_n^{\text{hash}}\big(\text{Hash}(g_{i,n})\big), \qquad g_{i,n} = \{b_{i-n+1}, \ldots, b_i\}.

Here gi,ng_{i,n} is the set of the last n bytes, xix_i is the byte embedding and EnhashE_n^{\text{hash}} is an embedding table indexed by a hash of the n-gram. The paper uses 500,000 hash entries.

A patch query P0,jP_{0,j} is initialised by pooling the byte vectors of patch j. Each encoder layer then updates it with cross-attention over the bytes of that patch only:

Pl=Pl−1+Wo(softmax⁡ ⁣(QKTdk)V),Q=WqPl−1,K=Wkhl−1,V=Wvhl−1.P_l = P_{l-1} + W_o\left(\operatorname{softmax}\!\left(\frac{Q K^{T}}{\sqrt{d_k}}\right) V\right), \qquad Q = W_q P_{l-1}, \quad K = W_k h_{l-1}, \quad V = W_v h_{l-1}.

The keys and values come from the byte representations hl−1h_{l-1}, and a mask lets each patch query see only its own bytes. The matrices Wq,Wk,Wv,WoW_q, W_k, W_v, W_o are learned projections, and dkd_k is the key dimension.

Global transformer (step 5 in symbols)

The latent transformer is an autoregressive Transformer over patch vectors pjp_j, producing output vectors ojo_j, with block-causal attention so a patch sees itself and earlier patches. It runs once per patch, so its cost is set by the number of patches npn_p.

The paper's flop estimate, per byte, adds four parts: the global transformer divided by the patch size, the small encoder over bytes, the small decoder over bytes, and the cross-attention blocks. The global term is the one that shrinks as patches grow. The local terms do not, which is why the saving is less than proportional.

Numbers for step 5: a 1,000-byte text gives 1000/3.7≈2701000 / 3.7 \approx 270 big-network runs at Llama 2 token size, 1000/4.4≈2271000 / 4.4 \approx 227 at Llama 3 token size, and 1000/8=1251000 / 8 = 125 at an 8-byte patch size. Going from 227 to 125 is about 45% fewer steps. The flop saving is smaller than the step count suggests, because the local encoder and decoder still process every byte.

Decoder (step 6 in symbols)

The decoder reverses the roles. Byte vectors become the queries, and patch outputs become the keys and values. The byte vectors start from the encoder's last layer:

D0=hlE,Bl=Dl−1+Wo(softmax⁡ ⁣(QKTdk)V),D_0 = h_{l_{\mathcal{E}}}, \qquad B_l = D_{l-1} + W_o\left(\operatorname{softmax}\!\left(\frac{QK^{T}}{\sqrt{d_k}}\right) V\right),

where QQ comes from the byte vectors and K,VK, V come from the patch outputs. A decoder Transformer layer then produces DlD_l, and the output head predicts the next byte.

Bits per byte (for comparison across tokenizers)

Perplexity depends on the tokenizer, so the paper reports bits per byte:

BPB(x)=LCE(x)ln⁡(2)⋅nbytes.\text{BPB}(\boldsymbol{x}) = \frac{\mathcal{L}_{CE}(\boldsymbol{x})}{\ln(2) \cdot n_{\text{bytes}}}.

Here LCE\mathcal{L}_{CE} is the total cross-entropy loss in nats, nbytesn_{\text{bytes}} is the number of bytes, and dividing by ln⁡2\ln 2 converts nats to bits. Lower is better, and the number does not depend on how the text was split.

Results

Matching Llama 3 on a benchmark mix. Table 1 compares an 8B Llama 3 model with two BLT variants, all trained on the same budget. Llama 3 scores 77.6, 53.3, 79.1, 80.7, 58.1, 40.2 and 31.1 on Arc-E, Arc-C, HellaSwag, PIQA, MMLU, MBPP and HumanEval. BLT-Entropy scores 79.6, 52.1, 80.6, 80.6, 57.4, 41.8 and 35.4 on the same tasks. The averages are 60.0 and 61.1. Check: the Llama 3 scores sum to 420.1, and 420.1/7=60.0420.1 / 7 = 60.0; the BLT-Entropy scores sum to 427.5, and 427.5/7≈61.1427.5 / 7 \approx 61.1. BLT-Entropy is higher on four of the seven tasks, and its largest single gain is on HumanEval, 4.3 points.

The cheaper variant is weaker. BLT-Space, with 6-byte average patches, scores 58.0 on average, 2 points below Llama 3, and is lower on five of the seven tasks. The paper's explanation is that with the same training budget its larger patches cover about 30% more data, which moves it further from the compute-optimal point. The authors also lower BLT-Entropy's inference threshold from 0.6 to 0.1, which they report improves task performance at the cost of more inference steps.

Scaling with patch size. In the fixed-inference study, BLT models with average patch sizes of 6 and 8 bytes overtake the token-based scaling trend at a training budget that is only a few times the compute-optimal point. The crossover moves from about 3x to about 2.5x the compute-optimal budget as models grow. The paper's claim is that patch size and model size can grow together at a fixed inference budget. Table 2 lists the matched model sizes, for example a 470M Llama 2 model against a 760M BLT model with an 8-byte average patch.

Robustness and characters. On noised HellaSwag, BLT averages 64.3, against 56.9 for Llama 3 trained on the same 1T tokens. On that noise average the gap is 7.4 points. On CUTE, a character-level benchmark, BLT scores 54.1 against 27.5 for Llama 3, and it scores 99.9 on the two spelling tasks. Word deletion and insertion are the tasks where the token model is better.

Translation. On FLORES-101, BLT's overall average is 14.0 for translation into English against 12.1 for Llama 3, and 6.4 for translation out of English against 5.9. On high-resource pairs the two are close, and the gap is largest for low-resource scripts.

What the results do not show. The scaling laws used to choose sizes were fitted for token-based models, so they may give a suboptimal data-to-parameter ratio for BLT. Many of the scaling experiments were run at scales up to 1B parameters. The authors also say their code may not match tokenized models on wall-clock time. Patching is done by a separate entropy model rather than learned end to end, which is listed as future work. The benchmarks are the paper's own choice, so a team with its own traffic should test there.

Try it. The BLT-Space scores are 75.4, 49.8, 79.6, 81.1, 54.8, 37.6 and 27.4. Find the average over the same seven tasks and compare it with the paper. Answer: the sum is 405.7, and 405.7/7≈57.96405.7 / 7 \approx 57.96, which the paper rounds to 58.0.

Reading guide

Check yourself

QuestionWhat decides where BLT starts a new patch?Show answer

The entropy of the next byte, as estimated by a separate small byte-level language model. A new patch starts at a byte whose entropy is above a threshold, so uncertain bytes start patches and predictable runs stay in one patch. The threshold is set so the average patch size hits a target.

QuestionA text has 2,000 bytes. How many times does the latent transformer run at an average patch size of 8 bytes, and how many at 4.4 bytes?Show answer

At 8 bytes the count is 2000/8=2502000 / 8 = 250. At 4.4 bytes it is 2000/4.4≈4552000 / 4.4 \approx 455. The longer patches give about 45% fewer big-network runs, before the local models are counted.

QuestionWhy does a longer average patch size lower inference cost, and why is the saving less than proportional?Show answer

The latent transformer is the expensive part, and it runs once per patch, so more bytes per patch means fewer runs of that network. The saving is less than proportional because the small encoder and decoder still process every byte, and the cross-attention blocks cost something per byte too.

QuestionA team wants a model for a support chatbot that receives many typos and mixed-script messages. Based on the paper, what is the case for BLT, and what should they check before adopting it?Show answer

The paper reports more robustness to noisy inputs, about 7 points on average over the same-data token model on noised HellaSwag, and much better character-level results on CUTE. Before adopting it, the team should measure its own serving cost, because the authors say their code may not match tokenized models on wall-clock time, and they should evaluate on their own traffic, not only on the paper's benchmarks.

Sources

Read the full paper

Artidoro Pagnoni, Ram Pasunuru, Pedro Rodriguez et al., 2024. arXiv:2412.09871