Repository navigation
fix: preserve serialized tokenizer truncation direction - #775
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughload_tokenizer now resolves the truncation direction from tokenizer_config.json’s truncation_side, then tokenizer.json’s serialized direction, and defaults to right. It passes the resolved direction when enabling truncation. Parameterized tests cover the default, each source set alone, and conflicting settings. Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The tokenizer direction change appears ready to merge after normal checks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation Issue
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #774.
Loading a tokenizer saved with left truncation currently switches it to right truncation when
load_tokenizerreapplies the context limit. Forone two three four fiveand a three-token limit, the loaded tokenizer keepsone two threeinstead of the saved tokenizer'sthree four five.Preserve the serialized truncation direction, defaulting to right when no truncation settings were saved. Existing context-limit resolution, stride reset, and padding behavior remain unchanged; no new public argument is added.
The 15 offline regression cases use real, tiny WordLevel tokenizers and cover left/right/unset direction, smaller/equal/larger context limits, the stricter config limit, mixed-length batches through
OnnxTextModel, stride reset, and independent left padding.Validation on Python 3.13.3 / macOS arm64, tokenizers 0.23.2:
tests/test_tokenizer_truncation.pyandtests/test_common.py), with outbound socket connections forbidden and Hugging Face offline mode enabled. The standalone example retains the expected tokens.pyright tests/type_stub.py: no errors.git diff --check: passed.The pretrained-model suite, including
test_preprocessor_utils.pywhose fixture constructs/downloads a model, was not run. No model weights, ONNX session, inference, or embedding-quality evaluation was used. The OS/Python CI matrix and upstream's newer lockfile environment remain unverified locally. An initial collection attempt failed because the interrupted dependency installation had not installed FastEmbed's package metadata; installing the locally built wheel without dependencies resolved that setup problem before the red/green runs above.All Submissions
Pre-commit hooks were not installed; their pinned Ruff checks were run directly. AI assistance (OpenAI Codex) was used for implementation review, regression validation, and preparing this submission.