Skip to content

Commit 2c45daf

Browse files
committed
up
1 parent bda2f18 commit 2c45daf

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/diffusers/modular_pipelines/modular_pipeline.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,6 @@ def __init__(
18761876

18771877
# update component_specs and config_specs from modular_repo
18781878
if pretrained_model_name_or_path is not None:
1879-
18801879
try:
18811880
config_dict = self.load_config(pretrained_model_name_or_path, **kwargs)
18821881
for name, value in config_dict.items():
@@ -1892,8 +1891,9 @@ def __init__(
18921891

18931892
except EnvironmentError as e:
18941893
logger.debug(e)
1895-
logger.debug(f" modular_model_index.json not found in the repo, trying to load from model_index.json")
1894+
logger.debug(" modular_model_index.json not found in the repo, trying to load from model_index.json")
18961895
from diffusers import DiffusionPipeline
1896+
18971897
config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path)
18981898
for name, value in config_dict.items():
18991899
if name in self._component_specs and isinstance(value, (tuple, list)) and len(value) == 2:
@@ -2435,17 +2435,31 @@ def update_components(self, **kwargs):
24352435
for name, component in passed_components.items():
24362436
current_component_spec = self._component_specs[name]
24372437

2438-
# warn if type changed
2438+
# log if type changed
24392439
if current_component_spec.type_hint is not None and not isinstance(
24402440
component, current_component_spec.type_hint
24412441
):
2442-
logger.warning(
2442+
logger.info(
24432443
f"ModularPipeline.update_components: adding {name} with new type: {component.__class__.__name__}, previous type: {current_component_spec.type_hint.__name__}"
24442444
)
24452445
# update _component_specs based on the new component
2446-
new_component_spec = ComponentSpec.from_component(name, component)
2447-
if new_component_spec.default_creation_method != current_component_spec.default_creation_method:
2446+
if component is None:
2447+
new_component_spec = current_component_spec
2448+
if hasattr(self, name) and getattr(self, name) is not None:
2449+
logger.warning(f"ModularPipeline.update_components: setting {name} to None (spec unchanged)")
2450+
elif current_component_spec.default_creation_method == "from_pretrained" and not (
2451+
hasattr(component, "_diffusers_load_id") and component._diffusers_load_id is not None
2452+
):
24482453
logger.warning(
2454+
f"ModularPipeline.update_components: {name} has no valid _diffusers_load_id. "
2455+
f"Updating the component but skipping spec update, use ComponentSpec.load() for proper specs"
2456+
)
2457+
new_component_spec = current_component_spec
2458+
else:
2459+
new_component_spec = ComponentSpec.from_component(name, component)
2460+
2461+
if new_component_spec.default_creation_method != current_component_spec.default_creation_method:
2462+
logger.info(
24492463
f"ModularPipeline.update_components: changing the default_creation_method of {name} from {current_component_spec.default_creation_method} to {new_component_spec.default_creation_method}."
24502464
)
24512465

@@ -2466,7 +2480,7 @@ def update_components(self, **kwargs):
24662480
if current_component_spec.type_hint is not None and not isinstance(
24672481
created_components[name], current_component_spec.type_hint
24682482
):
2469-
logger.warning(
2483+
logger.info(
24702484
f"ModularPipeline.update_components: adding {name} with new type: {created_components[name].__class__.__name__}, previous type: {current_component_spec.type_hint.__name__}"
24712485
)
24722486
# update _component_specs based on the user passed component_spec

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,36 @@ def _get_signature_types(cls):
17061706
logger.warning(f"cannot get type annotation for Parameter {k} of {cls}.")
17071707
return signature_types
17081708

1709+
@property
1710+
def parameters(self) -> Dict[str, Any]:
1711+
r"""
1712+
The `self.parameters` property can be useful to run different pipelines with the same weights and
1713+
configurations without reallocating additional memory.
1714+
1715+
Returns (`dict`):
1716+
A dictionary containing all the optional parameters needed to initialize the pipeline.
1717+
1718+
Examples:
1719+
1720+
```py
1721+
>>> from diffusers import (
1722+
... StableDiffusionPipeline,
1723+
... StableDiffusionImg2ImgPipeline,
1724+
... StableDiffusionInpaintPipeline,
1725+
... )
1726+
1727+
>>> text2img = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
1728+
>>> img2img = StableDiffusionImg2ImgPipeline(**text2img.components, **text2img.parameters)
1729+
>>> inpaint = StableDiffusionInpaintPipeline(**text2img.components, **text2img.parameters)
1730+
```
1731+
"""
1732+
expected_modules, optional_parameters = self._get_signature_keys(self)
1733+
pipeline_parameters = {
1734+
k: self.config[k] for k in self.config.keys() if not k.startswith("_") and k in optional_parameters
1735+
}
1736+
1737+
return pipeline_parameters
1738+
17091739
@property
17101740
def components(self) -> Dict[str, Any]:
17111741
r"""

0 commit comments

Comments
 (0)