[Fix] Resolve deprecated pipeline modules in from_pretrained#14026
Open
Nas01010101 wants to merge 1 commit into
Open
[Fix] Resolve deprecated pipeline modules in from_pretrained#14026Nas01010101 wants to merge 1 commit into
Nas01010101 wants to merge 1 commit into
Conversation
Pipelines relocated to `diffusers.pipelines.deprecated` (e.g. Wuerstchen via huggingface#13157) are no longer attributes of `diffusers.pipelines`, so the `hasattr(pipelines, module_candidate)` check in `_get_custom_components_and_folders` mistook them for missing custom modules and raised a spurious ValueError when loading repos such as `warp-ai/wuerstchen-prior`. Also check the deprecated namespace (via `importlib.util.find_spec`, no import side effects) before treating a component as a missing custom module. Genuinely missing modules still raise. Fixes huggingface#14008
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?
Fixes #14008
The bug
DiffusionPipeline.from_pretrainedraises a spuriousValueErrorwhen loading any pipeline that was relocated underdiffusers.pipelines.deprecated(for example Wuerstchen, moved in #13157):Root cause
This is a bug in the deprecation mechanism itself, not in the deprecated pipeline.
_get_custom_components_and_foldersdecides whether a component refers to a built-in module viahasattr(diffusers.pipelines, module_candidate). When a pipeline is moved todiffusers.pipelines.deprecated, its module name is no longer a top-level attribute ofdiffusers.pipelines(deprecated modules are nested under thedeprecatedkey in_import_structure). SohasattrreturnsFalse, the component is mistaken for a missing custom module, and loading fails.The fix suggested in the issue (
hasattr(diffusers.pipelines.deprecated, module_candidate)) does not work:diffusers.pipelines.deprecatedis a_LazyModule, so the module name (wuerstchen) is not an attribute until it is imported; only the lazily exposed class names are.hasattrtherefore still returnsFalse.Fix
Resolve the module spec under the deprecated namespace without importing it, via
importlib.util.find_spec("diffusers.pipelines.deprecated.<module>"). This is import side-effect free (no heavy import is triggered) and correctly recognizes relocated modules. Genuinely missing modules still raise, sincefind_specreturnsNonefor them.Tests
Added
GetCustomComponentsAndFoldersTestsintests/pipelines/test_pipeline_utils.py(the existing home forpipeline_loading_utilsunit tests). All are function level and require no network or GPU.Reverting only the production change reproduces the issue (
from_pretrainedraises theValueErrorabove) and makes the new tests fail, confirming they guard the bug.ruff checkandruff format --checkpass on the changed files.Before submitting
.ai/review-rules.md, and I understand and take responsibility for the change.