fix(inference): inject SentencePiece BOS/EOS from tokenizer.json post_processor#106
Merged
ohdearquant merged 2 commits intoMay 25, 2026
Merged
Conversation
…_processor Parse TemplateProcessing post_processor to detect BOS/EOS framing. E5 (multilingual-e5-small) parity moves from 0/9 to 9/9 — payload tokens were already correct, only <s>/<\/s> injection was missing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced May 25, 2026
Addresses codex round-1 finding: when a SentencePiece tokenizer has both `<s>`/`</s>` in vocab AND a TemplateProcessing post_processor that uses different special tokens (e.g. `[CLS]`/`[SEP]`), the prior fallback order (`bos_id.or(pp.bos_id)`) silently injected the vocab guesses instead of the template-supplied IDs. Inverts to `pp.bos_id.or(bos_id)` so the template IDs win when present, with vocab-name fallback only when the template omits explicit IDs. Adds two focused unit tests in `common.rs`: - BERT-style template ([CLS]/[SEP], IDs 101/102) → verifies template IDs win - XLM-RoBERTa-style template (<s>/</s>, IDs 0/2) → verifies the E5 path still resolves correctly E5 audit case still passes (9/9 multilingual_e5_small). Workspace clippy clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Layer
L1 — tokenizer fix (PR2 of 11 in
embed-perf-qualityshow)What
Parses
tokenizer.jsonpost_processorfield of typeTemplateProcessingfor SentencePiece tokenizers (E5 family). Extractssingletemplate, detects<s>/</s>IDs, injects them at the SP encode boundary AFTER subword tokenization and BEFORE returningTokenizedInput.Why
Audit gap: pre-fix lattice produced 0/9 PASS on E5 SentencePiece cases. HF reference always wraps SP outputs in BOS/EOS via the template processor.
Result
Stack
Base: #105 (PR1 audit baseline)
Umbrella: #104
🤖 Generated with Claude Code