Repository navigation
fix(tokenizer): implement metaspace prefix handling for issue #473 - #481
michalharakal merged 4 commits into
Conversation
michalharakal
left a comment
There was a problem hiding this comment.
Thanks @Sehul07. Two things, one about the branch and one about the fix itself.
The branch carries both lanes. This PR and #482 point at the same three commits, so the two diffs are identical right now. The last commit (af0872f7, the BPEStrategy change) belongs to #474. Could you reset this branch to 04ede43e and force-push, so that #481 only contains the #473 work and #482 only the #474 work? One PR per lane keeps each review small and lets them merge independently.
The #473 fix is not in the diff yet. After the split, what remains here is a comment change and re-indentation in detectFromVocab; addSpacePrefix is still hard-coded to false at the GGUFTokenizer(...) call at the end of fromTokenizerJson. The actual change is small and the value is already plumbed:
- In
fromTokenizerJson, locate the"pre_tokenizer"block and read"prepend_scheme"(for older files also anormalizerof typePrependwith"prepend": "▁", possibly inside aSequence). - Map it:
always→true,first→true,never→false, no block at all →false(today's behaviour). - Pass that boolean as
addSpacePrefixinstead of the constant.
The engine does the same sniffing in SentencePieceTokenizer.kt (lines 382–391 at the commit linked in the issue) — copying that shape is fine.
Tests (step 4 of #473): a synthetic ▁-vocab file with prepend_scheme: always encodes "Hi" to the ▁Hi id; the same file with never encodes to the Hi id. If you have Gemma 4 locally, Gemma4TokenizerParityTest must stay green ("Hi" → 10979); if not, just say so and I will run it.
Please also revert the indentation-only change in detectFromVocab so the diff is only the fix, add a CHANGELOG.md line and Closes #473 in the description.
CI runs are approved on your branches now, so you get compiler and test feedback on every push.
|
CI finished on this branch and fails in That line goes away entirely with the table-based |
…SKaiNET-developers#473) fromTokenizerJson no longer assumes addSpacePrefix=false for SentencePiece style vocabularies. detectPrependScheme reads pre_tokenizer.prepend_scheme (always and first -> true, never -> false) and, for older files, a Prepend normalizer with "prepend": "▁", also inside a Sequence. A file that declares neither keeps the previous behaviour, so Gemma 4 still encodes "Hi" as [Hi]. Reverts the indentation-only change in detectFromVocab, keeps the comment. GGUFTokenizerPrependSchemeTest covers always, first, never, no block and the legacy normalizer on a five-token vocabulary. CHANGELOG line under Unreleased.
af0872f to
5d90e42
Compare
|
Thanks @Sehul07. I took the branch split off your plate and finished the lane here:
With #480 merged alongside, the mmBERT file now encodes the #473 acceptance sentence exactly as the reference: Squash-merge with you as author once CI is green. Same note as on #480 about the commit email, it applies here too. |
Closes #473