mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1582] [CLOSED] tokenizer: initialize caches once per instance #3544
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3544
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1582
Author: @InB4DevOps
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:perf/tokenizer-cache-init📝 Commits (1)
4a51022tokenizer: initialize caches once per instance📊 Changes
2 files changed (+53 additions, -2 deletions)
View changed files
📝
tools/strata_tokenizer.py(+6 -2)📝
tools/test_strata_tokenizer.py(+47 -0)📄 Description
Summary
Initialize
_piece_idsand_bytes_cacheonce inTokenizer.__init__, then access those attributes directly.The previous
self.__dict__.setdefault("_bytes_cache", {})constructed an empty default dictionary and looked up the cache through__dict__for every decoded token, even on hits._encode_plain()used the same pattern per segment.Cache contents and limits, BPE merge order, special-token handling and byte decoding are unchanged. The two empty dictionaries are allocated at construction rather than first use.
This PR contains only:
tools/strata_tokenizer.pytools/test_strata_tokenizer.pyNo parser optimizations, profiling infrastructure, benchmark files, or native/GPU changes are included.
Isolated validation
Candidate and untouched baseline both started at upstream
fb58e0dbc8399662c0e47c76578c6e878b14f6cf. Server, frontend and benchmark-fixture source hashes were identical between checkouts; only the tokenizer and its test file differed.10 tests passed; five tests requiring unavailable tokenizer assets were skipped. Added checks cover:
Existing tests cover cold/warm/disabled piece caching, cache bounds, synthetic BPE parity and concurrent encoding.
git diff --checkpassed.Windows correctness and performance validation: pending.
Same-day CPU measurements
Intel Core i7-12700KF, Linux 7.0.0-38-generic, glibc 2.39, CPython 3.12.3, regex 2026.9.29, Jinja2 3.1.6. Default scheduling/power policy, no affinity pinning. Seven fresh-process samples per checkout, alternating baseline/candidate order, two warmups per case, profiling disabled.
Deterministic synthetic vocabulary (seed 268, 1,500 merges), 49,664 tokens / 66,048 UTF-8 bytes. Caches are warm; fixture construction, validation and hashing are outside timing. No model or GPU required.
Detokenization ranges: 12.68–13.13 ms upstream, 9.77–10.16 ms candidate. All 42 measured outputs matched fixtures and had matching hashes across checkouts and samples. These are synthetic Python CPU measurements, not inference-throughput claims; constructor/startup performance was not benchmarked.
Reproduction
With
regexandjinja2installed, run this from the root of the baseline and PR checkouts. It uses the repository's existing GPU-free tokenizer fixture and prints one warmed sample of each workload. Repeat in fresh processes and alternate checkouts for comparisons.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.