import{s as qe,o as Se,n as Qe}from"../chunks/scheduler.8c3d61f6.js";import{S as Ye,i as Oe,g as u,s as n,r as i,A as Ke,h as g,f as s,c as r,j as w,u as o,x as U,k as I,y as _,a,v as l,d as p,t as m,w as d}from"../chunks/index.da70eac4.js";import{D as L}from"../chunks/Docstring.6b390b9a.js";import{C as et}from"../chunks/CodeBlock.00a903b3.js";import{E as tt}from"../chunks/ExampleCodeBlock.db12be95.js";import{H as C,E as st}from"../chunks/EditOnGithub.1e64e623.js";function at(le){let c,P="Example:",v,h,$;return h=new et({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBDb2dWaWRlb1hUcmFuc2Zvcm1lcjNETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKSUwQSUwQWFwcGx5X2xheWVyd2lzZV9jYXN0aW5nKCUwQSUyMCUyMCUyMCUyMHRyYW5zZm9ybWVyJTJDJTBBJTIwJTIwJTIwJTIwc3RvcmFnZV9kdHlwZSUzRHRvcmNoLmZsb2F0OF9lNG0zZm4lMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEElMjAlMjAlMjAlMjBza2lwX21vZHVsZXNfcGF0dGVybiUzRCU1QiUyMnBhdGNoX2VtYmVkJTIyJTJDJTIwJTIybm9ybSUyMiUyQyUyMCUyMnByb2pfb3V0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwbm9uX2Jsb2NraW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXTransformer3DModel

<span class="hljs-meta">&gt;&gt;&gt; </span>transformer = CogVideoXTransformer3DModel.from_pretrained(
<span class="hljs-meta">... </span>    model_id, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, torch_dtype=torch.bfloat16
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>apply_layerwise_casting(
<span class="hljs-meta">... </span>    transformer,
<span class="hljs-meta">... </span>    storage_dtype=torch.float8_e4m3fn,
<span class="hljs-meta">... </span>    compute_dtype=torch.bfloat16,
<span class="hljs-meta">... </span>    skip_modules_pattern=[<span class="hljs-string">&quot;patch_embed&quot;</span>, <span class="hljs-string">&quot;norm&quot;</span>, <span class="hljs-string">&quot;proj_out&quot;</span>],
<span class="hljs-meta">... </span>    non_blocking=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`,wrap:!1}}),{c(){c=u("p"),c.textContent=P,v=n(),i(h.$$.fragment)},l(f){c=g(f,"P",{"data-svelte-h":!0}),U(c)!=="svelte-11lpom8"&&(c.textContent=P),v=r(f),o(h.$$.fragment,f)},m(f,y){a(f,c,y),a(f,v,y),l(h,f,y),$=!0},p:Qe,i(f){$||(p(h.$$.fragment,f),$=!0)},o(f){m(h.$$.fragment,f),$=!1},d(f){f&&(s(c),s(v)),d(h,f)}}}function nt(le){let c,P,v,h,$,f,y,Be="Utility and helper functions for working with 🤗 Diffusers.",pe,V,me,x,E,Ue,ee,Re="Convert a numpy image or a batch of images to a PIL image.",de,N,fe,T,Z,Pe,te,Fe="Convert a torch image to a PIL image.",ue,D,ge,k,B,Ve,se,Ge="Loads <code>image</code> to a PIL Image.",ce,R,_e,F,G,he,H,$e,X,z,ye,A,be,M,W,Ee,ae,He="Prepares a single grid of images. Useful for visualization purposes.",ve,q,we,J,S,Ne,ne,Xe=`A helper function to create random tensors on the desired <code>device</code> with the desired <code>dtype</code>. When
passing a list of generators, you can seed each batch size individually. If CPU generators are passed, the tensor
is always created on the CPU.`,Ie,Q,xe,b,Y,Ze,re,ze=`Applies layerwise casting to a given module. The module expected here is a Diffusers ModelMixin but it can be any
nn.Module using diffusers layers or pytorch primitives.`,De,j,Te,O,ke,oe,Me;return $=new C({props:{title:"Utilities",local:"utilities",headingTag:"h1"}}),V=new C({props:{title:"numpy_to_pil",local:"diffusers.utils.numpy_to_pil",headingTag:"h2"}}),E=new L({props:{name:"diffusers.utils.numpy_to_pil",anchor:"diffusers.utils.numpy_to_pil",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/pil_utils.py#L37"}}),N=new C({props:{title:"pt_to_pil",local:"diffusers.utils.pt_to_pil",headingTag:"h2"}}),Z=new L({props:{name:"diffusers.utils.pt_to_pil",anchor:"diffusers.utils.pt_to_pil",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/pil_utils.py#L27"}}),D=new C({props:{title:"load_image",local:"diffusers.utils.load_image",headingTag:"h2"}}),B=new L({props:{name:"diffusers.utils.load_image",anchor:"diffusers.utils.load_image",parameters:[{name:"image",val:": typing.Union[str, PIL.Image.Image]"},{name:"convert_method",val:": typing.Optional[typing.Callable[[PIL.Image.Image], PIL.Image.Image]] = None"}],parametersDescription:[{anchor:"diffusers.utils.load_image.image",description:`<strong>image</strong> (<code>str</code> or <code>PIL.Image.Image</code>) &#x2014;
The image to convert to the PIL Image format.`,name:"image"},{anchor:"diffusers.utils.load_image.convert_method",description:`<strong>convert_method</strong> (Callable[[PIL.Image.Image], PIL.Image.Image], <em>optional</em>) &#x2014;
A conversion method to apply to the image after loading it. When set to <code>None</code> the image will be converted
&#x201C;RGB&#x201D;.`,name:"convert_method"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/loading_utils.py#L13",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A PIL Image.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>PIL.Image.Image</code></p>
`}}),R=new C({props:{title:"export_to_gif",local:"diffusers.utils.export_to_gif",headingTag:"h2"}}),G=new L({props:{name:"diffusers.utils.export_to_gif",anchor:"diffusers.utils.export_to_gif",parameters:[{name:"image",val:": typing.List[PIL.Image.Image]"},{name:"output_gif_path",val:": str = None"},{name:"fps",val:": int = 10"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/export_utils.py#L28"}}),H=new C({props:{title:"export_to_video",local:"diffusers.utils.export_to_video",headingTag:"h2"}}),z=new L({props:{name:"diffusers.utils.export_to_video",anchor:"diffusers.utils.export_to_video",parameters:[{name:"video_frames",val:": typing.Union[typing.List[numpy.ndarray], typing.List[PIL.Image.Image]]"},{name:"output_video_path",val:": str = None"},{name:"fps",val:": int = 10"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/export_utils.py#L141"}}),A=new C({props:{title:"make_image_grid",local:"diffusers.utils.make_image_grid",headingTag:"h2"}}),W=new L({props:{name:"diffusers.utils.make_image_grid",anchor:"diffusers.utils.make_image_grid",parameters:[{name:"images",val:": typing.List[PIL.Image.Image]"},{name:"rows",val:": int"},{name:"cols",val:": int"},{name:"resize",val:": int = None"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/pil_utils.py#L53"}}),q=new C({props:{title:"randn_tensor",local:"diffusers.utils.torch_utils.randn_tensor",headingTag:"h2"}}),S=new L({props:{name:"diffusers.utils.torch_utils.randn_tensor",anchor:"diffusers.utils.torch_utils.randn_tensor",parameters:[{name:"shape",val:": typing.Union[typing.Tuple, typing.List]"},{name:"generator",val:": typing.Union[typing.List[ForwardRef('torch.Generator')], ForwardRef('torch.Generator'), NoneType] = None"},{name:"device",val:": typing.Optional[ForwardRef('torch.device')] = None"},{name:"dtype",val:": typing.Optional[ForwardRef('torch.dtype')] = None"},{name:"layout",val:": typing.Optional[ForwardRef('torch.layout')] = None"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/torch_utils.py#L38"}}),Q=new C({props:{title:"apply_layerwise_casting",local:"diffusers.hooks.apply_layerwise_casting",headingTag:"h2"}}),Y=new L({props:{name:"diffusers.hooks.apply_layerwise_casting",anchor:"diffusers.hooks.apply_layerwise_casting",parameters:[{name:"module",val:": Module"},{name:"storage_dtype",val:": dtype"},{name:"compute_dtype",val:": dtype"},{name:"skip_modules_pattern",val:": typing.Union[str, typing.Tuple[str, ...]] = 'auto'"},{name:"skip_modules_classes",val:": typing.Optional[typing.Tuple[typing.Type[torch.nn.modules.module.Module], ...]] = None"},{name:"non_blocking",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.hooks.apply_layerwise_casting.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) &#x2014;
The module whose leaf modules will be cast to a high precision dtype for computation, and to a low
precision dtype for storage.`,name:"module"},{anchor:"diffusers.hooks.apply_layerwise_casting.storage_dtype",description:`<strong>storage_dtype</strong> (<code>torch.dtype</code>) &#x2014;
The dtype to cast the module to before/after the forward pass for storage.`,name:"storage_dtype"},{anchor:"diffusers.hooks.apply_layerwise_casting.compute_dtype",description:`<strong>compute_dtype</strong> (<code>torch.dtype</code>) &#x2014;
The dtype to cast the module to during the forward pass for computation.`,name:"compute_dtype"},{anchor:"diffusers.hooks.apply_layerwise_casting.skip_modules_pattern",description:`<strong>skip_modules_pattern</strong> (<code>Tuple[str, ...]</code>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
A list of patterns to match the names of the modules to skip during the layerwise casting process. If set
to <code>&quot;auto&quot;</code>, the default patterns are used. If set to <code>None</code>, no modules are skipped. If set to <code>None</code>
alongside <code>skip_modules_classes</code> being <code>None</code>, the layerwise casting is applied directly to the module
instead of its internal submodules.`,name:"skip_modules_pattern"},{anchor:"diffusers.hooks.apply_layerwise_casting.skip_modules_classes",description:`<strong>skip_modules_classes</strong> (<code>Tuple[Type[torch.nn.Module], ...]</code>, defaults to <code>None</code>) &#x2014;
A list of module classes to skip during the layerwise casting process.`,name:"skip_modules_classes"},{anchor:"diffusers.hooks.apply_layerwise_casting.non_blocking",description:`<strong>non_blocking</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
If <code>True</code>, the weight casting operations are non-blocking.`,name:"non_blocking"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/layerwise_casting.py#L73"}}),j=new tt({props:{anchor:"diffusers.hooks.apply_layerwise_casting.example",$$slots:{default:[at]},$$scope:{ctx:le}}}),O=new st({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/utilities.md"}}),{c(){c=u("meta"),P=n(),v=u("p"),h=n(),i($.$$.fragment),f=n(),y=u("p"),y.textContent=Be,pe=n(),i(V.$$.fragment),me=n(),x=u("div"),i(E.$$.fragment),Ue=n(),ee=u("p"),ee.textContent=Re,de=n(),i(N.$$.fragment),fe=n(),T=u("div"),i(Z.$$.fragment),Pe=n(),te=u("p"),te.textContent=Fe,ue=n(),i(D.$$.fragment),ge=n(),k=u("div"),i(B.$$.fragment),Ve=n(),se=u("p"),se.innerHTML=Ge,ce=n(),i(R.$$.fragment),_e=n(),F=u("div"),i(G.$$.fragment),he=n(),i(H.$$.fragment),$e=n(),X=u("div"),i(z.$$.fragment),ye=n(),i(A.$$.fragment),be=n(),M=u("div"),i(W.$$.fragment),Ee=n(),ae=u("p"),ae.textContent=He,ve=n(),i(q.$$.fragment),we=n(),J=u("div"),i(S.$$.fragment),Ne=n(),ne=u("p"),ne.innerHTML=Xe,Ie=n(),i(Q.$$.fragment),xe=n(),b=u("div"),i(Y.$$.fragment),Ze=n(),re=u("p"),re.textContent=ze,De=n(),i(j.$$.fragment),Te=n(),i(O.$$.fragment),ke=n(),oe=u("p"),this.h()},l(e){const t=Ke("svelte-u9bgzb",document.head);c=g(t,"META",{name:!0,content:!0}),t.forEach(s),P=r(e),v=g(e,"P",{}),w(v).forEach(s),h=r(e),o($.$$.fragment,e),f=r(e),y=g(e,"P",{"data-svelte-h":!0}),U(y)!=="svelte-sj662i"&&(y.textContent=Be),pe=r(e),o(V.$$.fragment,e),me=r(e),x=g(e,"DIV",{class:!0});var K=w(x);o(E.$$.fragment,K),Ue=r(K),ee=g(K,"P",{"data-svelte-h":!0}),U(ee)!=="svelte-49eriv"&&(ee.textContent=Re),K.forEach(s),de=r(e),o(N.$$.fragment,e),fe=r(e),T=g(e,"DIV",{class:!0});var Je=w(T);o(Z.$$.fragment,Je),Pe=r(Je),te=g(Je,"P",{"data-svelte-h":!0}),U(te)!=="svelte-haxfgr"&&(te.textContent=Fe),Je.forEach(s),ue=r(e),o(D.$$.fragment,e),ge=r(e),k=g(e,"DIV",{class:!0});var Ce=w(k);o(B.$$.fragment,Ce),Ve=r(Ce),se=g(Ce,"P",{"data-svelte-h":!0}),U(se)!=="svelte-suegrh"&&(se.innerHTML=Ge),Ce.forEach(s),ce=r(e),o(R.$$.fragment,e),_e=r(e),F=g(e,"DIV",{class:!0});var Ae=w(F);o(G.$$.fragment,Ae),Ae.forEach(s),he=r(e),o(H.$$.fragment,e),$e=r(e),X=g(e,"DIV",{class:!0});var We=w(X);o(z.$$.fragment,We),We.forEach(s),ye=r(e),o(A.$$.fragment,e),be=r(e),M=g(e,"DIV",{class:!0});var je=w(M);o(W.$$.fragment,je),Ee=r(je),ae=g(je,"P",{"data-svelte-h":!0}),U(ae)!=="svelte-rk2372"&&(ae.textContent=He),je.forEach(s),ve=r(e),o(q.$$.fragment,e),we=r(e),J=g(e,"DIV",{class:!0});var Le=w(J);o(S.$$.fragment,Le),Ne=r(Le),ne=g(Le,"P",{"data-svelte-h":!0}),U(ne)!=="svelte-11ct46x"&&(ne.innerHTML=Xe),Le.forEach(s),Ie=r(e),o(Q.$$.fragment,e),xe=r(e),b=g(e,"DIV",{class:!0});var ie=w(b);o(Y.$$.fragment,ie),Ze=r(ie),re=g(ie,"P",{"data-svelte-h":!0}),U(re)!=="svelte-owzrds"&&(re.textContent=ze),De=r(ie),o(j.$$.fragment,ie),ie.forEach(s),Te=r(e),o(O.$$.fragment,e),ke=r(e),oe=g(e,"P",{}),w(oe).forEach(s),this.h()},h(){I(c,"name","hf:doc:metadata"),I(c,"content",rt),I(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(b,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){_(document.head,c),a(e,P,t),a(e,v,t),a(e,h,t),l($,e,t),a(e,f,t),a(e,y,t),a(e,pe,t),l(V,e,t),a(e,me,t),a(e,x,t),l(E,x,null),_(x,Ue),_(x,ee),a(e,de,t),l(N,e,t),a(e,fe,t),a(e,T,t),l(Z,T,null),_(T,Pe),_(T,te),a(e,ue,t),l(D,e,t),a(e,ge,t),a(e,k,t),l(B,k,null),_(k,Ve),_(k,se),a(e,ce,t),l(R,e,t),a(e,_e,t),a(e,F,t),l(G,F,null),a(e,he,t),l(H,e,t),a(e,$e,t),a(e,X,t),l(z,X,null),a(e,ye,t),l(A,e,t),a(e,be,t),a(e,M,t),l(W,M,null),_(M,Ee),_(M,ae),a(e,ve,t),l(q,e,t),a(e,we,t),a(e,J,t),l(S,J,null),_(J,Ne),_(J,ne),a(e,Ie,t),l(Q,e,t),a(e,xe,t),a(e,b,t),l(Y,b,null),_(b,Ze),_(b,re),_(b,De),l(j,b,null),a(e,Te,t),l(O,e,t),a(e,ke,t),a(e,oe,t),Me=!0},p(e,[t]){const K={};t&2&&(K.$$scope={dirty:t,ctx:e}),j.$set(K)},i(e){Me||(p($.$$.fragment,e),p(V.$$.fragment,e),p(E.$$.fragment,e),p(N.$$.fragment,e),p(Z.$$.fragment,e),p(D.$$.fragment,e),p(B.$$.fragment,e),p(R.$$.fragment,e),p(G.$$.fragment,e),p(H.$$.fragment,e),p(z.$$.fragment,e),p(A.$$.fragment,e),p(W.$$.fragment,e),p(q.$$.fragment,e),p(S.$$.fragment,e),p(Q.$$.fragment,e),p(Y.$$.fragment,e),p(j.$$.fragment,e),p(O.$$.fragment,e),Me=!0)},o(e){m($.$$.fragment,e),m(V.$$.fragment,e),m(E.$$.fragment,e),m(N.$$.fragment,e),m(Z.$$.fragment,e),m(D.$$.fragment,e),m(B.$$.fragment,e),m(R.$$.fragment,e),m(G.$$.fragment,e),m(H.$$.fragment,e),m(z.$$.fragment,e),m(A.$$.fragment,e),m(W.$$.fragment,e),m(q.$$.fragment,e),m(S.$$.fragment,e),m(Q.$$.fragment,e),m(Y.$$.fragment,e),m(j.$$.fragment,e),m(O.$$.fragment,e),Me=!1},d(e){e&&(s(P),s(v),s(h),s(f),s(y),s(pe),s(me),s(x),s(de),s(fe),s(T),s(ue),s(ge),s(k),s(ce),s(_e),s(F),s(he),s($e),s(X),s(ye),s(be),s(M),s(ve),s(we),s(J),s(Ie),s(xe),s(b),s(Te),s(ke),s(oe)),s(c),d($,e),d(V,e),d(E),d(N,e),d(Z),d(D,e),d(B),d(R,e),d(G),d(H,e),d(z),d(A,e),d(W),d(q,e),d(S),d(Q,e),d(Y),d(j),d(O,e)}}}const rt='{"title":"Utilities","local":"utilities","sections":[{"title":"numpy_to_pil","local":"diffusers.utils.numpy_to_pil","sections":[],"depth":2},{"title":"pt_to_pil","local":"diffusers.utils.pt_to_pil","sections":[],"depth":2},{"title":"load_image","local":"diffusers.utils.load_image","sections":[],"depth":2},{"title":"export_to_gif","local":"diffusers.utils.export_to_gif","sections":[],"depth":2},{"title":"export_to_video","local":"diffusers.utils.export_to_video","sections":[],"depth":2},{"title":"make_image_grid","local":"diffusers.utils.make_image_grid","sections":[],"depth":2},{"title":"randn_tensor","local":"diffusers.utils.torch_utils.randn_tensor","sections":[],"depth":2},{"title":"apply_layerwise_casting","local":"diffusers.hooks.apply_layerwise_casting","sections":[],"depth":2}],"depth":1}';function it(le){return Se(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ut extends Ye{constructor(c){super(),Oe(this,c,it,nt,qe,{})}}export{ut as component};
