diffusers
4c72e588 - Merge commit from fork

Commit
23 days ago
Merge commit from fork * Don't import modules named by a model repository A component's library name is read from `model_index.json` / `modular_model_index.json` and reached `importlib.import_module`. Requirement names are read from `modular_config.json` and reached `importlib.util.find_spec`, which imports the parent packages of a dotted name. A repository that sits on a `sys.path` root -- what a `git clone` or `hf download --local-dir` into the working directory gives you -- could therefore run a `.py` file it ships on a `from_pretrained()` with default arguments, with `trust_remote_code=False` and even with `DIFFUSERS_DISABLE_REMOTE_CODE=1`. Library names are now imported only when they name one of `LOADABLE_CLASSES` or a `diffusers.pipelines` module. Any other name is resolved from `sys.modules`, so a component class defined in the caller's own code still round-trips through `save_pretrained`, while a name only the repository knows about is never imported. Requirement names are resolved through `importlib.metadata`, which reads distribution metadata and imports nothing. `ModularPipelineBlocks.from_pretrained` also acted on a repository's `requirements` before `trust_remote_code` was resolved, and only raised for a repository without `auto_map` when `trust_remote_code=True` had been passed. It now raises either way, before reading anything else from the config. * Address review: drop the _package_map rebuild, test a mapped name _package_map is already built at import time, so _is_distribution_installed reads it directly and _is_package_available goes back to what it is on main. ValueError is caught alongside PackageNotFoundError because an empty requirement name raises that instead, and the keys come from a repository. test_installed_requirement_is_still_resolved now uses PIL, whose distribution is named pillow, so it exercises the import-name-to-distribution mapping. * Resolve component library names against imported modules only `_get_library_or_raise` now resolves a `diffusers.pipelines` submodule via `getattr(pipelines, library_name)` rather than re-importing it by name, and raises a clear error when the resolved module has no such class. --------- Co-authored-by: LinZiyu <221020063@fzu.edu.cn> Co-authored-by: DN6 <dhruv.nair@gmail.com> (cherry picked from commit 30766058a7364244d0bdf5d3bc476a64a687243f)
Author
Committer
DN6 DN6
Parents
Loading