Restore is_torch_fx_available for trust_remote_code backwards compatibility#44615
Open
MaybeSam05 wants to merge 1 commit intohuggingface:mainfrom
Open
Restore is_torch_fx_available for trust_remote_code backwards compatibility#44615MaybeSam05 wants to merge 1 commit intohuggingface:mainfrom
MaybeSam05 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Member
|
cc @ArthurZucker wdyt? We could consider reintroducing, but IMO a bit pointless as again we cannot guarantee BC for remote models, and it's bound to broke in another way soon (if it's not already broken in another fashion already) |
This was referenced Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Restores
is_torch_fx_availableintransformers.utils.import_utilsas a backwards-compatibility shim so that Hub models loaded withtrust_remote_code=Truethat still import this symbol no longer raiseImportErroron Transformers v5+.Context: In v5,
is_torch_fx_availablewas removed fromimport_utils. Many community models (e.g.deepseek-ai/deepseek-moe-16b-base) ship their ownmodeling_*.pyand still dofrom transformers.utils.import_utils import is_torch_fx_available, which breaks at import time when using v5.Changes:
is_torch_fx_available()insrc/transformers/utils/import_utils.py.DeprecationWarning(via@lru_cache), returnsFalseif PyTorch is not available, and otherwise checks thattorch.fxcan be imported and returnsTrue/False.torch.fxis always available, so behavior for existing callers is unchanged.Fixes #44561
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ArthurZucker @Rocketknight1 — this restores a symbol removed in v5 that breaks
trust_remote_codemodels (see #44561). Optional: @Cyrilvallez for model-loading/import-utils context.