A central registry and management system for model components across multiple pipelines.
ComponentsManager provides a unified way to register, track, and reuse model components (like UNet, VAE, text
encoders, etc.) across different modular pipelines. It includes features for duplicate detection, memory
management, and component organization.
This is an experimental feature and is likely to change in the future.
Example:
from diffusers import ComponentsManager
# Create a components manager
cm = ComponentsManager()
# Add components
cm.add("unet", unet_model, collection="sdxl")
cm.add("vae", vae_model, collection="sdxl")
# Enable auto offloading
cm.enable_auto_cpu_offload(device="cuda")
# Retrieve components
unet = cm.get_one(name="unet", collection="sdxl")
device (Union[str, int, torch.device]) — The execution device where models are moved for forward passes
memory_reserve_margin (str) — The memory reserve margin to use, default is 3GB. This is the amount of
memory to keep free on the device to avoid running out of memory during model
execution (e.g., for intermediate activations, gradients, etc.)
Enable automatic CPU offloading for all components.
The algorithm works as follows:
All models start on CPU by default
When a model’s forward pass is called, it’s moved to the execution device
If there’s insufficient memory, other models on the device are moved back to CPU
The system tries to offload the smallest combination of models that frees enough memory
Models stay on the execution device until another model needs memory and forces them off
component_id (str) — Name of the component to get info for
fields (Optional[Union[str, List[str]]]) —
Field(s) to return. Can be a string for single field or list of fields. If None, uses the
available_info_fields setting.
“unet” : match any component with base name “unet” (e.g., unet_123abc)
“!unet” : everything except components with base name “unet”
“unet*” : anything with base name starting with “unet”
“!unet*” : anything with base name NOT starting with “unet”
”unet” : anything with base name containing “unet”
“!unet” : anything with base name NOT containing “unet”
“refiner|vae|unet” : anything with base name exactly matching “refiner”, “vae”, or “unet”
“!refiner|vae|unet” : anything with base name NOT exactly matching “refiner”, “vae”, or “unet”
“unet|vae” : anything with base name starting with “unet” OR starting with “vae”
collection — Optional collection to filter by
load_id — Optional load_id to filter by
return_dict_with_names —
If True, returns a dictionary with component names as keys, throw an error if
multiple components with the same name are found If False, returns a dictionary
with component IDs as keys
Search components by name with simple pattern matching. Optionally filter by collection or load_id.