-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[Modular] loader related #13025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Modular] loader related #13025
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| name | ||
| for name in self._component_specs.keys() | ||
| if self._component_specs[name].default_creation_method == "from_pretrained" | ||
| and self._component_specs[name].pretrained_model_name_or_path is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this change, now, by default with pipeline.load_components():
- we don't load components that's already loaded in pipeline
- we don't load the components that do not have valid
pretrained_model_name_or_path
for (1), currently, under the main, if we run script below, we will load the text_encoder, add it to the pipeline with update_components, and then reload again when you run load_components() - which is a bit unintuitive I think
in this PR, it will skip text_encoder instead of loading all components
pipe = ModularPipeline.from_pretrained()
text_encoder = AutoModel.from_pretrained(...)
pipe.update_components(text_encoder=text_encoder )
pipe.load_components(torch_dtype=torch.bfloat16)for (2), in main, if you run this
from diffusers import ModularPipeline
pipe = ModularPipeline.from_pretrained("Qwen/Qwen-Image")
pipe.load_components(torch_dtype=torch.bfloat16)you would get a confusing message like this
Failed to create component controlnet:
- Component spec: ComponentSpec(name='controlnet', type_hint=<class 'diffusers.models.controlnets.controlnet_qwenimage.QwenImageControlNetModel'>, description=None, config=None, pretrained_model_name_or_path=None, subfolder='', variant=None, revision=None, default_creation_method='from_pretrained', repo=None)
- load() called with kwargs: {'torch_dtype': torch.bfloat16}
If this component is not required for your workflow you can safely ignore this message.
Traceback:
Traceback (most recent call last):
File "/fsx/yiyi/diffusers/src/diffusers/modular_pipelines/modular_pipeline.py", line 2173, in load_components
components_to_register[name] = spec.load(**component_load_kwargs)
File "/fsx/yiyi/diffusers/src/diffusers/modular_pipelines/modular_pipeline_utils.py", line 279, in load
raise ValueError(
ValueError: `pretrained_model_name_or_path` info is required when using `load` method (you can directly set it in `pretrained_model_name_or_path` field of the ComponentSpec or pass it as an argument)
this is because controlnet is a component in qwen auto pipeline, but not included in Qwen/Qwen-Image; in this PR, we just skip it by default and not sending any message - I think it is more of an expected behavior
|
ready for an initial review! let me know if you have other suggestions for making the loading behavior more intuitive/user-friendly once we are happy with it, we want to start building out a test suite and updating the docs. |
WIP
a few loading related refactor
will also add a test suit along this PR
refactor1: tag model with
_diffusers_load_idinsideAutoModel.from_pretrainedAutoModel now tags a
_diffusers_load_idon loaded models, this is to make it easier to serialize ModolarPipeline into amodular_model_index.jsonwith info such aspretrained_model_name_or_path,subfolder,variant,revisionrunning this under main would get a warn
but it would work without an issue under this PR
refactor 2: more intuitive (I hope!) defaults behavior for load_components()
load_components()now skips components that are already loaded or don't have a valid pretrained_model_name_or_path in their spec. This avoids unnecessary reloading and confusing error messages for optional components. See inline comments for details.