Repository navigation
Support CLIP tokenizers in HFTokenizer (Lowercase, end_of_word_suffix, RobertaProcessing) - #233
Open
kiymetakdemir wants to merge 1 commit into
Open
kiymetakdemir wants to merge 1 commit into
kiymetakdemir wants to merge 1 commit into
Conversation
Add the Lowercase normalizer, BPE end_of_word_suffix, and the RobertaProcessing post-processor, which CLIP's tokenizer.json uses.
Contributor
|
@claude review effort=max |
This branch has not been deployed
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.
Problem
HFTokenizercannot load the CLIP tokenizer used by Stable Diffusion, SDXL andFLUX.1 (
openai/clip-vit-large-patch14). CLIP'stokenizer.jsonuses threefeatures that were missing:
Lowercasenormalizer: loading failed withUnsupported Normalizer type: Lowercase.RobertaProcessingpost-processor: loading failed withUnsupported PostProcessor type: RobertaProcessing(a TODO inpost_processor.h).end_of_word_suffix("</w>"): silently ignored, so every word-final tokengot the wrong id (
a=64 instead ofa</w>=320,cat=1481 instead ofcat</w>=2368).Changes
LowercaseNormalizer: Unicode lowercasing per codepoint viaunicode_tolower.U+0130 maps to
i+ U+0307 to match Rust'schar::to_lowercase.RobertaProcessing:cls A sepfor a single sequence,cls A sep sep B sepfora pair, ids passed through unchanged when special tokens are off.
trim_offsetsandadd_prefix_spaceonly affect offsets, which are not tracked.end_of_word_suffix: parsed from the BPE model and appended to the last symbolof each pre-tokenized word. With no suffix configured, encoding takes the
existing code paths.
Testing
test_hf_tokenizer.py::test_clip: token ids matchtransformersexactly foropenai/clip-vit-large-patch14on mixed case, non-ASCII case (İ, Greek),contractions, digits, whitespace runs, an inline
<|endoftext|>, and a promptlonger than 77 tokens.
test_normalizer.cpp,test_post_processor.cppand
test_hf_tokenizer.cpp; theend_of_word_suffixcase was cross-checkedagainst the HuggingFace
tokenizerslibrary.This PR was authored with the help of Claude Code.