You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from ..utils.dynamic_modules_utilsimportget_class_from_dynamic_module, resolve_trust_remote_code
38
+
from ..utils.hub_utilsimportload_or_create_model_card, populate_model_card
37
39
from .components_managerimportComponentsManager
38
40
from .modular_pipeline_utilsimport (
39
41
ComponentSpec,
@@ -47,8 +49,7 @@
47
49
format_intermediates_short,
48
50
make_doc_string,
49
51
)
50
-
fromhuggingface_hubimportcreate_repo
51
-
from ..utils.hub_utilsimportload_or_create_model_card, populate_model_card
52
+
52
53
53
54
ifis_accelerate_available():
54
55
importaccelerate
@@ -1670,16 +1671,21 @@ def __init__(
1670
1671
1671
1672
This method sets up the pipeline by:
1672
1673
1. creating default pipeline blocks if not provided
1673
-
2. gather component and config specifications based on the pipeline blocks's requirement (e.g. expected_components, expected_configs)
1674
-
3. update the loading specs of from_pretrained components based on the modular_model_index.json file from huggingface hub if `pretrained_model_name_or_path` is provided
1674
+
2. gather component and config specifications based on the pipeline blocks's requirement (e.g.
1675
+
expected_components, expected_configs)
1676
+
3. update the loading specs of from_pretrained components based on the modular_model_index.json file from
1677
+
huggingface hub if `pretrained_model_name_or_path` is provided
1675
1678
4. create defaultfrom_config components and register everything
1676
1679
1677
1680
Args:
1678
1681
blocks: `ModularPipelineBlocks` instance. If None, will attempt to load
1679
1682
default blocks based on the pipeline class name.
1680
1683
pretrained_model_name_or_path: Path to a pretrained pipeline configuration. If provided,
1681
-
will load component specs (only for from_pretrained components) and config values from the saved modular_model_index.json file.
1682
-
components_manager: Optional ComponentsManager for managing multiple component cross different pipelines and apply offloading strategies.
1684
+
will load component specs (only for from_pretrained components) and config values from the saved
1685
+
modular_model_index.json file.
1686
+
components_manager:
1687
+
Optional ComponentsManager for managing multiple component cross different pipelines and apply
1688
+
offloading strategies.
1683
1689
collection: Optional collection name for organizing components in the ComponentsManager.
1684
1690
**kwargs: Additional arguments passed to `load_config()` when loading pretrained configuration.
- If blocks is None, the method will try to find default blocks based on the pipeline class name
1704
-
- Components with default_creation_method="from_config" are created immediately, its specs are not included in config dict and will not be saved in `modular_model_index.json`
1705
-
- Components with default_creation_method="from_pretrained" are set to None and can be loaded later with `load_default_components()`/`load_components()`
1706
-
- The pipeline's config dict is populated with component specs (only for from_pretrained components) and config values, which will be saved as `modular_model_index.json` during `save_pretrained`
1707
-
- The pipeline's config dict is also used to store the pipeline blocks's class name, which will be saved as `_blocks_class_name` in the config dict
1708
+
- Components with default_creation_method="from_config" are created immediately, its specs are not included
1709
+
in config dict and will not be saved in `modular_model_index.json`
1710
+
- Components with default_creation_method="from_pretrained" are set to None and can be loaded later with
1711
+
`load_default_components()`/`load_components()`
1712
+
- The pipeline's config dict is populated with component specs (only for from_pretrained components) and
1713
+
config values, which will be saved as `modular_model_index.json` during `save_pretrained`
1714
+
- The pipeline's config dict is also used to store the pipeline blocks's class name, which will be saved as
PipelineState instance contains inputs and intermediate values. If None, a new `PipelineState` will be created based on the user inputs and the pipeline blocks's requirement.
1780
+
PipelineState instance contains inputs and intermediate values. If None, a new `PipelineState` will be
1781
+
created based on the user inputs and the pipeline blocks's requirement.
1773
1782
output (`str` or `List[str]`, optional):
1774
1783
Optional specification of what to return:
1775
1784
- None: Returns the complete `PipelineState` with all inputs and intermediates (default)
1776
1785
- str: Returns a specific intermediate value from the state (e.g. `output="image"`)
1777
-
- List[str]: Returns a dictionary of specific intermediate values (e.g. `output=["image", "latents"]`)
1786
+
- List[str]: Returns a dictionary of specific intermediate values (e.g. `output=["image",
- If `output` is None: Complete `PipelineState` containing all inputs and intermediates
1800
1810
- If `output` is str: The specific intermediate value from the state (e.g. `output="image"`)
1801
-
- If `output` is List[str]: Dictionary mapping output names to their values from the state (e.g. `output=["image", "latents"]`)
1811
+
- If `output` is List[str]: Dictionary mapping output names to their values from the state (e.g.
1812
+
`output=["image", "latents"]`)
1802
1813
"""
1803
1814
ifstateisNone:
1804
1815
state=PipelineState()
@@ -1880,11 +1891,14 @@ def from_pretrained(
1880
1891
1881
1892
Args:
1882
1893
pretrained_model_name_or_path (`str` or `os.PathLike`, optional):
1883
-
Path to a pretrained pipeline configuration. If provided, will load component specs (only for from_pretrained components) and config values from the modular_model_index.json file.
1894
+
Path to a pretrained pipeline configuration. If provided, will load component specs (only for
1895
+
from_pretrained components) and config values from the modular_model_index.json file.
1884
1896
trust_remote_code (`bool`, optional):
1885
-
Whether to trust remote code when loading the pipeline, need to be set to True if you want to create pipeline blocks based on the custom code in `pretrained_model_name_or_path`
1897
+
Whether to trust remote code when loading the pipeline, need to be set to True if you want to create
1898
+
pipeline blocks based on the custom code in `pretrained_model_name_or_path`
- When registering None for a component, it sets attribute to None but still syncs specs with the config dict, which will be saved as `modular_model_index.json` during `save_pretrained`
1997
-
- component_specs are updated to match the new component outside of this method, e.g. in `update_components()` method
2010
+
- When registering None for a component, it sets attribute to None but still syncs specs with the config
2011
+
dict, which will be saved as `modular_model_index.json` during `save_pretrained`
2012
+
- component_specs are updated to match the new component outside of this method, e.g. in
- Components with trained weights must be created using ComponentSpec.load(). If the component has not been shared in huggingface hub and you don't have loading specs, you can upload it using `push_to_hub()`
2250
+
- Components with trained weights must be created using ComponentSpec.load(). If the component has not been
2251
+
shared in huggingface hub and you don't have loading specs, you can upload it using `push_to_hub()`
2232
2252
- ConfigMixin objects without weights (e.g., schedulers, guiders) can be passed directly
2233
-
- ComponentSpec objects with default_creation_method="from_pretrained" are not supported in update_components()
2253
+
- ComponentSpec objects with default_creation_method="from_pretrained" are not supported in
2254
+
update_components()
2234
2255
"""
2235
2256
2236
2257
# extract component_specs_updates & config_specs_updates from `specs`
logger.warning(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}.")
2259
-
2260
-
self._component_specs[name] =new_component_spec
2279
+
logger.warning(
2280
+
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}."
2281
+
)
2261
2282
2283
+
self._component_specs[name] =new_component_spec
2262
2284
2263
2285
iflen(kwargs) >0:
2264
2286
logger.warning(f"Unexpected keyword arguments, will be ignored: {kwargs.keys()}")
0 commit comments