Repository navigation
hftokenizer: fix ByteLevel spans & trim_offsets (#91); modeltests: teacher-forced generation checks - #93
Merged
Conversation
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.
Fixes #91
Summary
1.
tokenizers/hftokenizer: ByteLevel token spans andtrim_offsets(fixes #91)byteLevelPreTokenizeWithOffsetsandbyteLevelEncodeNoSplitto record one original byte offset per UTF-8 byte written for GPT-2 mapped characters (such as 2-byteĠ,Ċ, and multi-byte UTF-8 characters), instead of under-fillingword.offsetsand falling back to remapped byte lengths that shifted spans past the end of the input.[origStart, origLast+1)(matching HuggingFaceByteLevel::pre_tokenize, so split multi-byte runes never slice invalid UTF-8), and preservednormOffsets[0]on prepended spaces inByteLevel(add_prefix_space: true) andSequencepre-tokenizers.TrimOffsets,AddPrefixSpace,UseRegex, andProcessorsfields toPostProcessor(andTrimOffsetstoPreTokenizer), and implementedtrimByteLevelOffsetsmatching HuggingFacetokenizers'byte_level::process_offsetsforRobertaProcessing,ByteLevel, andSequencepost-processors.EncodeWithAnnotationsto run post-processor offset trimming even whenAddSpecialTokensisfalse(matching HuggingFacetokenizers), while still only inserting special tokens whenAddSpecialTokensistrue.TestByteLevelPreTokenizeSpans,TestPostProcessor_RobertaAndByteLevelSpans, plus span assertions inTestSplitPreTokenizer_WhitespaceLookaheadAndByteLevelNoRegex).2.
modeltests: Teacher-forcedkvcache_parityandteacher_forced_generatekvcache_parityto teacher-forced multi-step logit parity (single-pass causal naive forward vs. KV-cache prefill + forced single-token decode steps), asserting full-vocabulary cosine similarity, full-vocabulary max abs diff, and top-1 agreement whenever logit margin exceedstop1_margin_tolerance.greedy_generatewithteacher_forced_generate, feeding each goldengreedy_token_ids[k-1]into stepkand asserting both per-step logit gap (max(logits) - logits[wantID] <= 2 * logit_max_abs_diff) and minimum exact top-1 match count—preventing 1-ULP BFloat16 near-ties from cascading across subsequent tokens.docs/ModelTests.md,docs/CHANGELOG.md,.agents/AGENTS.md, and bumpedgithub.com/gomlx/gomlxingo.mod/go.sumto include ml/zoo/transformer/generate: normalize integer prompt tensors to Int32 gomlx#505.Testing
GOWORK=off go test -short ./...passes across all packages.Meyssa/gector-large-2024(tokenizer.jsonat commit93faea4b7a13a0384a37b10779a567dacea5ba41) vs HuggingFacetokenizers0.22.2: exact byte-offset parity on"I has three cats"([0,1), [2,5), [6,11), [12,16)), leading/multiple spaces, multi-byte UTF-8/CJK, added tokens, andAddSpecialTokens: false.go test ./modeltests/ -modeltests -backends="go;xla:cuda"ongemma4-e4bandqwen3.5-4b: allprefill_logits,variables,kvcache_parity, andteacher_forced_generatesubtests pass on both backends.