zylon-ai/private-gpt · error · ValueError
Could not load tokenizer from '{model_id}': {e}
Error message
Could not load tokenizer from '{model_id}': {e} What it means
With downloads allowed, any OSError from AutoProcessor.from_pretrained is wrapped as ValueError("Could not load tokenizer from '{model_id}': {e}"). OSError from the Hub typically means the repo id is invalid/not found, the connection failed, or the repo is gated.
Source
Thrown at private_gpt/components/llm/tokenizers/huggingface.py:104
# Extract tokenizer from multimodal processor if needed
tokenizer: PreTrainedTokenizerBase
if hasattr(loaded, "tokenizer"):
processor = cast(ProcessorMixin, loaded)
tokenizer = cast(PreTrainedTokenizerBase, loaded.tokenizer)
is_multimodal = True
else:
tokenizer = cast(PreTrainedTokenizerBase, loaded)
return cls(tokenizer, is_multimodal=is_multimodal, processor=processor)
except OSError as e:
if local_files_only:
raise FileNotFoundError(
f"Local model files not found at '{model_id}'. "
f"Ensure the model is downloaded locally."
) from e
raise ValueError(f"Could not load tokenizer from '{model_id}': {e}") from e
except Exception as e:
raise ValueError(f"Failed to load tokenizer: {e}") from e
@classmethod
def is_available(cls, model_id: str | Path | None, **kwargs: Any) -> bool:
return bool(model_id)
@property
def all_special_tokens(self) -> list[str]:
tokens: list[str] = self._tokenizer.all_special_tokens
return tokens
@property
def all_special_ids(self) -> list[int]:
ids: list[int] = self._tokenizer.all_special_ids
return ids
@propertyView on GitHub (pinned to 4a030776a3)
Solutions
- Check the underlying message chained in {e}: fix the repo id or network access accordingly.
- For gated models run `hf auth login` and set HF_TOKEN so the download is authorized.
- For offline-capable setups, pre-download the model and pass local_files_only=True (which then gives the more specific FileNotFoundError if still missing).
Example fix
# before
tok = HuggingFaceTokenizer.from_pretrained('mistralai/mistral-7b-typo')
# after
hf auth login # if gated
tok = HuggingFaceTokenizer.from_pretrained('mistralai/Mistral-7B-Instruct-v0.3') Defensive patterns
Strategy: try-catch
Validate before calling
from huggingface_hub import HfApi
def repo_exists(model_id: str) -> bool:
try:
HfApi().repo_info(model_id)
return True
except Exception:
return False Try / catch
try:
tok = HuggingFaceTokenizer.from_pretrained(model_id)
except ValueError as e:
if 'Could not load tokenizer' in str(e):
cause = e.__cause__
logger.error('load failed for %s: %s', model_id, cause)
raise ModelLoadError(model_id, cause) from e
raise Prevention
- Validate repo ids (org/name, exactly one slash) before passing them in.
- Authenticate with `hf auth login` for gated models.
- Log the chained cause — the underlying OSError carries the real reason.
When it happens
Trigger: HuggingFaceTokenizer.from_pretrained('nonexistent/model') with local_files_only=False; network outage or blocked HF endpoint in sandboxes; gated repo without prior `hf auth login`; malformed repo id (more than one slash, spaces).
Common situations: Typo'd or retired model ids; egress-restricted corporate networks; missing HF token for Llama-style gated models; proxies/SSL interception breaking huggingface_hub requests.
Related errors
- Transformers dependencies are not installed.
- Local model files not found at '{model_id}'. Ensure the mode
- Failed to load tokenizer: {e}
- HuggingFaceTokenizer is not available with the given configu
- Remote tokenizer response did not contain a valid 'tokens' f
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/3f674801fbdc6d25.
Report an issue: GitHub.