Skip to content

fix: catch HfHubHTTPError in safetensors auto_conversion thread - #44440

Closed
weiguangli-io wants to merge 1 commit into
huggingface:mainfrom
weiguangli-io:codex/transformers-44403-safetensors-noise
Closed

fix: catch HfHubHTTPError in safetensors auto_conversion thread#44440
weiguangli-io wants to merge 1 commit into
huggingface:mainfrom
weiguangli-io:codex/transformers-44403-safetensors-noise

Conversation

@weiguangli-io

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the noisy HfHubHTTPError exception output that appears when loading a transformer model from a repository that has discussions disabled.

Root cause

The previous_pr() function in safetensors_conversion.py calls get_repo_discussions() which raises HfHubHTTPError (403 Forbidden) when a repo has discussions disabled. This exception propagated up through the background Thread-auto_conversion thread, producing a scary traceback during normal model loading.

Changes

  1. src/transformers/safetensors_conversion.py: Wrap the get_repo_discussions() iteration in previous_pr() with a try/except HfHubHTTPError block, logging a debug-level message instead of propagating the exception.

  2. src/transformers/modeling_utils.py: Change ignore_errors_during_conversion from False to True for the background auto-conversion thread, since this thread is a best-effort optimization for future loads and should never produce user-visible error output.

Fixes #44403

Before

>>> from transformers import AutoModel
>>> bert_model = AutoModel.from_pretrained('hfl/chinese-electra-180g-large-discriminator')
...
Exception in Thread-auto_conversion:
Traceback (most recent call last):
  ...
huggingface_hub.errors.HfHubHTTPError: 403 Forbidden: Discussions are disabled for this repo.

After

>>> from transformers import AutoModel
>>> bert_model = AutoModel.from_pretrained('hfl/chinese-electra-180g-large-discriminator')
>>> # No exception output

馃 Generated with Claude Code

The background auto-conversion thread would raise unhandled
HfHubHTTPError exceptions when a model repository has discussions
disabled. This caused noisy error output during normal model loading.

Two changes:
- Catch HfHubHTTPError in previous_pr() when iterating discussions,
  logging a debug message instead of propagating the exception
- Set ignore_errors_during_conversion=True for the background thread
  so any remaining errors are silently suppressed

Fixes huggingface#44403
@Rocketknight1

Copy link
Copy Markdown
Member

Opening PRs to random issues when people are still discussing the issue is not actually helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary noise when loading a transformer

2 participants