feat: make transformers optional (#31) - #70
Conversation
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — The PR moves Transformers and multimodal dependencies into extras and adds BYO-tokenizer support, but it also removes the public RendererPool/create_renderer_pool API and its concurrent execution path while changing dependency-sensitive auto-resolution. These production contract changes exceed a self-contained dependency tweak and merit human review. Notes:
You can add or adjust custom eligibility rules. Learn more. |
|
not really satisfied with the way |
|
hey @hallerite , thanks for writing this PR! I see that its "approved" (by a bot, so idk if that counts). I am just wondering if you think it will still get merged. Thank you! |
|
@felipemello1 I will try to get this in asap, probably tomorrow or the day after! |
|
awesome, thanks @hallerite . Just to be clear: its not blocking us in TorchTitan. It is just a great feature. It is fine if you want to take your time to get it merged later. Ty! |
|
hey @hallerite , just checking if you still plan on merging it. We wanted to use it in SFT and not have to require transformers as a dependency. Is merging this PR still in your roadmap? |
f19becd to
e732606
Compare
|
@felipemello1 we are about to merge this PR. will be in the next renderers release after we test it for a bit! |
Closes #31.
Why
transformersis a heavy dependency, and text-only consumers that already owna tokenizer should not have to install it just to render and parse token IDs.
This branch has been rebuilt on current
main. It keeps the currentoffset-capable tokenizer policy and does not restore the removed
fastokensintegration.
What changed
TokenizerandChatTemplateTokenizerprotocols and movedall 19 concrete renderer modules off type-only Transformers imports.
transformersfrom the base install to therenderers[transformers]extra.renderers[multimodal]for Transformers plus Pillow.load_tokenizer, processor auto-loading, unknown-modelAutoConfigprobing, and vLLM multimodal feature encoding behind lazy, actionable
dependency checks.
their own processor remain lightweight.
uv.lockand documented the installation/BYO contracts.The vLLM/OpenAI client remains part of the base package in this revision. That
split is separate from making Transformers optional and avoids breaking the
existing root exports for client exceptions.
Behavior without Transformers
create_renderer()with anoffset-capable BYO tokenizer.
image/audio processor.
DefaultRendererworks when selected explicitly with a tokenizer thatprovides
apply_chat_template.renderers[transformers]or anexplicit renderer config, rather than silently treating a possible VLM as a
text model.
report the appropriate optional-extra hint.
Verification
3660 passed, 179 skipped, 1 xfailed174 passed, 24 skippedmain).transformersandmultimodalextras.Note
Make
transformersan optional dependency and removeRendererPooltransformersout of core dependencies into optional extras (transformersandmultimodal) in pyproject.toml, allowing the library to be installed withouttransformers.TokenizerandChatTemplateTokenizerProtocols in renderers/base.py so callers can pass any compatible tokenizer object instead of requiringPreTrainedTokenizer.RendererPoolclass,create_renderer_poolfactory, and pool-based offloading in renderers/client.py.generatenow accepts onlyRenderer, notRendererPool._require_transformershelper that raises an actionableImportErrorwhentransformersis missing, used byload_tokenizer,_model_has_vision_config, and multimodal feature builders in each renderer.RendererPoolandcreate_renderer_poolare removed fromrenderers/__init__.pyexports;generateinrenderers/client.pyno longer acceptsRendererPool;DefaultRenderer.__init__now requires a tokenizer withapply_chat_template.Macroscope summarized de6b9d2.
Note
High Risk
Removes
RendererPool/create_renderer_pooland changes default dependencies, which can break integrators; auto-resolution behavior for unknown models without Transformers is stricter and may require explicit configs.Overview
Makes Hugging Face Transformers optional so text-only users can install the base package and supply an offset-capable BYO tokenizer.
transformersmoves torenderers[transformers];renderers[multimodal]adds Pillow plus Transformers for image/audio paths. Docs and examples now describe BYO tokenizer requirements and the new extras.Introduces
TokenizerandChatTemplateTokenizerprotocols and retargets all concrete renderers fromPreTrainedTokenizerto those structural types.load_tokenizer, processor auto-load, unknown-modelAutoConfigprobing, and vLLM multimodal encoding call_require_transformerslazily with install hints. Without Transformers, registered text models still auto-resolve; unregistered names must use an explicit config (e.g.DefaultRendererConfig()) instead of silently falling back.Removes
RendererPoolandcreate_renderer_poolfrom the public API,base, docs, and tests.client.generateonly accepts a singleRendererand runs render/parse synchronously on the event loop (no pool thread offload).Breaking for downstream: default
pip install renderersno longer pulls Transformers; pool-based concurrency must be reimplemented outside the library.Reviewed by Cursor Bugbot for commit de6b9d2. Bugbot is set up for automated code reviews on this repo. Configure here.