fix: Single tokenizer initialization at startup#192
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the tokenization system to use single tokenizer instances initialized at startup per base model, replacing the previous LRU caching mechanism. This change simplifies the architecture by binding each tokenization pool to a specific base model, improving startup predictability and removing the complexity of dynamic tokenizer loading.
Key Changes
- Refactored
CachedTokenizerto hold a single pre-initialized tokenizer instead of an LRU cache with dynamic loading - Added
BaseModelNamefield tokvcache.Configfor binding pools to specific models - Updated
NewCachedHFTokenizerandNewCachedLocalTokenizerto take amodelNameparameter and initialize tokenizers at creation time - Removed
singleflightand LRU cache dependencies from tokenizer implementation - Removed deprecated Redis mock e2e tests and corresponding Makefile targets
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/tokenization/tokenizer.go |
Removed LRU cache and singleflight, refactored CachedTokenizer to hold single tokenizer instance, updated constructor signatures |
pkg/tokenization/tokenizer_test.go |
Updated test signatures to pass modelName to constructors, simplified test scenarios |
pkg/tokenization/pool.go |
Added modelName field to Pool struct, removed ModelName from Task struct, updated API signatures |
pkg/tokenization/pool_test.go |
Updated tests to use new API signatures, refactored benchmarks to run per-model |
pkg/kvcache/indexer.go |
Added BaseModelName field to Config struct with proper documentation |
tests/e2e/redis_mock/e2e_test.go |
Removed deprecated e2e tests |
tests/e2e/redis_mock/e2e_suite_test.go |
Removed deprecated e2e test suite |
Makefile |
Removed e2e-test target, simplified test target |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
deab7a0 to
dab9fed
Compare
vMaroon
reviewed
Dec 10, 2025
vMaroon
reviewed
Dec 10, 2025
a95f57a to
51b6c98
Compare
Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
…startup Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
052f04a to
7769f09
Compare
Signed-off-by: Sage Ahrac <sagiahrak@gmail.com>
7769f09 to
8d0936e
Compare
vMaroon
approved these changes
Dec 17, 2025
This was referenced Dec 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#187
This PR loads local and HF tokenizers at the pool initialization.
CachedTokenizer instances now carry a single tokenizer with respect to the base model name provided at startup.
Fixed tests