Buckets:
| import"../chunks/DsnmJJEf.js";import{i as B,h as W,C as X,H as P,D as o,E as H,s as U,a as Z}from"../chunks/CmJXCtRL.js";import{p as J,o as S,s as e,f as M,a as h,b as q,c as n,d as f,n as i,r as t}from"../chunks/DK803DsY.js";import{E as G}from"../chunks/Bu2vAape.js";const A='{"title":"Pipeline","local":"pipeline","sections":[{"title":"ModularPipeline","local":"diffusers.ModularPipeline","sections":[],"depth":2}],"depth":1}';var E=f('<meta name="hf:doc:metadata"/>'),Q=f("<p>Examples:</p> <!>",1),Y=f(`<p></p> <!> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Base class for all Modular pipelines.</p> <blockquote class="warning"><p>> This is an experimental feature and is likely to change in the future.</p></blockquote> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load a ModularPipeline from a huggingface hub repo.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load selected components from specs.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Register components with their corresponding specifications.</p> <p>This method is responsible for:</p> <ol><li>Sets component objects as attributes on the loader (e.g., self.unet = unet)</li> <li>Updates the config dict, which will be saved as <code>modular_model_index.json</code> during <code>save_pretrained</code> (only | |
| for from_pretrained components)</li> <li>Adds components to the component manager if one is attached (only for from_pretrained components)</li></ol> <p>This method is called when:</p> <ul><li>Components are first initialized in <strong>init</strong>: <ul><li>from_pretrained components not loaded during <strong>init</strong> so they are registered as None;</li> <li>non from_pretrained components are created during <strong>init</strong> and registered as the object itself</li></ul></li> <li>Components are updated with the <code>update_components()</code> method: e.g. loader.update_components(unet=unet) or | |
| loader.update_components(guider=guider_spec)</li> <li>(from_pretrained) Components are loaded with the <code>load_components()</code> method: e.g. | |
| loader.load_components(names=[“unet”]) or loader.load_components() to load all default components</li></ul> <p>Notes:</p> <ul><li>When registering None for a component, it sets attribute to None but still syncs specs with the config | |
| dict, which will be saved as <code>modular_model_index.json</code> during <code>save_pretrained</code></li> <li>component_specs are updated to match the new component outside of this method, e.g. in <code>update_components()</code> method</li></ul></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Save the pipeline and all its components to a directory, so that it can be re-loaded using the <a href="/docs/diffusers/pr_13881/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> class method.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Performs Pipeline dtype and/or device conversion. A torch.dtype and torch.device are inferred from the | |
| arguments of <code>self.to(*args, **kwargs).</code></p> <blockquote class="tip"><p>> 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.</p></blockquote> <p>Here are the ways to call <code>to</code>:</p> <ul><li><code>to(dtype, silence_dtype_warnings=False) → DiffusionPipeline</code> to return a pipeline with the specified <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.dtype" rel="nofollow"><code>dtype</code></a></li> <li><code>to(device, silence_dtype_warnings=False) → DiffusionPipeline</code> to return a pipeline with the specified <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.device" rel="nofollow"><code>device</code></a></li> <li><code>to(device=None, dtype=None, silence_dtype_warnings=False) → DiffusionPipeline</code> to return a pipeline with the | |
| specified <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.device" rel="nofollow"><code>device</code></a> and <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.dtype" rel="nofollow"><code>dtype</code></a></li></ul></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Update components and configuration values and specs after the pipeline has been instantiated.</p> <p>This method allows you to:</p> <ol><li>Replace existing components with new ones (e.g., updating <code>self.unet</code> or <code>self.text_encoder</code>)</li> <li>Update configuration values (e.g., changing <code>self.requires_safety_checker</code> flag)</li></ol> <p>In addition to updating the components and configuration values as pipeline attributes, the method also | |
| updates:</p> <ul><li>the corresponding specs in <code>_component_specs</code> and <code>_config_specs</code></li> <li>the <code>config</code> dict, which will be saved as <code>modular_model_index.json</code> during <code>save_pretrained</code></li></ul> <!> <p>Notes:</p> <ul><li>Components loaded with <code>AutoModel.from_pretrained()</code> or <code>ComponentSpec.load()</code> will have | |
| loading specs preserved for serialization. Custom or locally loaded components without Hub references will | |
| have their <code>modular_model_index.json</code> entries updated automatically during <code>save_pretrained()</code>.</li> <li>ConfigMixin objects without weights (e.g., schedulers, guiders) can be passed directly.</li></ul></div></div> <!> <p></p>`,1);function oe(N,C){J(C,!1),S(()=>{new URLSearchParams(window.location.search).get("fw")}),B();var g=Y();W("3aklyj",r=>{var u=E();U(u,"content",A),h(r,u)});var _=e(M(g),2);X(_,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var v=e(_,2);P(v,{title:"Pipeline",local:"pipeline",headingTag:"h1"});var b=e(v,2);P(b,{title:"ModularPipeline",local:"diffusers.ModularPipeline",headingTag:"h2"});var a=e(b,2),y=n(a);o(y,{name:"class diffusers.ModularPipeline",anchor:"diffusers.ModularPipeline",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L1595",parameters:[{name:"blocks",val:": diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None"},{name:"pretrained_model_name_or_path",val:": str | os.PathLike | None = None"},{name:"components_manager",val:": diffusers.modular_pipelines.components_manager.ComponentsManager | None = None"},{name:"collection",val:": str | None = None"},{name:"modular_config_dict",val:": dict[str, typing.Any] | None = None"},{name:"config_dict",val:": dict[str, typing.Any] | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.blocks",description:"<strong>blocks</strong> — ModularPipelineBlocks, the blocks to be used in the pipeline",name:"blocks"}]});var s=e(y,6),j=n(s);o(j,{name:"from_pretrained",anchor:"diffusers.ModularPipeline.from_pretrained",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L1807",parameters:[{name:"pretrained_model_name_or_path",val:": str | os.PathLike | None"},{name:"trust_remote_code",val:": bool | None = None"},{name:"components_manager",val:": diffusers.modular_pipelines.components_manager.ComponentsManager | None = None"},{name:"collection",val:": str | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.from_pretrained.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code>, optional) — | |
| Path to a pretrained pipeline configuration. It will first try to load config from | |
| <code>modular_model_index.json</code>, then fallback to <code>model_index.json</code> for compatibility with standard | |
| non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it | |
| will be set to None during initialization.`,name:"pretrained_model_name_or_path"},{anchor:"diffusers.ModularPipeline.from_pretrained.trust_remote_code",description:`<strong>trust_remote_code</strong> (<code>bool</code>, 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 <code>pretrained_model_name_or_path</code>`,name:"trust_remote_code"},{anchor:"diffusers.ModularPipeline.from_pretrained.components_manager",description:`<strong>components_manager</strong> (<code>ComponentsManager</code>, optional) — | |
| ComponentsManager instance for managing multiple component cross different pipelines and apply | |
| offloading strategies.`,name:"components_manager"},{anchor:"diffusers.ModularPipeline.from_pretrained.collection",description:"<strong>collection</strong> (<code>str</code>, optional) —`\nCollection name for organizing components in the ComponentsManager.",name:"collection"}]}),i(2),t(s);var d=e(s,2),T=n(d);o(T,{name:"get_component_spec",anchor:"diffusers.ModularPipeline.get_component_spec",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L2252",parameters:[{name:"name",val:": str"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <ul> | |
| <li>a copy of the ComponentSpec object for the given component name</li> | |
| </ul> | |
| `}),t(d);var l=e(d,2),D=n(l);o(D,{name:"load_components",anchor:"diffusers.ModularPipeline.load_components",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L2340",parameters:[{name:"names",val:": list[str] | str | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.load_components.names",description:`<strong>names</strong> — list of component names to load. If None, will load all components with | |
| default_creation_method == “from_pretrained”. If provided as a list or string, will load only the | |
| specified components.`,name:"names"},{anchor:"diffusers.ModularPipeline.load_components.*kwargs",description:`*<strong>*kwargs</strong> — additional kwargs to be passed to <code>from_pretrained()</code>.Can be: | |
| <ul> | |
| <li>a single value to be applied to all components to be loaded, e.g. torch_dtype=torch.bfloat16</li> | |
| <li>a dict, e.g. torch_dtype={“unet”: torch.bfloat16, “default”: torch.float32}</li> | |
| <li>if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. | |
| <code>pretrained_model_name_or_path</code>, <code>variant</code>, <code>revision</code>, etc.</li> | |
| <li>if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. | |
| <code>pretrained_model_name_or_path</code>, <code>variant</code>, <code>revision</code>, etc.</li> | |
| </ul>`,name:"*kwargs"}]}),i(2),t(l);var c=e(l,2),z=n(c);o(z,{name:"register_components",anchor:"diffusers.ModularPipeline.register_components",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L2047",parameters:[{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.register_components.*kwargs",description:`*<strong>*kwargs</strong> — Keyword arguments where keys are component names and values are component objects. | |
| E.g., register_components(unet=unet_model, text_encoder=encoder_model)`,name:"*kwargs"}]}),i(14),t(c);var p=e(c,2),L=n(p);o(L,{name:"save_pretrained",anchor:"diffusers.ModularPipeline.save_pretrained",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L1893",parameters:[{name:"save_directory",val:": str | os.PathLike"},{name:"safe_serialization",val:": bool = True"},{name:"variant",val:": str | None = None"},{name:"max_shard_size",val:": int | str | None = None"},{name:"push_to_hub",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.save_pretrained.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) — | |
| Directory to save the pipeline to. Will be created if it doesn’t exist.`,name:"save_directory"},{anchor:"diffusers.ModularPipeline.save_pretrained.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to save the model using <code>safetensors</code> or the traditional PyTorch way with <code>pickle</code>.`,name:"safe_serialization"},{anchor:"diffusers.ModularPipeline.save_pretrained.variant",description:`<strong>variant</strong> (<code>str</code>, <em>optional</em>) — | |
| If specified, weights are saved in the format <code>pytorch_model.<variant>.bin</code>.`,name:"variant"},{anchor:"diffusers.ModularPipeline.save_pretrained.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, defaults to <code>None</code>) — | |
| The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size | |
| lower than this size. If expressed as a string, needs to be digits followed by a unit (like <code>"5GB"</code>). | |
| If expressed as an integer, the unit is bytes.`,name:"max_shard_size"},{anchor:"diffusers.ModularPipeline.save_pretrained.push_to_hub",description:`<strong>push_to_hub</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to push the pipeline to the Hugging Face model hub after saving it.`,name:"push_to_hub"},{anchor:"diffusers.ModularPipeline.save_pretrained.*kwargs",description:`*<strong>*kwargs</strong> — Additional keyword arguments: | |
| <ul> | |
| <li><code>overwrite_modular_index</code> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>): | |
| When saving a Modular Pipeline, its components in <code>modular_model_index.json</code> may reference repos | |
| different from the destination repo. Setting this to <code>True</code> updates all component references in | |
| <code>modular_model_index.json</code> so they point to the repo specified by <code>repo_id</code>.</li> | |
| <li><code>repo_id</code> (<code>str</code>, <em>optional</em>): | |
| The repository ID to push the pipeline to. Defaults to the last component of <code>save_directory</code>.</li> | |
| <li><code>commit_message</code> (<code>str</code>, <em>optional</em>): | |
| Commit message for the push to hub operation.</li> | |
| <li><code>private</code> (<code>bool</code>, <em>optional</em>): | |
| Whether the repository should be private.</li> | |
| <li><code>create_pr</code> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>): | |
| Whether to create a pull request instead of pushing directly.</li> | |
| <li><code>token</code> (<code>str</code>, <em>optional</em>): | |
| The Hugging Face token to use for authentication.</li> | |
| </ul>`,name:"*kwargs"}]}),i(2),t(p);var m=e(p,2),R=n(m);o(R,{name:"to",anchor:"diffusers.ModularPipeline.to",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L2457",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.to.dtype",description:`<strong>dtype</strong> (<code>torch.dtype</code>, <em>optional</em>) — | |
| Returns a pipeline with the specified | |
| <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.dtype" rel="nofollow"><code>dtype</code></a>`,name:"dtype"},{anchor:"diffusers.ModularPipeline.to.device",description:`<strong>device</strong> (<code>torch.Device</code>, <em>optional</em>) — | |
| Returns a pipeline with the specified | |
| <a href="https://pytorch.org/docs/stable/tensor_attributes.html#torch.device" rel="nofollow"><code>device</code></a>`,name:"device"},{anchor:"diffusers.ModularPipeline.to.silence_dtype_warnings",description:`<strong>silence_dtype_warnings</strong> (<code>str</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to omit warnings if the target <code>dtype</code> is not compatible with the target <code>device</code>.`,name:"silence_dtype_warnings"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The pipeline converted to specified <code>dtype</code> and/or <code>dtype</code>.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/diffusers/pr_13881/en/api/pipelines/overview#diffusers.DiffusionPipeline" | |
| >DiffusionPipeline</a></p> | |
| `}),i(8),t(m);var w=e(m,2),x=n(w);o(x,{name:"update_components",anchor:"diffusers.ModularPipeline.update_components",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/modular_pipelines/modular_pipeline.py#L2259",parameters:[{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModularPipeline.update_components.*kwargs",description:`*<strong>*kwargs</strong> — Component objects or configuration values to update: | |
| <ul> | |
| <li>Component objects: Models loaded with <code>AutoModel.from_pretrained()</code> or <code>ComponentSpec.load()</code> | |
| are automatically tagged with loading information. ConfigMixin objects without weights (e.g., | |
| schedulers, guiders) can be passed directly.</li> | |
| <li>Configuration values: Simple values to update configuration settings | |
| (e.g., <code>requires_safety_checker=False</code>)</li> | |
| </ul>`,name:"*kwargs"}]});var I=e(x,12);G(I,{anchor:"diffusers.ModularPipeline.update_components.example",children:(r,u)=>{var k=Q(),F=e(M(k),2);Z(F,{code:"JTIzJTIwVXBkYXRlJTIwcHJlLXRyYWluZWQlMjBtb2RlbCUwQXBpcGVsaW5lLnVwZGF0ZV9jb21wb25lbnRzKHVuZXQlM0RuZXdfdW5ldF9tb2RlbCUyQyUyMHRleHRfZW5jb2RlciUzRG5ld190ZXh0X2VuY29kZXIpJTBBJTBBJTIzJTIwVXBkYXRlJTIwY29uZmlndXJhdGlvbiUyMHZhbHVlcyUwQXBpcGVsaW5lLnVwZGF0ZV9jb21wb25lbnRzKHJlcXVpcmVzX3NhZmV0eV9jaGVja2VyJTNERmFsc2Up",highlighted:`<span class="hljs-comment"># Update pre-trained model</span> | |
| pipeline.update_components(unet=new_unet_model, text_encoder=new_text_encoder) | |
| <span class="hljs-comment"># Update configuration values</span> | |
| pipeline.update_components(requires_safety_checker=<span class="hljs-literal">False</span>)`,lang:"python",wrap:!1}),h(r,k)},$$slots:{default:!0}}),i(4),t(w),t(a);var V=e(a,2);H(V,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/modular_diffusers/pipeline.md"}),i(2),h(N,g),q()}export{oe as component}; | |
Xet Storage Details
- Size:
- 19 kB
- Xet hash:
- ccf0ef2ff499a50a0f215fbae3efedc4108359bd491ff6187302dc7a49dcb295
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.