Make Transformers optional - #121
Draft
hallerite wants to merge 2 commits into
Draft
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.
Summary
transformersdependency with a small structural tokenizer contract and a Rusttokenizersadapterrenderers[hf]extraWhy
Concrete renderers only need token IDs, decoding, special-token lookup, and character offsets. Importing and installing all of Transformers for that surface made the core package larger, created downstream version conflicts, and coupled every renderer annotation to an implementation detail.
The standalone backend cannot replace three HF-only capabilities:
apply_chat_templatefor unknown models, custom tokenizers that do not publishtokenizer.json(notably Kimi), and multimodal AutoProcessor loading. Those remain supported throughrenderers[hf]or caller-supplied compatible objects.Transformers 5.14.1 constrains Tokenizers to
<=0.23.0; because 0.23.1 is above that cap, the core uses the newest published compatible Tokenizers release, 0.22.2.Validation
ruff check .tokenizersin core andtransformersonly under thehfextraTokenizersTokenizer, and rendered a Unicode promptNote
Make
transformersan optional dependency, adding a standalonetokenizersbackendtransformersfrom a core dependency to an optionalrenderers[hf]extra in pyproject.toml, withtokenizers(Rust) as the new core dependency.TokenizerLike,ChatTemplateTokenizerLikeprotocols and aTokenizersTokenizeradapter for the Rust tokenizers library.load_tokenizerin renderers/base.py withbackend('auto','tokenizers','transformers') andrevisionparameters;'auto'uses the Rust backend whentransformersis absent.Qwen3VL,Qwen35,KimiK25) guardAutoProcessorimports and raiseImportErrorwith instructions to installrenderers[hf]whentransformersis missing.DefaultRenderernow raisesTypeErrorat construction time if the tokenizer lacksapply_chat_template, pointing users torenderers[hf]or a model-specific renderer.rendererswithouttransformerswould fail at import; it now succeeds but raises at runtime when HF-specific features are used.Macroscope summarized 3bd9f6e. (Automatic summaries will resume when PR exits draft mode or review begins).