Skip to content

Bundle tokeniser, fix Claude 5 token counts, drop Ollama - #65

Merged
sammcj merged 1 commit into
mainfrom
modernise-tokeniser
Aug 11, 2026
Merged

sammcj merged 1 commit into
mainfrom
modernise-tokeniser

Conversation

@sammcj

@sammcj sammcj commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Token counts were roughly 30% low for Claude Opus 5, Sonnet 5 and Fable 5. Those models use the tokeniser introduced with Opus 4.7, which produces about 30% more tokens than earlier Claude models for the same text. The offline correction factor was calibrated against the old tokeniser, and count_tokens API calls were pinned to claude-sonnet-4-5.

Same input, three ways:

429 tokens  --no-correction (raw o200k)
506 tokens  --model claude-sonnet-4-5   (x1.18, old tokeniser)
656 tokens  default: claude-opus-5      (x1.53, 4.7+ tokeniser)

Changes

  • New -m/--model (default claude-opus-5) drives both the offline correction factor and the model sent to count_tokens
  • Offline counts scale by 1.53 for Opus 4.7 and later, 1.18 for earlier Claude models, and are left alone for non-Claude models
  • o200k_base and cl100k_base are embedded gzipped with a custom BpeLoader: no first-run download, no cache directory, works offline. Binary 19 MB to 22 MB
  • Ollama config and quantest VRAM estimation removed, dropping ollama, gollama, gopsutil and wmi from the module graph
  • llm_prompt_prefix and llm_prompt_suffix now work, they were documented but orphaned in the removed Ollama struct
  • 12 token package tests added, covering the embedded vocabularies against tiktoken reference vectors, UTF-8 round-tripping and the correction table
  • Dependencies bumped, including glamour v1.0.0

Breaking

  • -m/--model now means the token counting model, not the VRAM estimation model
  • --vram, --quant, --quanttype, --context, --kvcache, --memory and --fits are gone
  • --encoding accepts o200k and cl100k only, p50k/r50k removed
  • llm_model has no default, --llm now errors if it is unset in the config

Note

The 1.53 factor is derived rather than measured: the existing 1.18 calibration times Anthropic's documented ~30% increase. Actual error varies with content. --anthropic still gives exact counts.

Token counts were roughly 30% low for Claude Opus 5, Sonnet 5 and Fable 5.
Those models use the tokeniser introduced with Opus 4.7, which produces about
30% more tokens than earlier Claude models for the same text. The offline
correction factor was calibrated against the old tokeniser, and the
count_tokens API calls were pinned to claude-sonnet-4-5.

- Add -m/--model (default claude-opus-5), driving both the offline correction
  factor and the model sent to count_tokens
- Scale offline counts by 1.53 for Opus 4.7 and later, 1.18 for earlier Claude
  models, and leave non-Claude models uncorrected
- Embed gzipped o200k_base and cl100k_base vocabularies with a custom
  BpeLoader, so there is no first-run download and no cache directory
- Drop p50k/r50k, which have no use for a Claude focused tool
- Remove Ollama config and quantest VRAM estimation, dropping ollama, gollama,
  gopsutil and wmi from the module graph
- Wire llm_prompt_prefix and llm_prompt_suffix into LLMConfig, they were
  documented but orphaned in the removed Ollama struct
- Add token package tests and bump dependencies, including glamour v1.0.0
@sammcj sammcj self-assigned this Aug 11, 2026
@sammcj
sammcj merged commit 9a8ca07 into main Aug 11, 2026
5 checks passed
@sammcj
sammcj deleted the modernise-tokeniser branch August 11, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant