( blocks: typing.Optional[diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks] = None pretrained_model_name_or_path: typing.Union[str, os.PathLike, NoneType] = None components_manager: typing.Optional[diffusers.modular_pipelines.components_manager.ComponentsManager] = None collection: typing.Optional[str] = None **kwargs )
Base class for all Modular pipelines.
This is an experimental feature and is likely to change in the future.
( pretrained_model_name_or_path: typing.Union[str, os.PathLike, NoneType] trust_remote_code: typing.Optional[bool] = None components_manager: typing.Optional[diffusers.modular_pipelines.components_manager.ComponentsManager] = None collection: typing.Optional[str] = None **kwargs )
Parameters
str or os.PathLike, optional) —
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. bool, optional) —
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 ComponentsManager, optional) —
ComponentsManager instance for managing multiple component cross different pipelines and apply
offloading strategies. str, optional) —`
Collection name for organizing components in the ComponentsManager. Load a ModularPipeline from a huggingface hub repo.
( names: typing.Union[typing.List[str], str] **kwargs )
Parameters
from_pretrained().Can be:repo,
variant, revision, etc.Load selected components from specs.
( **kwargs )
Load from_pretrained components using the loading specs in the config dict.
( **kwargs )
Register components with their corresponding specifications.
This method is responsible for:
modular_model_index.json during save_pretrained (only
for from_pretrained components)This method is called when:
update_components() method: e.g. loader.update_components(unet=unet) or
loader.update_components(guider=guider_spec)load_default_components() method: e.g.
loader.load_default_components(names=[“unet”])Notes:
modular_model_index.json during save_pretrainedupdate_components() method( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )
Save the pipeline to a directory. It does not save components, you need to save them separately.
( *args **kwargs ) → DiffusionPipeline
Parameters
torch.dtype, optional) —
Returns a pipeline with the specified
dtype torch.Device, optional) —
Returns a pipeline with the specified
device str, optional, defaults to False) —
Whether to omit warnings if the target dtype is not compatible with the target device. Returns
The pipeline converted to specified dtype and/or dtype.
Performs Pipeline dtype and/or device conversion. A torch.dtype and torch.device are inferred from the
arguments of self.to(*args, **kwargs).
If the pipeline already has the correct torch.dtype and torch.device, then it is returned as is. Otherwise, the returned pipeline is a copy of self with the desired torch.dtype and torch.device.
Here are the ways to call to:
to(dtype, silence_dtype_warnings=False) → DiffusionPipeline to return a pipeline with the specified
dtypeto(device, silence_dtype_warnings=False) → DiffusionPipeline to return a pipeline with the specified
deviceto(device=None, dtype=None, silence_dtype_warnings=False) → DiffusionPipeline to return a pipeline with the
specified device and
dtype( **kwargs )
Parameters
ComponentSpec.from_component() method i.e. components created with ComponentSpec.load() or
ConfigMixin subclasses that aren’t nn.Modules (e.g., unet=new_unet, text_encoder=new_encoder)guider=ComponentSpec(name="guider", type_hint=ClassifierFreeGuidance, config={...}, default_creation_method="from_config"))requires_safety_checker=False)Raises
ValueError
ValueError — If a component object is not supported in ComponentSpec.from_component() method:_diffusers_load_id attribute_diffusers_load_id attributeUpdate components and configuration values and specs after the pipeline has been instantiated.
This method allows you to:
self.unet or self.text_encoder)self.requires_safety_checker flag)In addition to updating the components and configuration values as pipeline attributes, the method also updates:
_component_specs and _config_specsconfig dict, which will be saved as modular_model_index.json during save_pretrainedExamples:
# Update multiple components at once
pipeline.update_components(unet=new_unet_model, text_encoder=new_text_encoder)
# Update configuration values
pipeline.update_components(requires_safety_checker=False)
# Update both components and configs together
pipeline.update_components(unet=new_unet_model, requires_safety_checker=False)
# Update with ComponentSpec objects (from_config only)
pipeline.update_components(
guider=ComponentSpec(
name="guider",
type_hint=ClassifierFreeGuidance,
config={"guidance_scale": 5.0},
default_creation_method="from_config",
)
)Notes:
push_to_hub()