zylon-ai/private-gpt · error · ImportError
Transformers dependencies are not installed.
Error message
Transformers dependencies are not installed.
What it means
HuggingFaceTokenizer.from_pretrained imports transformers.AutoProcessor inside the method so that the rest of the module works without transformers installed. If the import fails it raises ImportError with a formatted missing-dependency message for 'Transformers'.
Source
Thrown at private_gpt/components/llm/tokenizers/huggingface.py:69
**kwargs: Any,
) -> "HuggingFaceTokenizer":
"""Load tokenizer from pretrained model with intelligent caching.
If the model is already cached locally, it will automatically use
offline mode to avoid network calls.
Args:
model_id: Model identifier or local path
local_files_only: Force offline mode (no downloads)
cache_dir: Custom cache directory
force_download: Force re-download even if cached
trust_remote_code: Allow custom code from model repositories
**kwargs: Additional arguments for AutoProcessor
"""
try:
from transformers import AutoProcessor # ty:ignore[unresolved-import]
except ImportError as e:
raise ImportError(
format_missing_dependency_message(
"Transformers",
)
) from e
try:
is_multimodal = False
processor = None
loaded: Any = AutoProcessor.from_pretrained(
pretrained_model_name_or_path=model_id,
local_files_only=local_files_only,
cache_dir=cache_dir,
force_download=force_download,
trust_remote_code=trust_remote_code,
**kwargs,
)
# Extract tokenizer from multimodal processor if neededView on GitHub (pinned to 4a030776a3)
Solutions
- Install transformers (or the project extra that pulls it in, e.g. the local-LLM extra): uv sync --inexact --extra <local-llm-extra>.
- Verify: python -c "from transformers import AutoProcessor".
- If you only use remote APIs and don't need real tokenization, switch tokenizer_mode to 'estimator' or 'remote'.
Example fix
# before: tokenizer_mode='huggingface' without transformers installed # after uv sync --inexact --extra llm-huggingface # or pip install transformers
Defensive patterns
Strategy: validation
Validate before calling
def transformers_available() -> bool:
try:
from transformers import AutoProcessor # noqa: F401
return True
except ImportError:
return False Try / catch
try:
tok = HuggingFaceTokenizer.from_pretrained(model_id)
except ImportError as e:
logger.warning('transformers missing; falling back to estimator tokenizer')
tok = TokenizerRegistry.get_tokenizer('estimator', model_id=model_id) Prevention
- Include the tokenizer extras in deployments that set tokenizer_mode to 'huggingface' or 'chat'.
- Add a startup dependency probe when local model support is enabled.
- Document which config flags require which extras.
When it happens
Trigger: Calling HuggingFaceTokenizer.from_pretrained (directly or via TokenizerRegistry modes 'huggingface'/'chat') in an environment lacking the transformers package.
Common situations: Slack/minimal installs that skipped the tokenizer extras; Docker images trimmed for remote-API-only deployments (no local models) where tokenizer_mode was later changed to 'huggingface'; CI environments with a reduced dependency set.
Related errors
- HuggingFaceTokenizer is not available with the given configu
- Mistral tokenizer dependencies are not installed. Install wi
- tiktoken dependencies are not installed. Install with `uv sy
- DB2 database query dependencies are not installed. Install w
- OpenAI embeddings dependencies are not installed. Install wi
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/33022a952e797eb9.
Report an issue: GitHub.