Skip to content

fix(inference): TemplateProcessing IDs are authoritative for SP BOS/EOS (codex follow-up)#117

Merged
ohdearquant merged 1 commit into
mainfrom
fix-sp-template-id-precedence
May 25, 2026
Merged

fix(inference): TemplateProcessing IDs are authoritative for SP BOS/EOS (codex follow-up)#117
ohdearquant merged 1 commit into
mainfrom
fix-sp-template-id-precedence

Conversation

@ohdearquant
Copy link
Copy Markdown
Owner

Context

Closes the codex round-1 Major finding on PR #106. The original fix preferred hard-coded ``/`` vocab guesses over the template-supplied IDs. This change inverts the precedence so the TemplateProcessing IDs are authoritative when present.

Why this is a separate PR

PR #106 merged into PR #105's (now-orphaned) base branch instead of main during the show stack collapse. The umbrella PR #104 brought the original PR #106 content to main but not this round-1 fix. This small PR closes the gap.

Diff

1 file (sentencepiece.rs) + 1 test file (common.rs):

  • Invert: `pp.bos_id.or(bos_id)` instead of `bos_id.or(pp.bos_id)`
  • 2 unit tests: BERT-style template ([CLS]/[SEP]) verifies template IDs win; XLM-RoBERTa-style template confirms E5 path still resolves

Verification

  • `cargo test -p lattice-inference --lib tokenizer::common test_parse_post_processor`: PASS (both new tests)
  • `cargo clippy --workspace -- -D warnings`: clean
  • E5 audit case (`multilingual_e5_small_sentencepiece_parity`) still passes

🤖 Generated with Claude Code

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>
@ohdearquant ohdearquant merged commit a0fac91 into main May 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant