import{S as Ks,i as Js,s as Qs,e as s,k as f,w,t as o,M as Ws,c as n,d as i,m as d,a as r,x as v,h as l,b as u,G as t,g as p,y as $,q as g,o as E,B as b,v as Xs}from"../../chunks/vendor-hf-doc-builder.js";import{T as Vs}from"../../chunks/Tip-hf-doc-builder.js";import{I as Ft}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as J}from"../../chunks/CodeBlock-hf-doc-builder.js";function Zs(Te){let c,T,h,y,C;return{c(){c=s("p"),T=o("\u{1F4A1} Take a look at GitHub Issue "),h=s("a"),y=o("#841"),C=o(" for more context about why we\u2019re adding community pipelines to help everyone easily share their work without being slowed down."),this.h()},l(m){c=n(m,"P",{});var _=r(c);T=l(_,"\u{1F4A1} Take a look at GitHub Issue "),h=n(_,"A",{href:!0,rel:!0});var H=r(h);y=l(H,"#841"),H.forEach(i),C=l(_," for more context about why we\u2019re adding community pipelines to help everyone easily share their work without being slowed down."),_.forEach(i),this.h()},h(){u(h,"href","https://github.com/huggingface/diffusers/issues/841"),u(h,"rel","nofollow")},m(m,_){p(m,c,_),t(c,T),t(c,h),t(h,y),t(c,C)},d(m){m&&i(c)}}}function en(Te){let c,T,h,y,C;return{c(){c=s("p"),T=o("\u{1F4A1} You can use whatever package you want in your community pipeline file - as long as the user has it installed, everything will work fine. Make sure you have one and only one pipeline class that inherits from "),h=s("code"),y=o("DiffusionPipeline"),C=o(" because this is automatically detected.")},l(m){c=n(m,"P",{});var _=r(c);T=l(_,"\u{1F4A1} You can use whatever package you want in your community pipeline file - as long as the user has it installed, everything will work fine. Make sure you have one and only one pipeline class that inherits from "),h=n(_,"CODE",{});var H=r(h);y=l(H,"DiffusionPipeline"),H.forEach(i),C=l(_," because this is automatically detected."),_.forEach(i)},m(m,_){p(m,c,_),t(c,T),t(c,h),t(h,y),t(c,C)},d(m){m&&i(c)}}}function tn(Te){let c,T,h,y,C,m,_,H,Hi,Lt,Q,Ut,I,Ii,Oe,Si,xi,Ye,Ai,qi,Mt,W,Ni,Ve,Fi,Li,zt,U,X,Ke,ae,Ui,Je,Mi,Bt,P,zi,Qe,Bi,Gi,He,Ri,Yi,We,Vi,Ki,Xe,Ji,Qi,Gt,pe,Rt,D,Wi,Ze,Xi,Zi,et,eo,to,Ie,io,oo,tt,lo,so,Yt,fe,Vt,Z,no,it,ro,ao,Kt,M,ee,ot,de,po,lt,fo,Jt,k,uo,st,co,ho,nt,mo,_o,rt,yo,wo,at,vo,$o,Qt,ue,Wt,S,go,pt,Eo,bo,ft,Po,Do,Xt,ce,Zt,te,ko,he,dt,jo,Co,ei,me,ti,z,ie,ut,_e,To,ct,Oo,ii,O,Ho,ye,Io,So,ht,xo,Ao,we,qo,No,oi,x,Fo,mt,Lo,Uo,_t,Mo,zo,li,ve,si,j,Bo,yt,Go,Ro,$e,Yo,Vo,wt,Ko,Jo,vt,Qo,Wo,ni,ge,ri,Se,Xo,ai,oe,$t,B,pi,Zo,gt,el,tl,Et,il,ol,G,R,bt,ll,sl,Pt,nl,rl,Dt,al,pl,Y,kt,fl,dl,jt,ul,cl,Ct,hl,ml,V,Tt,_l,yl,Ot,wl,vl,Ht,$l,fi,le,di,K,se,It,Ee,gl,St,El,ui,ne,bl,xe,Pl,Dl,ci,A,be,kl,xt,jl,Cl,Tl,Pe,Ol,At,Hl,Il,Sl,De,xl,qt,Al,ql,hi,Ae,Nl,mi,ke,_i,qe,Fl,yi,je,wi;return m=new Ft({}),Q=new Vs({props:{$$slots:{default:[Zs]},$$scope:{ctx:Te}}}),ae=new Ft({}),pe=new J({props:{code:`from diffusers import DiffusionPipeline
import torch


class UnetSchedulerOneForwardPipeline(DiffusionPipeline):
    def __init__(self, unet, scheduler):
        super().__init__()`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">import</span> torch


<span class="hljs-keyword">class</span> <span class="hljs-title class_">UnetSchedulerOneForwardPipeline</span>(<span class="hljs-title class_ inherited__">DiffusionPipeline</span>):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, unet, scheduler</span>):
        <span class="hljs-built_in">super</span>().__init__()`}}),fe=new J({props:{code:`  from diffusers import DiffusionPipeline
  import torch

  class UnetSchedulerOneForwardPipeline(DiffusionPipeline):
      def __init__(self, unet, scheduler):
          super().__init__()

+         self.register_modules(unet=unet, scheduler=scheduler)`,highlighted:`  from diffusers import DiffusionPipeline
  import torch

  class UnetSchedulerOneForwardPipeline(DiffusionPipeline):
      def __init__(self, unet, scheduler):
          super().__init__()

<span class="hljs-addition">+         self.register_modules(unet=unet, scheduler=scheduler)</span>`}}),de=new Ft({}),ue=new J({props:{code:`  from diffusers import DiffusionPipeline
  import torch


  class UnetSchedulerOneForwardPipeline(DiffusionPipeline):
      def __init__(self, unet, scheduler):
          super().__init__()

          self.register_modules(unet=unet, scheduler=scheduler)

+     def __call__(self):
+         image = torch.randn(
+             (1, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size),
+         )
+         timestep = 1

+         model_output = self.unet(image, timestep).sample
+         scheduler_output = self.scheduler.step(model_output, timestep, image).prev_sample

+         return scheduler_output`,highlighted:`  from diffusers import DiffusionPipeline
  import torch


  class UnetSchedulerOneForwardPipeline(DiffusionPipeline):
      def __init__(self, unet, scheduler):
          super().__init__()

          self.register_modules(unet=unet, scheduler=scheduler)

<span class="hljs-addition">+     def __call__(self):</span>
<span class="hljs-addition">+         image = torch.randn(</span>
<span class="hljs-addition">+             (1, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size),</span>
<span class="hljs-addition">+         )</span>
<span class="hljs-addition">+         timestep = 1</span>

<span class="hljs-addition">+         model_output = self.unet(image, timestep).sample</span>
<span class="hljs-addition">+         scheduler_output = self.scheduler.step(model_output, timestep, image).prev_sample</span>

<span class="hljs-addition">+         return scheduler_output</span>`}}),ce=new J({props:{code:`from diffusers import DDPMScheduler, UNet2DModel

scheduler = DDPMScheduler()
unet = UNet2DModel()

pipeline = UnetSchedulerOneForwardPipeline(unet=unet, scheduler=scheduler)

output = pipeline()`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDPMScheduler, UNet2DModel

scheduler = DDPMScheduler()
unet = UNet2DModel()

pipeline = UnetSchedulerOneForwardPipeline(unet=unet, scheduler=scheduler)

output = pipeline()`}}),me=new J({props:{code:`pipeline = UnetSchedulerOneForwardPipeline.from_pretrained("google/ddpm-cifar10-32")

output = pipeline()`,highlighted:`pipeline = UnetSchedulerOneForwardPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>)

output = pipeline()`}}),_e=new Ft({}),ve=new J({props:{code:`from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("google/ddpm-cifar10-32", custom_pipeline="one_step_unet")
pipe()`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, custom_pipeline=<span class="hljs-string">&quot;one_step_unet&quot;</span>)
pipe()`}}),ge=new J({props:{code:`from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained("google/ddpm-cifar10-32", custom_pipeline="stevhliu/one_step_unet")`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, custom_pipeline=<span class="hljs-string">&quot;stevhliu/one_step_unet&quot;</span>)`}}),le=new Vs({props:{$$slots:{default:[en]},$$scope:{ctx:Te}}}),Ee=new Ft({}),ke=new J({props:{code:`from diffusers import DiffusionPipeline
from transformers import CLIPFeatureExtractor, CLIPModel

model_id = "CompVis/stable-diffusion-v1-4"
clip_model_id = "laion/CLIP-ViT-B-32-laion2B-s34B-b79K"

feature_extractor = CLIPFeatureExtractor.from_pretrained(clip_model_id)
clip_model = CLIPModel.from_pretrained(clip_model_id, torch_dtype=torch.float16)

pipeline = DiffusionPipeline.from_pretrained(
    model_id,
    custom_pipeline="clip_guided_stable_diffusion",
    clip_model=clip_model,
    feature_extractor=feature_extractor,
    scheduler=scheduler,
    torch_dtype=torch.float16,
)`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CLIPFeatureExtractor, CLIPModel

model_id = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
clip_model_id = <span class="hljs-string">&quot;laion/CLIP-ViT-B-32-laion2B-s34B-b79K&quot;</span>

feature_extractor = CLIPFeatureExtractor.from_pretrained(clip_model_id)
clip_model = CLIPModel.from_pretrained(clip_model_id, torch_dtype=torch.float16)

pipeline = DiffusionPipeline.from_pretrained(
    model_id,
    custom_pipeline=<span class="hljs-string">&quot;clip_guided_stable_diffusion&quot;</span>,
    clip_model=clip_model,
    feature_extractor=feature_extractor,
    scheduler=scheduler,
    torch_dtype=torch.float16,
)`}}),je=new J({props:{code:`# 2. Load the pipeline class, if using custom module then load it from the hub
# if we load from explicit class, let's use it
if custom_pipeline is not None:
    pipeline_class = get_class_from_dynamic_module(
        custom_pipeline, module_file=CUSTOM_PIPELINE_FILE_NAME, cache_dir=custom_pipeline
    )
elif cls != DiffusionPipeline:
    pipeline_class = cls
else:
    diffusers_module = importlib.import_module(cls.__module__.split(".")[0])
    pipeline_class = getattr(diffusers_module, config_dict["_class_name"])`,highlighted:`<span class="hljs-comment"># 2. Load the pipeline class, if using custom module then load it from the hub</span>
<span class="hljs-comment"># if we load from explicit class, let&#x27;s use it</span>
<span class="hljs-keyword">if</span> custom_pipeline <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
    pipeline_class = get_class_from_dynamic_module(
        custom_pipeline, module_file=CUSTOM_PIPELINE_FILE_NAME, cache_dir=custom_pipeline
    )
<span class="hljs-keyword">elif</span> cls != DiffusionPipeline:
    pipeline_class = cls
<span class="hljs-keyword">else</span>:
    diffusers_module = importlib.import_module(cls.__module__.split(<span class="hljs-string">&quot;.&quot;</span>)[<span class="hljs-number">0</span>])
    pipeline_class = <span class="hljs-built_in">getattr</span>(diffusers_module, config_dict[<span class="hljs-string">&quot;_class_name&quot;</span>])`}}),{c(){c=s("meta"),T=f(),h=s("h1"),y=s("a"),C=s("span"),w(m.$$.fragment),_=f(),H=s("span"),Hi=o("How to contribute a community pipeline"),Lt=f(),w(Q.$$.fragment),Ut=f(),I=s("p"),Ii=o("Community pipelines allow you to add any additional features you\u2019d like on top of the "),Oe=s("a"),Si=o("DiffusionPipeline"),xi=o(". The main benefit of building on top of the "),Ye=s("code"),Ai=o("DiffusionPipeline"),qi=o(" is anyone can load and use your pipeline by only adding one more argument, making it super easy for the community to access."),Mt=f(),W=s("p"),Ni=o("This guide will show you how to create a community pipeline and explain how they work. To keep things simple, you\u2019ll create a \u201Cone-step\u201D pipeline where the "),Ve=s("code"),Fi=o("UNet"),Li=o(" does a single forward pass and calls the scheduler once."),zt=f(),U=s("h2"),X=s("a"),Ke=s("span"),w(ae.$$.fragment),Ui=f(),Je=s("span"),Mi=o("Initialize the pipeline"),Bt=f(),P=s("p"),zi=o("You should start by creating a "),Qe=s("code"),Bi=o("one_step_unet.py"),Gi=o(" file for your community pipeline. In this file, create a pipeline class that inherits from the "),He=s("a"),Ri=o("DiffusionPipeline"),Yi=o(" to be able to load model weights and the scheduler configuration from the Hub. The one-step pipeline needs a "),We=s("code"),Vi=o("UNet"),Ki=o(" and a scheduler, so you\u2019ll need to add these as arguments to the "),Xe=s("code"),Ji=o("__init__"),Qi=o(" function:"),Gt=f(),w(pe.$$.fragment),Rt=f(),D=s("p"),Wi=o("To ensure your pipeline and its components ("),Ze=s("code"),Xi=o("unet"),Zi=o(" and "),et=s("code"),eo=o("scheduler"),to=o(") can be saved with "),Ie=s("a"),io=o("save_pretrained()"),oo=o(", add them to the "),tt=s("code"),lo=o("register_modules"),so=o(" function:"),Yt=f(),w(fe.$$.fragment),Vt=f(),Z=s("p"),no=o("Cool, the "),it=s("code"),ro=o("__init__"),ao=o(" step is done and you can move to the forward pass now! \u{1F525}"),Kt=f(),M=s("h2"),ee=s("a"),ot=s("span"),w(de.$$.fragment),po=f(),lt=s("span"),fo=o("Define the forward pass"),Jt=f(),k=s("p"),uo=o("In the forward pass, which we recommend defining as "),st=s("code"),co=o("__call__"),ho=o(", you have complete creative freedom to add whatever feature you\u2019d like. For our amazing one-step pipeline, create a random image and only call the "),nt=s("code"),mo=o("unet"),_o=o(" and "),rt=s("code"),yo=o("scheduler"),wo=o(" once by setting "),at=s("code"),vo=o("timestep=1"),$o=o(":"),Qt=f(),w(ue.$$.fragment),Wt=f(),S=s("p"),go=o("That\u2019s it! \u{1F680} You can now run this pipeline by passing a "),pt=s("code"),Eo=o("unet"),bo=o(" and "),ft=s("code"),Po=o("scheduler"),Do=o(" to it:"),Xt=f(),w(ce.$$.fragment),Zt=f(),te=s("p"),ko=o("But what\u2019s even better is you can load pre-existing weights into the pipeline if the pipeline structure is identical. For example, you can load the "),he=s("a"),dt=s("code"),jo=o("google/ddpm-cifar10-32"),Co=o(" weights into the one-step pipeline:"),ei=f(),w(me.$$.fragment),ti=f(),z=s("h2"),ie=s("a"),ut=s("span"),w(_e.$$.fragment),To=f(),ct=s("span"),Oo=o("Share your pipeline"),ii=f(),O=s("p"),Ho=o("Open a Pull Request on the \u{1F9E8} Diffusers "),ye=s("a"),Io=o("repository"),So=o(" to add your awesome pipeline in "),ht=s("code"),xo=o("one_step_unet.py"),Ao=o(" to the "),we=s("a"),qo=o("examples/community"),No=o(" subfolder."),oi=f(),x=s("p"),Fo=o("Once it is merged, anyone with "),mt=s("code"),Lo=o("diffusers >= 0.4.0"),Uo=o(" installed can use this pipeline magically \u{1FA84} by specifying it in the "),_t=s("code"),Mo=o("custom_pipeline"),zo=o(" argument:"),li=f(),w(ve.$$.fragment),si=f(),j=s("p"),Bo=o("Another way to share your community pipeline is to upload the "),yt=s("code"),Go=o("one_step_unet.py"),Ro=o(" file directly to your preferred "),$e=s("a"),Yo=o("model repository"),Vo=o(" on the Hub. Instead of specifying the "),wt=s("code"),Ko=o("one_step_unet.py"),Jo=o(" file, pass the model repository id to the "),vt=s("code"),Qo=o("custom_pipeline"),Wo=o(" argument:"),ni=f(),w(ge.$$.fragment),ri=f(),Se=s("p"),Xo=o("Take a look at the following table to compare the two sharing workflows to help you decide the best option for you:"),ai=f(),oe=s("table"),$t=s("thead"),B=s("tr"),pi=s("th"),Zo=f(),gt=s("th"),el=o("GitHub community pipeline"),tl=f(),Et=s("th"),il=o("HF Hub community pipeline"),ol=f(),G=s("tbody"),R=s("tr"),bt=s("td"),ll=o("usage"),sl=f(),Pt=s("td"),nl=o("same"),rl=f(),Dt=s("td"),al=o("same"),pl=f(),Y=s("tr"),kt=s("td"),fl=o("review process"),dl=f(),jt=s("td"),ul=o("open a Pull Request on GitHub and undergo a review process from the Diffusers team before merging; may be slower"),cl=f(),Ct=s("td"),hl=o("upload directly to a Hub repository without any review; this is the fastest workflow"),ml=f(),V=s("tr"),Tt=s("td"),_l=o("visibility"),yl=f(),Ot=s("td"),wl=o("included in the official Diffusers repository and documentation"),vl=f(),Ht=s("td"),$l=o("included on your HF Hub profile and relies on your own usage/promotion to gain visibility"),fi=f(),w(le.$$.fragment),di=f(),K=s("h2"),se=s("a"),It=s("span"),w(Ee.$$.fragment),gl=f(),St=s("span"),El=o("How do community pipelines work?"),ui=f(),ne=s("p"),bl=o("A community pipeline is a class that inherits from "),xe=s("a"),Pl=o("DiffusionPipeline"),Dl=o(" which means:"),ci=f(),A=s("ul"),be=s("li"),kl=o("It can be loaded with the "),xt=s("code"),jl=o("custom_pipeline"),Cl=o(" argument."),Tl=f(),Pe=s("li"),Ol=o("The model weights and scheduler configuration are loaded from "),At=s("code"),Hl=o("pretrained_model_name_or_path"),Il=o("."),Sl=f(),De=s("li"),xl=o("The code that implements a feature in the community pipeline is defined in a "),qt=s("code"),Al=o("pipeline.py"),ql=o(" file."),hi=f(),Ae=s("p"),Nl=o("Sometimes you can\u2019t load all the pipeline components weights from an official repository. In this case, the other components should be passed directly to the pipeline:"),mi=f(),w(ke.$$.fragment),_i=f(),qe=s("p"),Fl=o("The magic behind community pipelines is contained in the following code. It allows the community pipeline to be loaded from GitHub or the Hub, and it\u2019ll be available to all \u{1F9E8} Diffusers packages."),yi=f(),w(je.$$.fragment),this.h()},l(e){const a=Ws('[data-svelte="svelte-1phssyn"]',document.head);c=n(a,"META",{name:!0,content:!0}),a.forEach(i),T=d(e),h=n(e,"H1",{class:!0});var Ce=r(h);y=n(Ce,"A",{id:!0,class:!0,href:!0});var Nt=r(y);C=n(Nt,"SPAN",{});var Ll=r(C);v(m.$$.fragment,Ll),Ll.forEach(i),Nt.forEach(i),_=d(Ce),H=n(Ce,"SPAN",{});var Ul=r(H);Hi=l(Ul,"How to contribute a community pipeline"),Ul.forEach(i),Ce.forEach(i),Lt=d(e),v(Q.$$.fragment,e),Ut=d(e),I=n(e,"P",{});var Ne=r(I);Ii=l(Ne,"Community pipelines allow you to add any additional features you\u2019d like on top of the "),Oe=n(Ne,"A",{href:!0});var Ml=r(Oe);Si=l(Ml,"DiffusionPipeline"),Ml.forEach(i),xi=l(Ne,". The main benefit of building on top of the "),Ye=n(Ne,"CODE",{});var zl=r(Ye);Ai=l(zl,"DiffusionPipeline"),zl.forEach(i),qi=l(Ne," is anyone can load and use your pipeline by only adding one more argument, making it super easy for the community to access."),Ne.forEach(i),Mt=d(e),W=n(e,"P",{});var vi=r(W);Ni=l(vi,"This guide will show you how to create a community pipeline and explain how they work. To keep things simple, you\u2019ll create a \u201Cone-step\u201D pipeline where the "),Ve=n(vi,"CODE",{});var Bl=r(Ve);Fi=l(Bl,"UNet"),Bl.forEach(i),Li=l(vi," does a single forward pass and calls the scheduler once."),vi.forEach(i),zt=d(e),U=n(e,"H2",{class:!0});var $i=r(U);X=n($i,"A",{id:!0,class:!0,href:!0});var Gl=r(X);Ke=n(Gl,"SPAN",{});var Rl=r(Ke);v(ae.$$.fragment,Rl),Rl.forEach(i),Gl.forEach(i),Ui=d($i),Je=n($i,"SPAN",{});var Yl=r(Je);Mi=l(Yl,"Initialize the pipeline"),Yl.forEach(i),$i.forEach(i),Bt=d(e),P=n(e,"P",{});var q=r(P);zi=l(q,"You should start by creating a "),Qe=n(q,"CODE",{});var Vl=r(Qe);Bi=l(Vl,"one_step_unet.py"),Vl.forEach(i),Gi=l(q," file for your community pipeline. In this file, create a pipeline class that inherits from the "),He=n(q,"A",{href:!0});var Kl=r(He);Ri=l(Kl,"DiffusionPipeline"),Kl.forEach(i),Yi=l(q," to be able to load model weights and the scheduler configuration from the Hub. The one-step pipeline needs a "),We=n(q,"CODE",{});var Jl=r(We);Vi=l(Jl,"UNet"),Jl.forEach(i),Ki=l(q," and a scheduler, so you\u2019ll need to add these as arguments to the "),Xe=n(q,"CODE",{});var Ql=r(Xe);Ji=l(Ql,"__init__"),Ql.forEach(i),Qi=l(q," function:"),q.forEach(i),Gt=d(e),v(pe.$$.fragment,e),Rt=d(e),D=n(e,"P",{});var N=r(D);Wi=l(N,"To ensure your pipeline and its components ("),Ze=n(N,"CODE",{});var Wl=r(Ze);Xi=l(Wl,"unet"),Wl.forEach(i),Zi=l(N," and "),et=n(N,"CODE",{});var Xl=r(et);eo=l(Xl,"scheduler"),Xl.forEach(i),to=l(N,") can be saved with "),Ie=n(N,"A",{href:!0});var Zl=r(Ie);io=l(Zl,"save_pretrained()"),Zl.forEach(i),oo=l(N,", add them to the "),tt=n(N,"CODE",{});var es=r(tt);lo=l(es,"register_modules"),es.forEach(i),so=l(N," function:"),N.forEach(i),Yt=d(e),v(fe.$$.fragment,e),Vt=d(e),Z=n(e,"P",{});var gi=r(Z);no=l(gi,"Cool, the "),it=n(gi,"CODE",{});var ts=r(it);ro=l(ts,"__init__"),ts.forEach(i),ao=l(gi," step is done and you can move to the forward pass now! \u{1F525}"),gi.forEach(i),Kt=d(e),M=n(e,"H2",{class:!0});var Ei=r(M);ee=n(Ei,"A",{id:!0,class:!0,href:!0});var is=r(ee);ot=n(is,"SPAN",{});var os=r(ot);v(de.$$.fragment,os),os.forEach(i),is.forEach(i),po=d(Ei),lt=n(Ei,"SPAN",{});var ls=r(lt);fo=l(ls,"Define the forward pass"),ls.forEach(i),Ei.forEach(i),Jt=d(e),k=n(e,"P",{});var F=r(k);uo=l(F,"In the forward pass, which we recommend defining as "),st=n(F,"CODE",{});var ss=r(st);co=l(ss,"__call__"),ss.forEach(i),ho=l(F,", you have complete creative freedom to add whatever feature you\u2019d like. For our amazing one-step pipeline, create a random image and only call the "),nt=n(F,"CODE",{});var ns=r(nt);mo=l(ns,"unet"),ns.forEach(i),_o=l(F," and "),rt=n(F,"CODE",{});var rs=r(rt);yo=l(rs,"scheduler"),rs.forEach(i),wo=l(F," once by setting "),at=n(F,"CODE",{});var as=r(at);vo=l(as,"timestep=1"),as.forEach(i),$o=l(F,":"),F.forEach(i),Qt=d(e),v(ue.$$.fragment,e),Wt=d(e),S=n(e,"P",{});var Fe=r(S);go=l(Fe,"That\u2019s it! \u{1F680} You can now run this pipeline by passing a "),pt=n(Fe,"CODE",{});var ps=r(pt);Eo=l(ps,"unet"),ps.forEach(i),bo=l(Fe," and "),ft=n(Fe,"CODE",{});var fs=r(ft);Po=l(fs,"scheduler"),fs.forEach(i),Do=l(Fe," to it:"),Fe.forEach(i),Xt=d(e),v(ce.$$.fragment,e),Zt=d(e),te=n(e,"P",{});var bi=r(te);ko=l(bi,"But what\u2019s even better is you can load pre-existing weights into the pipeline if the pipeline structure is identical. For example, you can load the "),he=n(bi,"A",{href:!0,rel:!0});var ds=r(he);dt=n(ds,"CODE",{});var us=r(dt);jo=l(us,"google/ddpm-cifar10-32"),us.forEach(i),ds.forEach(i),Co=l(bi," weights into the one-step pipeline:"),bi.forEach(i),ei=d(e),v(me.$$.fragment,e),ti=d(e),z=n(e,"H2",{class:!0});var Pi=r(z);ie=n(Pi,"A",{id:!0,class:!0,href:!0});var cs=r(ie);ut=n(cs,"SPAN",{});var hs=r(ut);v(_e.$$.fragment,hs),hs.forEach(i),cs.forEach(i),To=d(Pi),ct=n(Pi,"SPAN",{});var ms=r(ct);Oo=l(ms,"Share your pipeline"),ms.forEach(i),Pi.forEach(i),ii=d(e),O=n(e,"P",{});var re=r(O);Ho=l(re,"Open a Pull Request on the \u{1F9E8} Diffusers "),ye=n(re,"A",{href:!0,rel:!0});var _s=r(ye);Io=l(_s,"repository"),_s.forEach(i),So=l(re," to add your awesome pipeline in "),ht=n(re,"CODE",{});var ys=r(ht);xo=l(ys,"one_step_unet.py"),ys.forEach(i),Ao=l(re," to the "),we=n(re,"A",{href:!0,rel:!0});var ws=r(we);qo=l(ws,"examples/community"),ws.forEach(i),No=l(re," subfolder."),re.forEach(i),oi=d(e),x=n(e,"P",{});var Le=r(x);Fo=l(Le,"Once it is merged, anyone with "),mt=n(Le,"CODE",{});var vs=r(mt);Lo=l(vs,"diffusers >= 0.4.0"),vs.forEach(i),Uo=l(Le," installed can use this pipeline magically \u{1FA84} by specifying it in the "),_t=n(Le,"CODE",{});var $s=r(_t);Mo=l($s,"custom_pipeline"),$s.forEach(i),zo=l(Le," argument:"),Le.forEach(i),li=d(e),v(ve.$$.fragment,e),si=d(e),j=n(e,"P",{});var L=r(j);Bo=l(L,"Another way to share your community pipeline is to upload the "),yt=n(L,"CODE",{});var gs=r(yt);Go=l(gs,"one_step_unet.py"),gs.forEach(i),Ro=l(L," file directly to your preferred "),$e=n(L,"A",{href:!0,rel:!0});var Es=r($e);Yo=l(Es,"model repository"),Es.forEach(i),Vo=l(L," on the Hub. Instead of specifying the "),wt=n(L,"CODE",{});var bs=r(wt);Ko=l(bs,"one_step_unet.py"),bs.forEach(i),Jo=l(L," file, pass the model repository id to the "),vt=n(L,"CODE",{});var Ps=r(vt);Qo=l(Ps,"custom_pipeline"),Ps.forEach(i),Wo=l(L," argument:"),L.forEach(i),ni=d(e),v(ge.$$.fragment,e),ri=d(e),Se=n(e,"P",{});var Ds=r(Se);Xo=l(Ds,"Take a look at the following table to compare the two sharing workflows to help you decide the best option for you:"),Ds.forEach(i),ai=d(e),oe=n(e,"TABLE",{});var Di=r(oe);$t=n(Di,"THEAD",{});var ks=r($t);B=n(ks,"TR",{});var Ue=r(B);pi=n(Ue,"TH",{}),r(pi).forEach(i),Zo=d(Ue),gt=n(Ue,"TH",{});var js=r(gt);el=l(js,"GitHub community pipeline"),js.forEach(i),tl=d(Ue),Et=n(Ue,"TH",{});var Cs=r(Et);il=l(Cs,"HF Hub community pipeline"),Cs.forEach(i),Ue.forEach(i),ks.forEach(i),ol=d(Di),G=n(Di,"TBODY",{});var Me=r(G);R=n(Me,"TR",{});var ze=r(R);bt=n(ze,"TD",{});var Ts=r(bt);ll=l(Ts,"usage"),Ts.forEach(i),sl=d(ze),Pt=n(ze,"TD",{});var Os=r(Pt);nl=l(Os,"same"),Os.forEach(i),rl=d(ze),Dt=n(ze,"TD",{});var Hs=r(Dt);al=l(Hs,"same"),Hs.forEach(i),ze.forEach(i),pl=d(Me),Y=n(Me,"TR",{});var Be=r(Y);kt=n(Be,"TD",{});var Is=r(kt);fl=l(Is,"review process"),Is.forEach(i),dl=d(Be),jt=n(Be,"TD",{});var Ss=r(jt);ul=l(Ss,"open a Pull Request on GitHub and undergo a review process from the Diffusers team before merging; may be slower"),Ss.forEach(i),cl=d(Be),Ct=n(Be,"TD",{});var xs=r(Ct);hl=l(xs,"upload directly to a Hub repository without any review; this is the fastest workflow"),xs.forEach(i),Be.forEach(i),ml=d(Me),V=n(Me,"TR",{});var Ge=r(V);Tt=n(Ge,"TD",{});var As=r(Tt);_l=l(As,"visibility"),As.forEach(i),yl=d(Ge),Ot=n(Ge,"TD",{});var qs=r(Ot);wl=l(qs,"included in the official Diffusers repository and documentation"),qs.forEach(i),vl=d(Ge),Ht=n(Ge,"TD",{});var Ns=r(Ht);$l=l(Ns,"included on your HF Hub profile and relies on your own usage/promotion to gain visibility"),Ns.forEach(i),Ge.forEach(i),Me.forEach(i),Di.forEach(i),fi=d(e),v(le.$$.fragment,e),di=d(e),K=n(e,"H2",{class:!0});var ki=r(K);se=n(ki,"A",{id:!0,class:!0,href:!0});var Fs=r(se);It=n(Fs,"SPAN",{});var Ls=r(It);v(Ee.$$.fragment,Ls),Ls.forEach(i),Fs.forEach(i),gl=d(ki),St=n(ki,"SPAN",{});var Us=r(St);El=l(Us,"How do community pipelines work?"),Us.forEach(i),ki.forEach(i),ui=d(e),ne=n(e,"P",{});var ji=r(ne);bl=l(ji,"A community pipeline is a class that inherits from "),xe=n(ji,"A",{href:!0});var Ms=r(xe);Pl=l(Ms,"DiffusionPipeline"),Ms.forEach(i),Dl=l(ji," which means:"),ji.forEach(i),ci=d(e),A=n(e,"UL",{});var Re=r(A);be=n(Re,"LI",{});var Ci=r(be);kl=l(Ci,"It can be loaded with the "),xt=n(Ci,"CODE",{});var zs=r(xt);jl=l(zs,"custom_pipeline"),zs.forEach(i),Cl=l(Ci," argument."),Ci.forEach(i),Tl=d(Re),Pe=n(Re,"LI",{});var Ti=r(Pe);Ol=l(Ti,"The model weights and scheduler configuration are loaded from "),At=n(Ti,"CODE",{});var Bs=r(At);Hl=l(Bs,"pretrained_model_name_or_path"),Bs.forEach(i),Il=l(Ti,"."),Ti.forEach(i),Sl=d(Re),De=n(Re,"LI",{});var Oi=r(De);xl=l(Oi,"The code that implements a feature in the community pipeline is defined in a "),qt=n(Oi,"CODE",{});var Gs=r(qt);Al=l(Gs,"pipeline.py"),Gs.forEach(i),ql=l(Oi," file."),Oi.forEach(i),Re.forEach(i),hi=d(e),Ae=n(e,"P",{});var Rs=r(Ae);Nl=l(Rs,"Sometimes you can\u2019t load all the pipeline components weights from an official repository. In this case, the other components should be passed directly to the pipeline:"),Rs.forEach(i),mi=d(e),v(ke.$$.fragment,e),_i=d(e),qe=n(e,"P",{});var Ys=r(qe);Fl=l(Ys,"The magic behind community pipelines is contained in the following code. It allows the community pipeline to be loaded from GitHub or the Hub, and it\u2019ll be available to all \u{1F9E8} Diffusers packages."),Ys.forEach(i),yi=d(e),v(je.$$.fragment,e),this.h()},h(){u(c,"name","hf:doc:metadata"),u(c,"content",JSON.stringify(on)),u(y,"id","how-to-contribute-a-community-pipeline"),u(y,"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"),u(y,"href","#how-to-contribute-a-community-pipeline"),u(h,"class","relative group"),u(Oe,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(X,"id","initialize-the-pipeline"),u(X,"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"),u(X,"href","#initialize-the-pipeline"),u(U,"class","relative group"),u(He,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(Ie,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline.save_pretrained"),u(ee,"id","define-the-forward-pass"),u(ee,"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"),u(ee,"href","#define-the-forward-pass"),u(M,"class","relative group"),u(he,"href","https://huggingface.co/google/ddpm-cifar10-32"),u(he,"rel","nofollow"),u(ie,"id","share-your-pipeline"),u(ie,"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"),u(ie,"href","#share-your-pipeline"),u(z,"class","relative group"),u(ye,"href","https://github.com/huggingface/diffusers"),u(ye,"rel","nofollow"),u(we,"href","https://github.com/huggingface/diffusers/tree/main/examples/community"),u(we,"rel","nofollow"),u($e,"href","https://huggingface.co/docs/hub/models-uploading"),u($e,"rel","nofollow"),u(se,"id","how-do-community-pipelines-work"),u(se,"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"),u(se,"href","#how-do-community-pipelines-work"),u(K,"class","relative group"),u(xe,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline")},m(e,a){t(document.head,c),p(e,T,a),p(e,h,a),t(h,y),t(y,C),$(m,C,null),t(h,_),t(h,H),t(H,Hi),p(e,Lt,a),$(Q,e,a),p(e,Ut,a),p(e,I,a),t(I,Ii),t(I,Oe),t(Oe,Si),t(I,xi),t(I,Ye),t(Ye,Ai),t(I,qi),p(e,Mt,a),p(e,W,a),t(W,Ni),t(W,Ve),t(Ve,Fi),t(W,Li),p(e,zt,a),p(e,U,a),t(U,X),t(X,Ke),$(ae,Ke,null),t(U,Ui),t(U,Je),t(Je,Mi),p(e,Bt,a),p(e,P,a),t(P,zi),t(P,Qe),t(Qe,Bi),t(P,Gi),t(P,He),t(He,Ri),t(P,Yi),t(P,We),t(We,Vi),t(P,Ki),t(P,Xe),t(Xe,Ji),t(P,Qi),p(e,Gt,a),$(pe,e,a),p(e,Rt,a),p(e,D,a),t(D,Wi),t(D,Ze),t(Ze,Xi),t(D,Zi),t(D,et),t(et,eo),t(D,to),t(D,Ie),t(Ie,io),t(D,oo),t(D,tt),t(tt,lo),t(D,so),p(e,Yt,a),$(fe,e,a),p(e,Vt,a),p(e,Z,a),t(Z,no),t(Z,it),t(it,ro),t(Z,ao),p(e,Kt,a),p(e,M,a),t(M,ee),t(ee,ot),$(de,ot,null),t(M,po),t(M,lt),t(lt,fo),p(e,Jt,a),p(e,k,a),t(k,uo),t(k,st),t(st,co),t(k,ho),t(k,nt),t(nt,mo),t(k,_o),t(k,rt),t(rt,yo),t(k,wo),t(k,at),t(at,vo),t(k,$o),p(e,Qt,a),$(ue,e,a),p(e,Wt,a),p(e,S,a),t(S,go),t(S,pt),t(pt,Eo),t(S,bo),t(S,ft),t(ft,Po),t(S,Do),p(e,Xt,a),$(ce,e,a),p(e,Zt,a),p(e,te,a),t(te,ko),t(te,he),t(he,dt),t(dt,jo),t(te,Co),p(e,ei,a),$(me,e,a),p(e,ti,a),p(e,z,a),t(z,ie),t(ie,ut),$(_e,ut,null),t(z,To),t(z,ct),t(ct,Oo),p(e,ii,a),p(e,O,a),t(O,Ho),t(O,ye),t(ye,Io),t(O,So),t(O,ht),t(ht,xo),t(O,Ao),t(O,we),t(we,qo),t(O,No),p(e,oi,a),p(e,x,a),t(x,Fo),t(x,mt),t(mt,Lo),t(x,Uo),t(x,_t),t(_t,Mo),t(x,zo),p(e,li,a),$(ve,e,a),p(e,si,a),p(e,j,a),t(j,Bo),t(j,yt),t(yt,Go),t(j,Ro),t(j,$e),t($e,Yo),t(j,Vo),t(j,wt),t(wt,Ko),t(j,Jo),t(j,vt),t(vt,Qo),t(j,Wo),p(e,ni,a),$(ge,e,a),p(e,ri,a),p(e,Se,a),t(Se,Xo),p(e,ai,a),p(e,oe,a),t(oe,$t),t($t,B),t(B,pi),t(B,Zo),t(B,gt),t(gt,el),t(B,tl),t(B,Et),t(Et,il),t(oe,ol),t(oe,G),t(G,R),t(R,bt),t(bt,ll),t(R,sl),t(R,Pt),t(Pt,nl),t(R,rl),t(R,Dt),t(Dt,al),t(G,pl),t(G,Y),t(Y,kt),t(kt,fl),t(Y,dl),t(Y,jt),t(jt,ul),t(Y,cl),t(Y,Ct),t(Ct,hl),t(G,ml),t(G,V),t(V,Tt),t(Tt,_l),t(V,yl),t(V,Ot),t(Ot,wl),t(V,vl),t(V,Ht),t(Ht,$l),p(e,fi,a),$(le,e,a),p(e,di,a),p(e,K,a),t(K,se),t(se,It),$(Ee,It,null),t(K,gl),t(K,St),t(St,El),p(e,ui,a),p(e,ne,a),t(ne,bl),t(ne,xe),t(xe,Pl),t(ne,Dl),p(e,ci,a),p(e,A,a),t(A,be),t(be,kl),t(be,xt),t(xt,jl),t(be,Cl),t(A,Tl),t(A,Pe),t(Pe,Ol),t(Pe,At),t(At,Hl),t(Pe,Il),t(A,Sl),t(A,De),t(De,xl),t(De,qt),t(qt,Al),t(De,ql),p(e,hi,a),p(e,Ae,a),t(Ae,Nl),p(e,mi,a),$(ke,e,a),p(e,_i,a),p(e,qe,a),t(qe,Fl),p(e,yi,a),$(je,e,a),wi=!0},p(e,[a]){const Ce={};a&2&&(Ce.$$scope={dirty:a,ctx:e}),Q.$set(Ce);const Nt={};a&2&&(Nt.$$scope={dirty:a,ctx:e}),le.$set(Nt)},i(e){wi||(g(m.$$.fragment,e),g(Q.$$.fragment,e),g(ae.$$.fragment,e),g(pe.$$.fragment,e),g(fe.$$.fragment,e),g(de.$$.fragment,e),g(ue.$$.fragment,e),g(ce.$$.fragment,e),g(me.$$.fragment,e),g(_e.$$.fragment,e),g(ve.$$.fragment,e),g(ge.$$.fragment,e),g(le.$$.fragment,e),g(Ee.$$.fragment,e),g(ke.$$.fragment,e),g(je.$$.fragment,e),wi=!0)},o(e){E(m.$$.fragment,e),E(Q.$$.fragment,e),E(ae.$$.fragment,e),E(pe.$$.fragment,e),E(fe.$$.fragment,e),E(de.$$.fragment,e),E(ue.$$.fragment,e),E(ce.$$.fragment,e),E(me.$$.fragment,e),E(_e.$$.fragment,e),E(ve.$$.fragment,e),E(ge.$$.fragment,e),E(le.$$.fragment,e),E(Ee.$$.fragment,e),E(ke.$$.fragment,e),E(je.$$.fragment,e),wi=!1},d(e){i(c),e&&i(T),e&&i(h),b(m),e&&i(Lt),b(Q,e),e&&i(Ut),e&&i(I),e&&i(Mt),e&&i(W),e&&i(zt),e&&i(U),b(ae),e&&i(Bt),e&&i(P),e&&i(Gt),b(pe,e),e&&i(Rt),e&&i(D),e&&i(Yt),b(fe,e),e&&i(Vt),e&&i(Z),e&&i(Kt),e&&i(M),b(de),e&&i(Jt),e&&i(k),e&&i(Qt),b(ue,e),e&&i(Wt),e&&i(S),e&&i(Xt),b(ce,e),e&&i(Zt),e&&i(te),e&&i(ei),b(me,e),e&&i(ti),e&&i(z),b(_e),e&&i(ii),e&&i(O),e&&i(oi),e&&i(x),e&&i(li),b(ve,e),e&&i(si),e&&i(j),e&&i(ni),b(ge,e),e&&i(ri),e&&i(Se),e&&i(ai),e&&i(oe),e&&i(fi),b(le,e),e&&i(di),e&&i(K),b(Ee),e&&i(ui),e&&i(ne),e&&i(ci),e&&i(A),e&&i(hi),e&&i(Ae),e&&i(mi),b(ke,e),e&&i(_i),e&&i(qe),e&&i(yi),b(je,e)}}}const on={local:"how-to-contribute-a-community-pipeline",sections:[{local:"initialize-the-pipeline",title:"Initialize the pipeline"},{local:"define-the-forward-pass",title:"Define the forward pass"},{local:"share-your-pipeline",title:"Share your pipeline"},{local:"how-do-community-pipelines-work",title:"How do community pipelines work?"}],title:"How to contribute a community pipeline"};function ln(Te){return Xs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pn extends Ks{constructor(c){super();Js(this,c,ln,tn,Qs,{})}}export{pn as default,on as metadata};
