[PR #1823] [CLOSED] tokenizer: a long message's ids remembered whole, on top of the piece cache #3700

Closed
opened 2026-11-07 15:30:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1823
Author: @xrip
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: pr/tokenizer-text-cache


📝 Commits (1)

  • a61d351 tokenizer: a long message's ids remembered whole, on top of the piece cache

📊 Changes

1 file changed (+13 additions, -0 deletions)

View changed files

📝 tools/strata_tokenizer.py (+13 -0)

📄 Description

What

tools/strata_tokenizer.py: on top of 0.1.41's piece cache, a long piece of text between special tokens (one chat
message, 1,024+ characters) keeps its ids too. The ids are the same; only the work is skipped. At most 256 texts are
kept, and the cache is cleared when full.

Why

An agent sends its whole conversation again every turn. The piece cache skips the BPE merges of repeated pieces, but
the pre-tokenizer regex still runs over the whole conversation each turn. Text between special tokens is already
encoded on its own, so a message seen before can return its ids directly.

Measured

2.5 GHz Xeon E5-2670 v2, before the piece cache existed (fork based on 0.1.38): at a 190K-token conversation,
encoding took 1.06 s per turn before and 0.042 s with this cache. The ids were identical on all 36 turns of a
coding-agent session (34K -> 190K tokens).

How much this adds on top of the piece cache alone was not measured yet: the piece cache already removes the
merges, so the gain is the regex pass over the old messages.

tools.test_strata_tokenizer and serve.test_detok pass.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1823 **Author:** [@xrip](https://github.com/xrip) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/tokenizer-text-cache` --- ### 📝 Commits (1) - [`a61d351`](https://github.com/Niko1221/Strata/commit/a61d3511b12073b36c7212a427f5982f1d4bd962) tokenizer: a long message's ids remembered whole, on top of the piece cache ### 📊 Changes **1 file changed** (+13 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tools/strata_tokenizer.py` (+13 -0) </details> ### 📄 Description ## What `tools/strata_tokenizer.py`: on top of 0.1.41's piece cache, a long piece of text between special tokens (one chat message, 1,024+ characters) keeps its ids too. The ids are the same; only the work is skipped. At most 256 texts are kept, and the cache is cleared when full. ## Why An agent sends its whole conversation again every turn. The piece cache skips the BPE merges of repeated pieces, but the pre-tokenizer regex still runs over the whole conversation each turn. Text between special tokens is already encoded on its own, so a message seen before can return its ids directly. ## Measured 2.5 GHz Xeon E5-2670 v2, before the piece cache existed (fork based on 0.1.38): at a 190K-token conversation, encoding took 1.06 s per turn before and 0.042 s with this cache. The ids were identical on all 36 turns of a coding-agent session (34K -> 190K tokens). How much this adds on top of the piece cache alone was **not measured yet**: the piece cache already removes the merges, so the gain is the regex pass over the old messages. `tools.test_strata_tokenizer` and `serve.test_detok` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:09 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3700
No description provided.