Skip to content

Conversation

@manueldeprada
Copy link
Contributor

@manueldeprada manueldeprada commented Apr 15, 2025

Prior to PR #36033, unexpected exceptions (e.g., ModuleNotFoundError) during hub model loading were not swallowed silently. They either matched specific except blocks or were raised.

After #36033, a catch-all except Exception block was introduced without a fallback else, causing unknown errors to be silently ignored and leading to misleading downstream behavior.

This commit adds an else: raise e to ensure only explicitly handled exceptions are suppressed. All others are surfaced, restoring pre-4.50 behavior and aiding in debugging and dependency visibility.

Fixes #37477, see my last comment there for more details.

Since I am new here, I appreciate reviews :)
Should a test for proper exceptions be written so this kind of regression does not happen again?

Who can review?

@gante @Cyrilvallez @Wauplin

Prior to PR #36033, unexpected exceptions (e.g., ModuleNotFoundError) during hub model loading were not swallowed silently. They either matched specific except blocks or were raised.

After #36033, a catch-all except Exception block was introduced without a fallback else, causing unknown errors to be silently ignored and leading to misleading downstream behavior.

This commit adds an `else: raise e` to ensure only explicitly handled exceptions are suppressed. All others are surfaced, restoring pre-4.50 behavior and aiding in debugging and dependency visibility.
@github-actions github-actions bot marked this pull request as draft April 15, 2025 11:11
@github-actions
Copy link
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@manueldeprada manueldeprada marked this pull request as ready for review April 15, 2025 11:15
Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yes, nice detective work figuring it out and solving it cleanly!

@Rocketknight1
Copy link
Member

Test issues here may be caused by intermittent Hub issues right now, although the change in this PR may make explicit errors more likely when that happens! You can try just pushing empty commits or rebasing to trigger tests to see if a second run fixes things.

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

I believe this final else should be after everything in the except block no? I.e. after we tried to recover from local files, and raised other exceptions depending on other types

@manueldeprada
Copy link
Contributor Author

I believe this final else should be after everything in the except block no? I.e. after we tried to recover from local files, and raised other exceptions depending on other types

thanks, youre right. I didnt see there was more condition tests right after :)
updated the branch!

@manueldeprada manueldeprada requested review from Cyrilvallez and removed request for ArthurZucker April 15, 2025 11:42
Cyrilvallez
Cyrilvallez previously approved these changes Apr 15, 2025
Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

Alright, LGTM now! 🤗 Thanks a lot! Hopefully that will help surface clearer issues, especially with the hub problems these days.
Do you know the range of Exception we expect to re-raise in this final else? Is it only ModuleNotFoundError, or some other types as well?

Let's wait for the CIs, then this should be good to go!

@Cyrilvallez
Copy link
Member

Wait, I think this final condition should in fact be

elif not isinstance(e, EntryNotFoundError):
    raise e

because as I mentionned in the comment, this specific one is treated later

@Cyrilvallez Cyrilvallez dismissed their stale review April 15, 2025 11:50

Should not raise EntryNotFound

@manueldeprada
Copy link
Contributor Author

manueldeprada commented Apr 15, 2025

Alright, LGTM now! 🤗 Thanks a lot! Hopefully that will help surface clearer issues, especially with the hub problems these days. Do you know the range of Exception we expect to re-raise in this final else? Is it only ModuleNotFoundError, or some other types as well?

Let's wait for the CIs, then this should be good to go!

thanks!!
honestly, no idea, and I don't think we can realistically cover every case. There can be all kinds of unexpected exceptions. For example, just a few days ago I saw PermissionError from file locks when using a shared HF_HUB_CACHE with incomplete downloads.

regarging CI, it's difficult to spot actual errors with the current flood of 404s. Maybe best to wait until the hub issues are resolved before merging?

@manueldeprada
Copy link
Contributor Author

manueldeprada commented Apr 15, 2025

Wait, I think this final condition should in fact be

elif not isinstance(e, EntryNotFoundError):
    raise e

because as I mentionned in the comment, this specific one is treated later

I see... took me time to follow that flow. thanks a lot for taking the time to review! 🤗
Updated the PR!

maybe I should write some proper exception tests?

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

Alright, I think this is finally the correct fix, and the CI seem to agree with me! Indeed if you don't mind, a test with a custom Exception would indeed be nice to make sure we keep handling it correctly in the future! 🤗

Let's add the comment as well 😉

@manueldeprada
Copy link
Contributor Author

Alright, I think this is finally the correct fix, and the CI seem to agree with me! Indeed if you don't mind, a test with a custom Exception would indeed be nice to make sure we keep handling it correctly in the future! 🤗

Let's add the comment as well 😉

thanks a lot!! will merge and do the tests later this week :)

@manueldeprada manueldeprada merged commit 0ad3710 into main Apr 15, 2025
20 of 21 checks passed
@manueldeprada manueldeprada deleted the manueldeprada-patch-hub branch April 15, 2025 12:54
@Cyrilvallez
Copy link
Member

It's totally fine and I'm happy that we merged this one quickly as it should help our workflows, but it's in general more advisable to add the tests along the fixes themselves! 🤗 Just because they may sometimes surface issues we did not think about, or simply because we may otherwise forget to add them/get absorbed in other things!

cyr0930 pushed a commit to cyr0930/transformers that referenced this pull request Apr 18, 2025
…uggingface#37525)

* fix: Restore explicit error surfacing for unexpected hub exceptions

Prior to PR huggingface#36033, unexpected exceptions (e.g., ModuleNotFoundError) during hub model loading were not swallowed silently. They either matched specific except blocks or were raised.

After huggingface#36033, a catch-all except Exception block was introduced without a fallback else, causing unknown errors to be silently ignored and leading to misleading downstream behavior.

This commit adds an `else: raise e` to ensure only explicitly handled exceptions are suppressed. All others are surfaced, restoring pre-4.50 behavior and aiding in debugging and dependency visibility.

Co-authored-by: Cyril Vallez <[email protected]>
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
…uggingface#37525)

* fix: Restore explicit error surfacing for unexpected hub exceptions

Prior to PR huggingface#36033, unexpected exceptions (e.g., ModuleNotFoundError) during hub model loading were not swallowed silently. They either matched specific except blocks or were raised.

After huggingface#36033, a catch-all except Exception block was introduced without a fallback else, causing unknown errors to be silently ignored and leading to misleading downstream behavior.

This commit adds an `else: raise e` to ensure only explicitly handled exceptions are suppressed. All others are surfaced, restoring pre-4.50 behavior and aiding in debugging and dependency visibility.

Co-authored-by: Cyril Vallez <[email protected]>
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.

Unrecognized model in Qwen/Qwen2.5-Coder-7B-Instruct

4 participants