Skip to content

Make transformers an opt-in dependency (conserver-local group)#188

Merged
pavanputhra merged 6 commits into
mainfrom
deps/transformers-optional
Jun 7, 2026
Merged

Make transformers an opt-in dependency (conserver-local group)#188
pavanputhra merged 6 commits into
mainfrom
deps/transformers-optional

Conversation

@howethomas

Copy link
Copy Markdown
Contributor

Summary

transformers is the single largest installed package in the project (~48MB on its own; ~67MB once you count tokenizers, huggingface_hub, and hf_xet, plus shared numpy). Despite that weight, its only consumer is conserver/links/hugging_llm_link, and only the LocalHuggingFaceLLM path uses it:

  • That path is off by default (use_local_model: false).
  • It calls transformers.pipeline("text-generation", ...), which needs a model backend (torch). torch is not a project dependency, so the local path cannot run today regardless.
  • The default path is a plain requests.post() to the HuggingFace inference API and needs none of transformers.
  • LLM analysis is already covered by the analyze / analyze_and_label / analyze_vcon links (OpenAI/Groq).

This makes transformers a large dependency carried by every conserver image for an off-by-default, non-functional path. This PR makes it opt-in.

Changes

  • pyproject.toml: move transformers>=4.48.0 out of the base conserver group into a new opt-in conserver-local group.
  • hugging_llm_link/__init__.py: defer import transformers into LocalHuggingFaceLLM.__init__, raising a clear ImportError (with the install command) if the optional group isn't present. Importing the link no longer loads transformers.
  • hugging_llm_link/main.py: lazy-import pipeline inside HuggingLLMLink.__init__.
  • README: document that local inference is opt-in and additionally needs a backend (torch).
  • uv.lock: regenerated — the transformers node is unchanged, just regrouped.

Impact

Removes ~67MB from the base conserver install with no functional change to the default API-based path. Users who want on-device inference install it explicitly:

uv sync --group conserver --group conserver-local   # + a backend, e.g. torch

Testing

conserver/tests/test_link_metrics.py: 25/25 pass (incl. both TestHuggingLLMMetrics cases). Verified that importing links.hugging_llm_link (and its main) no longer pulls transformers into sys.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 via pymilvus with zero direct use — candidate for a storage-milvus extra split.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 3, 2026 22:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.0 from the base conserver dependency group to a new optional conserver-local group (and regroup in uv.lock).
  • Lazy-import transformers/pipeline within hugging_llm_link code paths so importing the link no longer pulls ML dependencies.
  • Document that local inference is opt-in and requires installing conserver-local plus 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.

Comment thread conserver/links/hugging_llm_link/__init__.py
Comment thread conserver/links/hugging_llm_link/main.py Outdated
Copilot AI review requested due to automatic review settings June 3, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Comment thread conserver/links/hugging_llm_link/main.py Outdated
Comment thread conserver/links/hugging_llm_link/main.py
Comment thread conserver/links/hugging_llm_link/__init__.py
howethomas and others added 3 commits June 3, 2026 18:36
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>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 19:56
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Comment thread conserver/links/hugging_llm_link/__init__.py
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 pavanputhra merged commit ed52ed0 into main Jun 7, 2026
1 check passed
@pavanputhra pavanputhra deleted the deps/transformers-optional branch June 7, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants