Make transformers an opt-in dependency (conserver-local group)#188
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes the transformers dependency opt-in for the conserver service by moving it into a new optional dependency group (conserver-local) and deferring transformers imports until the local-model paths are actually used. This reduces the default conserver install/image size while keeping the default HuggingFace HTTP API path unchanged.
Changes:
- Move
transformers>=4.48.0from the baseconserverdependency group to a new optionalconserver-localgroup (and regroup inuv.lock). - Lazy-import
transformers/pipelinewithinhugging_llm_linkcode paths so importing the link no longer pulls ML dependencies. - Document that local inference is opt-in and requires installing
conserver-localplus a backend (e.g.torch).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Regroups transformers under a new conserver-local dependency group. |
pyproject.toml |
Adds conserver-local optional group and removes transformers from base conserver. |
conserver/links/hugging_llm_link/README.md |
Documents opt-in local inference and required install command/backend. |
conserver/links/hugging_llm_link/main.py |
Defers pipeline import to initialization time. |
conserver/links/hugging_llm_link/__init__.py |
Defers transformers import to LocalHuggingFaceLLM.__init__ with a custom ImportError. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
transformers is the single largest installed package (~48MB, ~67MB with tokenizers/huggingface_hub/hf_xet) but its only consumer is hugging_llm_link, and only the off-by-default LocalHuggingFaceLLM path (use_local_model=true) actually uses it. That path needs a model backend (torch) which is not a project dependency, so it cannot run today regardless. The default path calls the HuggingFace HTTP API and needs none of transformers. - Move transformers>=4.48.0 out of the base `conserver` group into a new opt-in `conserver-local` group. - Defer `import transformers` into LocalHuggingFaceLLM.__init__ (and HuggingLLMLink.__init__ in main.py) with a clear ImportError pointing at the install command, so importing the link no longer drags in transformers. - Document the opt-in in the link README. - Regenerate uv.lock (transformers node unchanged, just regrouped). Removes ~67MB from the base conserver install with no functional change to the default API-based path. test_link_metrics.py: 25/25 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
cda68a5 to
49e8a1b
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
pavanputhra
approved these changes
Jun 7, 2026
The lazy `import transformers` in LocalHuggingFaceLLM caught any ImportError and re-raised generic "install conserver-local" guidance. That masks failures where transformers is installed but raises while importing a transitive dependency/backend. Catch ModuleNotFoundError and re-raise unless the missing module is transformers itself, matching the pattern already used in main.py. Addresses Copilot review comment on the broad except ImportError. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pavanputhra
approved these changes
Jun 7, 2026
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
transformersis the single largest installed package in the project (~48MB on its own; ~67MB once you counttokenizers,huggingface_hub, andhf_xet, plus sharednumpy). Despite that weight, its only consumer isconserver/links/hugging_llm_link, and only theLocalHuggingFaceLLMpath uses it:use_local_model: false).transformers.pipeline("text-generation", ...), which needs a model backend (torch).torchis not a project dependency, so the local path cannot run today regardless.requests.post()to the HuggingFace inference API and needs none oftransformers.analyze/analyze_and_label/analyze_vconlinks (OpenAI/Groq).This makes
transformersa large dependency carried by every conserver image for an off-by-default, non-functional path. This PR makes it opt-in.Changes
transformers>=4.48.0out of the baseconservergroup into a new opt-inconserver-localgroup.hugging_llm_link/__init__.py: deferimport transformersintoLocalHuggingFaceLLM.__init__, raising a clearImportError(with the install command) if the optional group isn't present. Importing the link no longer loadstransformers.hugging_llm_link/main.py: lazy-importpipelineinsideHuggingLLMLink.__init__.torch).transformersnode is unchanged, just regrouped.Impact
Removes ~67MB from the base
conserverinstall with no functional change to the default API-based path. Users who want on-device inference install it explicitly:Testing
conserver/tests/test_link_metrics.py: 25/25 pass (incl. bothTestHuggingLLMMetricscases). Verified that importinglinks.hugging_llm_link(and itsmain) no longer pullstransformersintosys.modules.Related
Same theme as #160 (Redis Stack): heavy/specialized dependency with shallow or absent usage. A follow-up lever:
pandas(48MB) +grpcio(37MB) ride in transitively viapymilvuswith zero direct use — candidate for astorage-milvusextra split.🤖 Generated with Claude Code