Token-Free and Byte-Level Language Models › Where the Compute Goes

Michael BrenndoerferNovember 17, 20266 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 135Token-Free and Byte-Level Language Models › Where the Compute Goes
Reading section 5 of 13 · Where the Compute Goes · 6 minSection 5 of 13 · 6 min

Section 5 of 13 · 6 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Suppose a particular subword tokenizer represents a passage using one position for every four bytes on average. A direct byte model uses about four times as many content positions on that passage.

In a dense causal mask, the number of allowed attention pairs grows roughly with the square of the position count. Four times the positions give about sixteen times as many pairs for long sequences.

Measure the byte-to-token ratio on the actual corpus. Its value can vary with the tokenizer, domain, language and normalization.

Exact Position-Pair Counts

For a causal transformer with LL positions, the number of ordered query-key pairs that participate in attention, counting the diagonal, is

Ncausal(L)=∑i=1Li=L(L+1)2.N_{\text{causal}}(L) = \sum_{i=1}^{L} i = \frac{L(L+1)}{2}.

This is exact for dense causal attention with no sliding window and no sparse pattern. It is the quantity that scales quadratically.

Now consider a patched model. The byte sequence of length TT is partitioned into PP patches of sizes s1,…,sPs_1, \dots, s_P with ∑ksk=T\sum_k s_k = T. A global model attends over the PP patch representations. A local model attends over the bytes within each patch. The pair counts are

Nglobal=P(P+1)2,Nlocal=∑k=1Psk(sk+1)2.N_{\text{global}} = \frac{P(P+1)}{2}, \qquad N_{\text{local}} = \sum_{k=1}^{P} \frac{s_k(s_k+1)}{2}.

For equal patches of width ww with T=PwT = Pw, the local count becomes Pw(w+1)/2=T(w+1)/2P w(w+1)/2 = T(w+1)/2. Substituting P=T/wP = T/w into the global count and adding the local count gives the two terms below plus T/(2w)+T/2T/(2w) + T/2. Dropping those added terms gives the continuous width approximation.

Ntotal≈T22w2+Tw2.N_{\text{total}} \approx \frac{T^2}{2w^2} + \frac{Tw}{2}.

Treating the approximate pair count as a function of continuous width ww, differentiate it and set the result to zero to get the width that minimizes this proxy.

w⋆=(2T)1/3.w^\star = (2T)^{1/3}.

For T=106T = 10^6 bytes, this approximation gives w⋆≈126w^\star \approx 126 bytes. Integer widths and partially filled final patches change the exact counts.

This derivation is a useful sanity check on architecture design. It is not a performance model.

PythonIn [24]
CollapseExpand
import numpy as np

LENGTHS = np.unique(np.round(np.logspace(2, 6, 60)).astype(int)).astype(
    np.int64
)
WIDTHS = [64, 256, 1024]


def causal_pairs(n):
    return n * (n + 1) / 2.0


def patched_pairs(n, w):
    p = int(np.ceil(n / w))
    global_pairs = p * (p + 1) / 2.0
    local_pairs = 0.0
    remaining = n
    for _ in range(p):
        s = min(w, remaining)
        local_pairs += s * (s + 1) / 2.0
        remaining -= s
    return global_pairs + local_pairs


full_curve = np.array([causal_pairs(n) for n in LENGTHS])
patched_curves = {
    w: np.array([patched_pairs(n, w) for n in LENGTHS]) for w in WIDTHS
}
optimal_widths = np.array([(2.0 * n) ** (1.0 / 3.0) for n in LENGTHS])
optimal_curve = np.array(
    [
        patched_pairs(n, max(1, int(round(w))))
        for n, w in zip(LENGTHS, optimal_widths)
    ]
)
VisualizationOut [25]
CollapseExpand
Log-log line chart comparing quadratic attention pair counts against patched counts at three fixed widths, with a curve using the approximate minimizing width.
Exact causal attention position-pair counts for full attention and for patched attention at three fixed patch widths, on log-log axes. The dashed line uses the rounded width suggested by the leading-term approximation. Pair counts are an attention-only proxy and not a FLOP or latency measurement.

At one million bytes, full causal attention includes about 5.00×10115.00 \times 10^{11} pairs. Width 256 gives 3,907 patches including a final 64-byte patch. The global and local terms together give about 1.36×1081.36 \times 10^8 pairs, roughly 3,673 times fewer. The dashed curve chooses widths using the leading-term approximation and computes exact counts at those widths.

What Pair Counts Do Not Measure

Position-pair counts are exact for what they count and misleading for everything else. A production comparison needs four separate quantities, and conflating them is how architecture claims get overstated.

  • Pair-dependent work. Attention score and value operations scale with pair count, head width and head count. The attention softmax also runs over the allowed pairs. Include cross-attention pairs where the architecture uses them.
  • Per-position work. Count attention projections, feed-forward layers, normalization and any vocabulary projection at the positions and widths where they run. MEGABYTE emits byte-vocabulary logits in its local decoder. BLT also uses a local encoder. Global patch processing and local byte work may have different widths and layer counts.
  • Memory. Count cached positions, cache-bearing layers, KV heads, dimensions, and element sizes. Four times as many cached positions needs four times the KV payload only when the remaining layout and retention policy are the same. Training activation memory uses different accounting.
  • Runtime. Wall-clock time depends on kernel efficiency, occupancy, batch size, sequence length relative to the hardware's preferred tile size, and whether the implementation can keep the accelerator busy. A model with fewer FLOPs can be slower if its shapes are awkward.

In MEGABYTE and BLT, the global model works over patch positions while a local decoder generates at byte resolution. Fewer patches mean fewer global position updates for the same byte string. The number of sequential byte predictions remains fixed in the autoregressive decoding discussed here.

The four quantities can point in different directions, and that is the source of most of the confusion in the literature. For example:

  • A model can have fewer attention FLOPs and more total FLOPs, because the linear terms grew.
  • It can have fewer FLOPs and higher latency, because the kernels are less efficient.
  • It can have a smaller KV cache and a larger activation footprint, because the global and local models have different shapes.

A claim that a patched model is "more efficient" is incomplete until you say which quantity you mean and under what conditions you measured it.

We take up parallel and semi-autoregressive generation in Part XIX, Chapter 5, where the serial constraint is relaxed.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy