Answers for LLM inference engineers

Perplexity to bits per byte: comparing models that use different tokenizers (llama.cpp, lm-eval)

Bits per byte = ln(perplexity) × tokens scored ÷ (ln 2 × UTF-8 bytes those tokens cover). Perplexity and “loss” are per token, so they change when the tokenizer changes; bits per byte does not. On the same 807 kB of Python source, three toy models scored perplexity 33.6, 108.6 and 897.4 with llama-perplexity, a 27× spread, yet their bits per byte were 2.35, 1.97 and 2.23: the model with the lowest perplexity was the worst of the three. The catch with llama.cpp is that llama-perplexity prints neither count you need. It scores only the second half of each chunk and drops the tail of the file, 49.2% to 49.9% of the text in the runs below. The calculator on this page does the arithmetic, and ppl2bpb.py works out the exact counts for a llama.cpp run. A figure such as OpenAI's “log-perplexity below 0.8” cannot be compared with yours either way: it is per token, on a private dataset, with the log base and the tokenizer not stated.

Published 2026-12-02 · llama.cpp b12925 · 10 llama-perplexity runs on CPU, each recomputed in PyTorch · toy models only, no real model was measured

Convert a perplexity or a loss to bits per byte

Enter the number you have and how much text it covers. Everything is computed in your browser.

Formulas: nats per token = ln(PPL) = bits per token × ln 2 = log10 value × ln 10. Bits per byte = nats per token × tokens ÷ (ln 2 × bytes). Byte perplexity = 2bits per byte. The llama-perplexity mode counts the scored tokens exactly (chunks = floor(tokens ÷ c), each scoring c − 1 − floor(c ÷ 2) tokens) and assumes the scored half has the same bytes per token as the whole file; that assumption was within 0.62% of the exact figure in the nine full runs below. The bytes-per-token mode depends on the text: the presets are for Python source and are wrong for prose.

How do I convert perplexity to bits per byte?

Take the natural log of the perplexity, multiply by the number of tokens that were scored, and divide by ln 2 and by the UTF-8 bytes those tokens cover. The first step undoes the exponential (perplexity is e to the average loss per token), the second gives the total information in the text, and the last expresses it per byte, a unit no tokenizer can change.

nats per token  = ln(PPL)                      # the "loss"; also called log-perplexity
bits per token  = ln(PPL) / ln 2
total bits      = bits per token * tokens scored
bits per byte   = total bits / bytes covered by the scored tokens
byte perplexity = 2 ** bits per byte           # = exp(total nats / bytes)

Worked example from the runs below (Toy B, -c 512): PPL 108.5936 is 4.68761 nats or 6.76280 bits per token. Over 116,790 scored tokens that is about 789,827 bits, and those tokens cover 401,209 bytes, so the model needs 1.9686 bits per byte. Bits per character is the same sum divided by characters; for ASCII-heavy text such as code the two are nearly equal, and for CJK text they differ by about a factor of three.

Why can't I compare perplexity between models with different tokenizers?

Because the average is taken over tokens, and each tokenizer cuts the same text into a different number of tokens. A tokenizer with short tokens gives the model many easy predictions and a low perplexity; one with long tokens gives fewer, harder predictions and a high perplexity, for the same total information.

The evaluation text here is 807,325 bytes of Python (20 files of CPython 3.14.0's Lib/). The GPT-2 vocabulary splits it into 372,143 tokens (2.17 bytes each, largely because it spends one token on every space of indentation), the Llama 3 vocabulary into 183,439 (4.40 bytes each):

TokenizerTokens for the textBytes per tokenTokens if llama-tokenize runs with its defaults (difference)
GPT-2 BPE (llama.cpp ggml-vocab-gpt-2)372,1432.169371,816 (-327)
Llama 2 SentencePiece (ggml-vocab-llama-spm)234,5513.442234,281 (-270)
Llama 3 BPE (ggml-vocab-llama-bpe)183,4394.401183,209 (-230)
OpenAI cl100k_base (tiktoken 0.14.0)183,4764.400n/a
OpenAI o200k_base (tiktoken 0.14.0)184,9374.365n/a

Three toy language models, one per llama.cpp vocabulary, were trained for about four minutes each on the other 133 files and measured with llama-perplexity at its default context of 512:

ModelBytes per scored tokenPerplexityRank by perplexityNats per tokenBits per tokenBits per byteRank by bits per byte
Toy A (GPT-2 BPE vocabulary)
gpt2, 2 layers, width 128, vocabulary 50,257
2.15633.600113.51455.07042.35183
Toy B (Llama 2 SentencePiece vocabulary)
llama, 2 layers, width 128, vocabulary 32,000
3.435108.593624.68766.76281.96861
Toy C (Llama 3 BPE vocabulary)
llama, 2 layers, width 64, vocabulary 128,256
4.404897.353736.79959.80952.22752

Ranked by perplexity, Toy A looks about three times better than Toy B and 27 times better than Toy C. Ranked by bits per byte it is the worst of the three. Nothing about the models changed between the two columns, only the unit. The toys are small on purpose (they are here to check the arithmetic, and at this context size all three compress worse than gzip), so read the table as a demonstration of the unit, not as a result about these tokenizers.

Context size moves perplexity too: Toy A scores 31.9 at -c 128, 33.6 at 512 and 35.7 at 1024 on the same file. (These toys were trained on 128-token windows, so they get worse with longer chunks; real models usually get better.) Compare runs only when the text and -c are the same.

Which tokens does llama-perplexity actually score?

Only the second half of every chunk: with the default -c 512, 255 tokens out of each 512, and nothing from the tail of the file that does not fill a chunk. So the perplexity it prints describes roughly half of your text, and the byte count to divide by is the bytes of those tokens, not the file size.

From tools/perplexity/perplexity.cpp at b12925:

To check that reading, each run was recomputed in PyTorch from the original checkpoint in float64, scoring exactly those positions. All nine perplexities agree with llama.cpp's (F32 GGUF) to within 0.0003%:

Model-cChunksTokens scoredBytes coveredShare of the textPPL, llama-perplexityPPL, PyTorchBits per byte (exact)Whole-file shortcut (error)
Toy A1282,907183,141397,19349.2%31.941931.94192.30422.3036 (-0.03%)
Toy A512726185,130399,13549.4%33.600133.60012.35182.3372 (-0.62%)
Toy A1024363185,493403,00049.9%35.719735.71962.37442.3779 (+0.15%)
Toy B1281,832115,416398,00549.3%85.535885.53561.86131.8648 (+0.19%)
Toy B512458116,790401,20949.7%108.5936108.59361.96861.9648 (-0.19%)
Toy B1024229117,019402,88749.9%138.2609138.26132.06552.0660 (+0.03%)
Toy C1281,43390,279398,42849.4%891.0020891.00122.22042.2266 (+0.28%)
Toy C51235891,290402,01749.8%897.3537897.35242.22752.2289 (+0.06%)
Toy C102417991,469402,36149.8%929.3054929.30422.24152.2404 (-0.05%)

The last column is what you get by dividing by the whole file instead: ln(PPL) × all tokens ÷ (ln 2 × file bytes). When the run covers the whole file the scored half is a fair sample and the shortcut was off by at most 0.62% here. It breaks when the run is partial: with --chunks 40 at -c 256 the scored tokens were 2.0% of the text, and the shortcut gave 2.180 against an exact 2.321 bits per byte (-6.1%).

ppl2bpb.py: the exact conversion for a llama.cpp run

ppl2bpb.py (Python 3.8+, standard library only) tokenizes the file with llama-tokenize the way llama-perplexity does, replays the chunking, adds up the bytes of the scored tokens and prints every unit.

# run llama-perplexity and convert (arguments after -- go to llama-perplexity)
python ppl2bpb.py --bin-dir llama.cpp/build/bin -m model.gguf -f text.txt -c 512 -- -ngl 99

# convert a perplexity you already measured with the same -f and -c
python ppl2bpb.py --bin-dir llama.cpp/build/bin -m model.gguf -f text.txt -c 512 --ppl 7.4213

# arithmetic only
python ppl2bpb.py --ppl 7.4213 --tokens 91290 --bytes 372100

It stops if llama-perplexity reports a different number of chunks than it expects, which is how a build with different chunking would show up. Runs with --ppl-stride use another window and are not supported.

Can I compare my model with OpenAI's log-perplexity of 0.8?

No. The numbers in OpenAI's “Perplexity and Intelligence” post (2026-11-22) are per-token losses on a dataset nobody else has, and the post does not say which log base, tokenizer or context length they use. Converting your own result to bits per byte fixes the tokenizer problem but not the other two.

What you would needWhat the post saysWhy it matters
The evaluation textHeld-out data “sourced from our internal codebase”, a fixed snapshot; not publishedLoss depends on the text more than on anything else. In the Pile paper the same GPT-3 davinci scores 0.7177 bits per byte on the whole Pile and 0.5635 on its GitHub part.
The log base“the log of perplexity, also called cross-entropy loss”; no base givenTraining code normally reports the natural log, but base 2 would make every value 31% smaller in nats and base 10 would make it 2.3 times larger.
The tokenizerNot statedA per-token value turns into bits per byte only through bytes per token. OpenAI's public tokenizers differ little on Python source (4.400 bytes per token for cl100k_base, 4.365 for o200k_base here), but the one behind the chart is unknown.
Context length and checkpointNo context length given; the post speaks of comparing “base models”Context length changes the loss (see the -c comparison above), and a chat-tuned checkpoint is not the base model.

To see what the choice of base alone does, here are the post's values turned into bits per byte under each reading, assuming o200k_base and text that tokenizes like the Python source used on this page (4.365 bytes per token). This is an illustration of the units, not an estimate of OpenAI's models:

Value in the postAs printedBits per byte if it is in natsif it is in bitsif it is base 10
GPT-3.50.990.3270.2270.753
GPT-40.910.3010.2080.692
“losses below 0.8”0.800.2640.1830.609
the model that “started producing groundbreaking results”0.760.2510.1740.578

What you can do with your own model is measure it and a reference model on the same public text and report bits per byte for both.

What is a good bits-per-byte number?

It depends on the text, so the useful anchors are other things measured on the same text. A general-purpose compressor is the cheapest one: a model that cannot beat xz or bzip2 on your text has not learned much about it.

On the 807 kB of Python source used hereBits per byteHow
gzip -9 (Python standard library)1.854measured here, whole text
bzip2 -9 (Python standard library)1.544measured here, whole text
zstd -19 (zstandard package)1.591measured here, whole text
xz -9e (Python standard library)1.563measured here, whole text
Toy B, -c 5121.969measured here, the scored half of the text
Toy C, -c 5122.228measured here, the scored half of the text
Toy A, -c 5122.352measured here, the scored half of the text

At -c 512 the toys need 1.97 to 2.35 bits per byte, more than gzip's 1.85 on the whole text; they have two layers and a few minutes of training. For real models, the Pile paper (2021) reports bits per byte for GPT-2 and GPT-3 on its test set (Table 2, one tenth of the test data):

TextGPT-2 smallGPT-2 mediumGPT-2 largeGPT-2 xlGPT-3 adaGPT-3 babbageGPT-3 curieGPT-3 davinci
The Pile (all components)1.22531.09281.08281.04680.96310.87180.79800.7177
Github1.79121.31801.79091.64860.87610.73350.64150.5635

Those rows are on the Pile's text, not on the Python files used here, so they are not comparable with the table above.

How do I get bits per byte from lm-eval or llama-server?

lm-eval already prints it for rolling-likelihood tasks, and llama-server cannot give you the per-token likelihood of a prompt through /v1/completions, so for GGUF models use llama-perplexity and convert.

An alternative that stays in token units is to rescale every model to one reference tokenizer's token count, as the “weighted perplexity benchmark” write-up does; it is the same total log-likelihood divided by a different constant.

How was this measured?

Everything ran on 2 CPU cores on 2026-12-02 with llama.cpp b12925 (commit 58bd04a05) built from source.

The scripts that produce every number, and the test that runs this page's calculator against them, are in the site repository.

Limits

FAQ

How do I convert perplexity to bits per byte?
Bits per byte = ln(perplexity) x tokens scored / (ln 2 x UTF-8 bytes those tokens cover). ln(perplexity) is the average loss in nats per token; multiplying by the token count gives the total, and dividing by ln 2 and by the bytes gives bits per byte. Example from this page: perplexity 108.5936 over 116,790 tokens covering 401,209 bytes is 1.9686 bits per byte.
Can I compare perplexity between models that use different tokenizers?
No. Perplexity is per token, and tokenizers cut the same text into different numbers of tokens. On the same Python source, three toy models here scored perplexity 33.6, 108.6 and 897.4, but 2.35, 1.97 and 2.23 bits per byte: the model with the lowest perplexity had the worst bits per byte. Compare bits per byte (or total log-likelihood) on the same text instead.
Can I compare my llama.cpp perplexity with OpenAI's log-perplexity of 0.8?
No. OpenAI's numbers are a per-token loss on held-out data from its internal codebase, which is not public, and the post states neither the log base nor the tokenizer. Even after converting your own result to bits per byte you would be measuring a different text.
Does llama-perplexity score every token in the file?
No. In llama.cpp b12925 it cuts the tokens into chunks of -c tokens (default 512), scores only the second half of each chunk (255 of 512 tokens) and drops the tail that does not fill a chunk. In the nine full runs here the scored tokens covered 49.2% to 49.9% of the bytes of the text.
Why does llama-tokenize report a different token count than llama-perplexity uses?
llama-tokenize processes escape sequences such as \n in the text and parses special tokens by default; llama-perplexity does neither, and its -f drops one trailing newline. Run llama-tokenize with --no-escape --no-parse-special to get the same tokens. On the Python source used here the default gave 230 to 327 fewer tokens.
Does lm-eval report bits per byte?
Yes, for tasks with output_type loglikelihood_rolling such as wikitext. It prints word_perplexity, byte_perplexity and bits_per_byte, where bits_per_byte is minus the summed log-likelihood divided by the summed UTF-8 bytes and by ln 2, so no conversion is needed.

Sources