Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Quickstart","local":"quickstart","sections":[{"title":"ModularPipelineBlocks","local":"modularpipelineblocks","sections":[],"depth":2},{"title":"Pipeline and block states","local":"pipeline-and-block-states","sections":[],"depth":2},{"title":"Customizing blocks","local":"customizing-blocks","sections":[{"title":"prepare_latents","local":"preparelatents","sections":[],"depth":3},{"title":"denoise","local":"denoise","sections":[],"depth":3}],"depth":2},{"title":"Assembling the blocks","local":"assembling-the-blocks","sections":[],"depth":2},{"title":"ModularPipeline","local":"modularpipeline","sections":[],"depth":2},{"title":"Adding workflows","local":"adding-workflows","sections":[{"title":"IP-Adapter","local":"ip-adapter","sections":[],"depth":3},{"title":"ControlNet","local":"controlnet","sections":[],"depth":3},{"title":"AutoPipelineBlocks","local":"autopipelineblocks","sections":[],"depth":3}],"depth":2},{"title":"Share","local":"share","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/diffusers/pr_12403/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/entry/start.33959e67.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/scheduler.8c3d61f6.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/singletons.46d5608c.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/index.0997d446.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/paths.0dc9c45f.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/entry/app.87796ad1.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/index.da70eac4.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/nodes/0.9198881c.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/nodes/243.6efd1ead.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/CodeBlock.a9c4becf.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_12403/en/_app/immutable/chunks/getInferenceSnippets.ea1775db.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Quickstart","local":"quickstart","sections":[{"title":"ModularPipelineBlocks","local":"modularpipelineblocks","sections":[],"depth":2},{"title":"Pipeline and block states","local":"pipeline-and-block-states","sections":[],"depth":2},{"title":"Customizing blocks","local":"customizing-blocks","sections":[{"title":"prepare_latents","local":"preparelatents","sections":[],"depth":3},{"title":"denoise","local":"denoise","sections":[],"depth":3}],"depth":2},{"title":"Assembling the blocks","local":"assembling-the-blocks","sections":[],"depth":2},{"title":"ModularPipeline","local":"modularpipeline","sections":[],"depth":2},{"title":"Adding workflows","local":"adding-workflows","sections":[{"title":"IP-Adapter","local":"ip-adapter","sections":[],"depth":3},{"title":"ControlNet","local":"controlnet","sections":[],"depth":3},{"title":"AutoPipelineBlocks","local":"autopipelineblocks","sections":[],"depth":3}],"depth":2},{"title":"Share","local":"share","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="quickstart" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#quickstart"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Quickstart</span></h1> <p data-svelte-h="svelte-5o1nme">Modular Diffusers is a framework for quickly building flexible and customizable pipelines. At the core of Modular Diffusers are <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> that can be combined with other blocks to adapt to new workflows. The blocks are converted into a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>, a friendly user-facing interface developers can use.</p> <p data-svelte-h="svelte-14bi1ah">This doc will show you how to implement a <a href="https://differential-diffusion.github.io/" rel="nofollow">Differential Diffusion</a> pipeline with the modular framework.</p> <h2 class="relative group"><a id="modularpipelineblocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#modularpipelineblocks"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ModularPipelineBlocks</span></h2> <p data-svelte-h="svelte-nuujw6"><a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> are <em>definitions</em> that specify the components, inputs, outputs, and computation logic for a single step in a pipeline. There are four types of blocks.</p> <ul data-svelte-h="svelte-t662oo"><li><a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> is the most basic block for a single step.</li> <li><code>SequentialPipelineBlocks</code> is a multi-block that composes other blocks linearly. The outputs of one block are the inputs to the next block.</li> <li><code>LoopSequentialPipelineBlocks</code> is a multi-block that runs iteratively and is designed for iterative workflows.</li> <li><code>AutoPipelineBlocks</code> is a collection of blocks for different workflows and it selects which block to run based on the input. It is designed to conveniently package multiple workflows into a single pipeline.</li></ul> <p data-svelte-h="svelte-7tdtn5"><a href="https://differential-diffusion.github.io/" rel="nofollow">Differential Diffusion</a> is an image-to-image workflow. Start with the <code>IMAGE2IMAGE_BLOCKS</code> preset, a collection of <code>ModularPipelineBlocks</code> for image-to-image generation.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers.modular_pipelines.stable_diffusion_xl <span class="hljs-keyword">import</span> IMAGE2IMAGE_BLOCKS | |
| IMAGE2IMAGE_BLOCKS = InsertableDict([ | |
| (<span class="hljs-string">"text_encoder"</span>, StableDiffusionXLTextEncoderStep), | |
| (<span class="hljs-string">"image_encoder"</span>, StableDiffusionXLVaeEncoderStep), | |
| (<span class="hljs-string">"input"</span>, StableDiffusionXLInputStep), | |
| (<span class="hljs-string">"set_timesteps"</span>, StableDiffusionXLImg2ImgSetTimestepsStep), | |
| (<span class="hljs-string">"prepare_latents"</span>, StableDiffusionXLImg2ImgPrepareLatentsStep), | |
| (<span class="hljs-string">"prepare_add_cond"</span>, StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep), | |
| (<span class="hljs-string">"denoise"</span>, StableDiffusionXLDenoiseStep), | |
| (<span class="hljs-string">"decode"</span>, StableDiffusionXLDecodeStep) | |
| ])<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="pipeline-and-block-states" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#pipeline-and-block-states"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Pipeline and block states</span></h2> <p data-svelte-h="svelte-1hrx77z">Modular Diffusers uses <em>state</em> to communicate data between blocks. There are two types of states.</p> <ul data-svelte-h="svelte-hgqjo0"><li><code>PipelineState</code> is a global state that can be used to track all inputs and outputs across all blocks.</li> <li><code>BlockState</code> is a local view of relevant variables from <code>PipelineState</code> for an individual block.</li></ul> <h2 class="relative group"><a id="customizing-blocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#customizing-blocks"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Customizing blocks</span></h2> <p data-svelte-h="svelte-16tz7j4"><a href="https://differential-diffusion.github.io/" rel="nofollow">Differential Diffusion</a> differs from standard image-to-image in its <code>prepare_latents</code> and <code>denoise</code> blocks. All the other blocks can be reused, but you’ll need to modify these two.</p> <p data-svelte-h="svelte-pmw538">Create placeholder <code>ModularPipelineBlocks</code> for <code>prepare_latents</code> and <code>denoise</code> by copying and modifying the existing ones.</p> <p data-svelte-h="svelte-1qke84t">Print the <code>denoise</code> block to see that it is composed of <code>LoopSequentialPipelineBlocks</code> with three sub-blocks, <code>before_denoiser</code>, <code>denoiser</code>, and <code>after_denoiser</code>. Only the <code>before_denoiser</code> sub-block needs to be modified to prepare the latent input for the denoiser based on the change map.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->denoise_blocks = IMAGE2IMAGE_BLOCKS[<span class="hljs-string">"denoise"</span>]() | |
| <span class="hljs-built_in">print</span>(denoise_blocks)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-g4vtz4">Replace the <code>StableDiffusionXLLoopBeforeDenoiser</code> sub-block with the new <code>SDXLDiffDiffLoopBeforeDenoiser</code> block.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Copy existing blocks as placeholders</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">SDXLDiffDiffPrepareLatentsStep</span>(<span class="hljs-title class_ inherited__">ModularPipelineBlocks</span>): | |
| <span class="hljs-string">"""Copied from StableDiffusionXLImg2ImgPrepareLatentsStep - will modify later"""</span> | |
| <span class="hljs-comment"># ... same implementation as StableDiffusionXLImg2ImgPrepareLatentsStep</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">SDXLDiffDiffDenoiseStep</span>(<span class="hljs-title class_ inherited__">StableDiffusionXLDenoiseLoopWrapper</span>): | |
| block_classes = [SDXLDiffDiffLoopBeforeDenoiser, StableDiffusionXLLoopDenoiser, StableDiffusionXLLoopAfterDenoiser] | |
| block_names = [<span class="hljs-string">"before_denoiser"</span>, <span class="hljs-string">"denoiser"</span>, <span class="hljs-string">"after_denoiser"</span>]<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="preparelatents" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#preparelatents"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>prepare_latents</span></h3> <p data-svelte-h="svelte-1hnij81">The <code>prepare_latents</code> block requires the following changes.</p> <ul data-svelte-h="svelte-wu0sp3"><li>a processor to process the change map</li> <li>a new <code>inputs</code> to accept the user-provided change map, <code>timestep</code> for precomputing all the latents and <code>num_inference_steps</code> to create the mask for updating the image regions</li> <li>update the computation in the <code>__call__</code> method for processing the change map and creating the masks, and storing it in the <code>BlockState</code></li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->class SDXLDiffDiffPrepareLatentsStep(ModularPipelineBlocks): | |
| @property | |
| def expected_components(self) -> List[ComponentSpec]: | |
| return [ | |
| ComponentSpec("vae", AutoencoderKL), | |
| ComponentSpec("scheduler", EulerDiscreteScheduler), | |
| <span class="hljs-addition">+ ComponentSpec("mask_processor", VaeImageProcessor, config=FrozenDict({"do_normalize": False, "do_convert_grayscale": True}))</span> | |
| ] | |
| @property | |
| def inputs(self) -> List[Tuple[str, Any]]: | |
| return [ | |
| InputParam("generator"), | |
| <span class="hljs-addition">+ InputParam("diffdiff_map", required=True),</span> | |
| <span class="hljs-deletion">- InputParam("latent_timestep", required=True, type_hint=torch.Tensor),</span> | |
| <span class="hljs-addition">+ InputParam("timesteps", type_hint=torch.Tensor),</span> | |
| <span class="hljs-addition">+ InputParam("num_inference_steps", type_hint=int),</span> | |
| ] | |
| @property | |
| def intermediate_outputs(self) -> List[OutputParam]: | |
| return [ | |
| <span class="hljs-addition">+ OutputParam("original_latents", type_hint=torch.Tensor),</span> | |
| <span class="hljs-addition">+ OutputParam("diffdiff_masks", type_hint=torch.Tensor),</span> | |
| ] | |
| def __call__(self, components, state: PipelineState): | |
| # ... existing logic ... | |
| <span class="hljs-addition">+ # Process change map and create masks</span> | |
| <span class="hljs-addition">+ diffdiff_map = components.mask_processor.preprocess(block_state.diffdiff_map, height=latent_height, width=latent_width)</span> | |
| <span class="hljs-addition">+ thresholds = torch.arange(block_state.num_inference_steps, dtype=diffdiff_map.dtype) / block_state.num_inference_steps</span> | |
| <span class="hljs-addition">+ block_state.diffdiff_masks = diffdiff_map > (thresholds + (block_state.denoising_start or 0))</span> | |
| <span class="hljs-addition">+ block_state.original_latents = block_state.latents</span><!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="denoise" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#denoise"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>denoise</span></h3> <p data-svelte-h="svelte-1lriej4">The <code>before_denoiser</code> sub-block requires the following changes.</p> <ul data-svelte-h="svelte-k274di"><li>a new <code>inputs</code> to accept a <code>denoising_start</code> parameter, <code>original_latents</code> and <code>diffdiff_masks</code> from the <code>prepare_latents</code> block</li> <li>update the computation in the <code>__call__</code> method for applying Differential Diffusion</li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->class SDXLDiffDiffLoopBeforeDenoiser(ModularPipelineBlocks): | |
| @property | |
| def description(self) -> str: | |
| return ( | |
| "Step within the denoising loop for differential diffusion that prepare the latent input for the denoiser" | |
| ) | |
| @property | |
| def inputs(self) -> List[str]: | |
| return [ | |
| InputParam("latents", required=True, type_hint=torch.Tensor), | |
| <span class="hljs-addition">+ InputParam("denoising_start"),</span> | |
| <span class="hljs-addition">+ InputParam("original_latents", type_hint=torch.Tensor),</span> | |
| <span class="hljs-addition">+ InputParam("diffdiff_masks", type_hint=torch.Tensor),</span> | |
| ] | |
| def __call__(self, components, block_state, i, t): | |
| <span class="hljs-addition">+ # Apply differential diffusion logic</span> | |
| <span class="hljs-addition">+ if i == 0 and block_state.denoising_start is None:</span> | |
| <span class="hljs-addition">+ block_state.latents = block_state.original_latents[:1]</span> | |
| <span class="hljs-addition">+ else:</span> | |
| <span class="hljs-addition">+ block_state.mask = block_state.diffdiff_masks[i].unsqueeze(0).unsqueeze(1)</span> | |
| <span class="hljs-addition">+ block_state.latents = block_state.original_latents[i] * block_state.mask + block_state.latents * (1 - block_state.mask)</span> | |
| # ... rest of existing logic ...<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="assembling-the-blocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#assembling-the-blocks"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Assembling the blocks</span></h2> <p data-svelte-h="svelte-gzxjs4">You should have all the blocks you need at this point to create a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>.</p> <p data-svelte-h="svelte-bcrjsa">Copy the existing <code>IMAGE2IMAGE_BLOCKS</code> preset and for the <code>set_timesteps</code> block, use the <code>set_timesteps</code> from the <code>TEXT2IMAGE_BLOCKS</code> because Differential Diffusion doesn’t require a <code>strength</code> parameter.</p> <p data-svelte-h="svelte-1qdwaia">Set the <code>prepare_latents</code> and <code>denoise</code> blocks to the <code>SDXLDiffDiffPrepareLatentsStep</code> and <code>SDXLDiffDiffDenoiseStep</code> blocks you just modified.</p> <p data-svelte-h="svelte-c6bj14">Call <code>SequentialPipelineBlocks.from_blocks_dict</code> on the blocks to create a <code>SequentialPipelineBlocks</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->DIFFDIFF_BLOCKS = IMAGE2IMAGE_BLOCKS.copy() | |
| DIFFDIFF_BLOCKS[<span class="hljs-string">"set_timesteps"</span>] = TEXT2IMAGE_BLOCKS[<span class="hljs-string">"set_timesteps"</span>] | |
| DIFFDIFF_BLOCKS[<span class="hljs-string">"prepare_latents"</span>] = SDXLDiffDiffPrepareLatentsStep | |
| DIFFDIFF_BLOCKS[<span class="hljs-string">"denoise"</span>] = SDXLDiffDiffDenoiseStep | |
| dd_blocks = SequentialPipelineBlocks.from_blocks_dict(DIFFDIFF_BLOCKS) | |
| <span class="hljs-built_in">print</span>(dd_blocks)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="modularpipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#modularpipeline"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ModularPipeline</span></h2> <p data-svelte-h="svelte-1bep9rb">Convert the <code>SequentialPipelineBlocks</code> into a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> with the <code>ModularPipeline.init_pipeline</code> method. This initializes the expected components to load from a <code>modular_model_index.json</code> file. Explicitly load the components by calling <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">ModularPipeline.load_components()</a>.</p> <p data-svelte-h="svelte-1bgpkuf">It is a good idea to initialize the <code>ComponentManager</code> with the pipeline to help manage the different components. Once you call <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>, the components are registered to the <code>ComponentManager</code> and can be shared between workflows. The example below uses the <code>collection</code> argument to assign the components a <code>"diffdiff"</code> label for better organization.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> ComponentsManager | |
| components = ComponentManager() | |
| dd_pipeline = dd_blocks.init_pipeline(<span class="hljs-string">"YiYiXu/modular-demo-auto"</span>, components_manager=components, collection=<span class="hljs-string">"diffdiff"</span>) | |
| dd_pipeline.load_default_componenets(torch_dtype=torch.float16) | |
| dd_pipeline.to(<span class="hljs-string">"cuda"</span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="adding-workflows" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#adding-workflows"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Adding workflows</span></h2> <p data-svelte-h="svelte-1cxd8c4">Other workflows can be added to the <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> to support additional features without rewriting the entire pipeline from scratch.</p> <p data-svelte-h="svelte-denp3n">This section demonstrates how to add an IP-Adapter or ControlNet.</p> <h3 class="relative group"><a id="ip-adapter" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#ip-adapter"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>IP-Adapter</span></h3> <p data-svelte-h="svelte-1mrw5mx">Stable Diffusion XL already has a preset IP-Adapter block that you can use and doesn’t require any changes to the existing Differential Diffusion pipeline.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers.modular_pipelines.stable_diffusion_xl.encoders <span class="hljs-keyword">import</span> StableDiffusionXLAutoIPAdapterStep | |
| ip_adapter_block = StableDiffusionXLAutoIPAdapterStep()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-qfuuot">Use the <code>sub_blocks.insert</code> method to insert it into the <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>. The example below inserts the <code>ip_adapter_block</code> at position <code>0</code>. Print the pipeline to see that the <code>ip_adapter_block</code> is added and it requires an <code>ip_adapter_image</code>. This also added two components to the pipeline, the <code>image_encoder</code> and <code>feature_extractor</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->dd_blocks.sub_blocks.insert(<span class="hljs-string">"ip_adapter"</span>, ip_adapter_block, <span class="hljs-number">0</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1dxt1h0">Call <code>~ModularPipeline.init_pipeline</code> to initialize a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> and use <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> to load the model components. Load and set the IP-Adapter to run the pipeline.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->dd_pipeline = dd_blocks.init_pipeline(<span class="hljs-string">"YiYiXu/modular-demo-auto"</span>, collection=<span class="hljs-string">"diffdiff"</span>) | |
| dd_pipeline.load_components(torch_dtype=torch.float16) | |
| dd_pipeline.loader.load_ip_adapter(<span class="hljs-string">"h94/IP-Adapter"</span>, subfolder=<span class="hljs-string">"sdxl_models"</span>, weight_name=<span class="hljs-string">"ip-adapter_sdxl.bin"</span>) | |
| dd_pipeline.loader.set_ip_adapter_scale(<span class="hljs-number">0.6</span>) | |
| dd_pipeline = dd_pipeline.to(device) | |
| ip_adapter_image = load_image(<span class="hljs-string">"https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_orange.jpeg"</span>) | |
| image = load_image(<span class="hljs-string">"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true"</span>) | |
| mask = load_image(<span class="hljs-string">"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true"</span>) | |
| prompt = <span class="hljs-string">"a green pear"</span> | |
| negative_prompt = <span class="hljs-string">"blurry"</span> | |
| generator = torch.Generator(device=device).manual_seed(<span class="hljs-number">42</span>) | |
| image = dd_pipeline( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| num_inference_steps=<span class="hljs-number">25</span>, | |
| generator=generator, | |
| ip_adapter_image=ip_adapter_image, | |
| diffdiff_map=mask, | |
| image=image, | |
| output=<span class="hljs-string">"images"</span> | |
| )[<span class="hljs-number">0</span>]<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="controlnet" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#controlnet"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ControlNet</span></h3> <p data-svelte-h="svelte-wr3jw6">Stable Diffusion XL already has a preset ControlNet block that can readily be used.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers.modular_pipelines.stable_diffusion_xl.modular_blocks <span class="hljs-keyword">import</span> StableDiffusionXLAutoControlNetInputStep | |
| control_input_block = StableDiffusionXLAutoControlNetInputStep()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-czmnsx">However, it requires modifying the <code>denoise</code> block because that’s where the ControlNet injects the control information into the UNet.</p> <p data-svelte-h="svelte-mbulqa">Modify the <code>denoise</code> block by replacing the <code>StableDiffusionXLLoopDenoiser</code> sub-block with the <code>StableDiffusionXLControlNetLoopDenoiser</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">class</span> <span class="hljs-title class_">SDXLDiffDiffControlNetDenoiseStep</span>(<span class="hljs-title class_ inherited__">StableDiffusionXLDenoiseLoopWrapper</span>): | |
| block_classes = [SDXLDiffDiffLoopBeforeDenoiser, StableDiffusionXLControlNetLoopDenoiser, StableDiffusionXLDenoiseLoopAfterDenoiser] | |
| block_names = [<span class="hljs-string">"before_denoiser"</span>, <span class="hljs-string">"denoiser"</span>, <span class="hljs-string">"after_denoiser"</span>] | |
| controlnet_denoise_block = SDXLDiffDiffControlNetDenoiseStep()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1y4cujc">Insert the <code>controlnet_input</code> block and replace the <code>denoise</code> block with the new <code>controlnet_denoise_block</code>. Initialize a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> and <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> into it.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->dd_blocks.sub_blocks.insert(<span class="hljs-string">"controlnet_input"</span>, control_input_block, <span class="hljs-number">7</span>) | |
| dd_blocks.sub_blocks[<span class="hljs-string">"denoise"</span>] = controlnet_denoise_block | |
| dd_pipeline = dd_blocks.init_pipeline(<span class="hljs-string">"YiYiXu/modular-demo-auto"</span>, collection=<span class="hljs-string">"diffdiff"</span>) | |
| dd_pipeline.load_components(torch_dtype=torch.float16) | |
| dd_pipeline = dd_pipeline.to(device) | |
| control_image = load_image(<span class="hljs-string">"https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_tomato_canny.jpeg"</span>) | |
| image = load_image(<span class="hljs-string">"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true"</span>) | |
| mask = load_image(<span class="hljs-string">"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true"</span>) | |
| prompt = <span class="hljs-string">"a green pear"</span> | |
| negative_prompt = <span class="hljs-string">"blurry"</span> | |
| generator = torch.Generator(device=device).manual_seed(<span class="hljs-number">42</span>) | |
| image = dd_pipeline( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| num_inference_steps=<span class="hljs-number">25</span>, | |
| generator=generator, | |
| control_image=control_image, | |
| controlnet_conditioning_scale=<span class="hljs-number">0.5</span>, | |
| diffdiff_map=mask, | |
| image=image, | |
| output=<span class="hljs-string">"images"</span> | |
| )[<span class="hljs-number">0</span>]<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="autopipelineblocks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autopipelineblocks"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoPipelineBlocks</span></h3> <p data-svelte-h="svelte-1s3uk3t">The Differential Diffusion, IP-Adapter, and ControlNet workflows can be bundled into a single <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> by using <code>AutoPipelineBlocks</code>. This allows automatically selecting which sub-blocks to run based on the inputs like <code>control_image</code> or <code>ip_adapter_image</code>. If none of these inputs are passed, then it defaults to the Differential Diffusion.</p> <p data-svelte-h="svelte-rehsh7">Use <code>block_trigger_inputs</code> to only run the <code>SDXLDiffDiffControlNetDenoiseStep</code> block if a <code>control_image</code> input is provided. Otherwise, the <code>SDXLDiffDiffDenoiseStep</code> is used.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">class</span> <span class="hljs-title class_">SDXLDiffDiffAutoDenoiseStep</span>(<span class="hljs-title class_ inherited__">AutoPipelineBlocks</span>): | |
| block_classes = [SDXLDiffDiffControlNetDenoiseStep, SDXLDiffDiffDenoiseStep] | |
| block_names = [<span class="hljs-string">"controlnet_denoise"</span>, <span class="hljs-string">"denoise"</span>] | |
| block_trigger_inputs = [<span class="hljs-string">"controlnet_cond"</span>, <span class="hljs-literal">None</span>]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-o3hbbv">Add the <code>ip_adapter</code> and <code>controlnet_input</code> blocks.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->DIFFDIFF_AUTO_BLOCKS = IMAGE2IMAGE_BLOCKS.copy() | |
| DIFFDIFF_AUTO_BLOCKS[<span class="hljs-string">"prepare_latents"</span>] = SDXLDiffDiffPrepareLatentsStep | |
| DIFFDIFF_AUTO_BLOCKS[<span class="hljs-string">"set_timesteps"</span>] = TEXT2IMAGE_BLOCKS[<span class="hljs-string">"set_timesteps"</span>] | |
| DIFFDIFF_AUTO_BLOCKS[<span class="hljs-string">"denoise"</span>] = SDXLDiffDiffAutoDenoiseStep | |
| DIFFDIFF_AUTO_BLOCKS.insert(<span class="hljs-string">"ip_adapter"</span>, StableDiffusionXLAutoIPAdapterStep, <span class="hljs-number">0</span>) | |
| DIFFDIFF_AUTO_BLOCKS.insert(<span class="hljs-string">"controlnet_input"</span>,StableDiffusionXLControlNetAutoInput, <span class="hljs-number">7</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-w2xqck">Call <code>SequentialPipelineBlocks.from_blocks_dict</code> to create a <code>SequentialPipelineBlocks</code> and create a <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> and load in the model components to run.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->dd_auto_blocks = SequentialPipelineBlocks.from_blocks_dict(DIFFDIFF_AUTO_BLOCKS) | |
| dd_pipeline = dd_auto_blocks.init_pipeline(<span class="hljs-string">"YiYiXu/modular-demo-auto"</span>, collection=<span class="hljs-string">"diffdiff"</span>) | |
| dd_pipeline.load_components(torch_dtype=torch.float16)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="share" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#share"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Share</span></h2> <p data-svelte-h="svelte-14b0ysn">Add your <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> to the Hub with <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.save_pretrained">save_pretrained()</a> and set <code>push_to_hub</code> argument to <code>True</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->dd_pipeline.save_pretrained(<span class="hljs-string">"YiYiXu/test_modular_doc"</span>, push_to_hub=<span class="hljs-literal">True</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1hjtsha">Other users can load the <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> with <a href="/docs/diffusers/pr_12403/en/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager | |
| components = ComponentsManager() | |
| diffdiff_pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"YiYiXu/modular-diffdiff-0704"</span>, trust_remote_code=<span class="hljs-literal">True</span>, components_manager=components, collection=<span class="hljs-string">"diffdiff"</span>) | |
| diffdiff_pipeline.load_components(torch_dtype=torch.float16)<!-- HTML_TAG_END --></pre></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/modular_diffusers/quickstart.md" target="_blank"><span data-svelte-h="svelte-1kd6by1"><</span> <span data-svelte-h="svelte-x0xyl0">></span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_g87enx = { | |
| assets: "/docs/diffusers/pr_12403/en", | |
| base: "/docs/diffusers/pr_12403/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/diffusers/pr_12403/en/_app/immutable/entry/start.33959e67.js"), | |
| import("/docs/diffusers/pr_12403/en/_app/immutable/entry/app.87796ad1.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 243], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 67 kB
- Xet hash:
- b3c30ca3821fe36edcedb6e75e92646657b859a4538a7a2d1027887606f33f8a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.