Buckets:
| 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 o,A as Ke,h as g,f as s,c as r,j as w,u as i,x as U,k as I,y as _,a,v as l,d as p,t as d,w as m}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:",b,h,$;return h=new et({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBDb2dWaWRlb1hUcmFuc2Zvcm1lcjNETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKSUwQSUwQWFwcGx5X2xheWVyd2lzZV9jYXN0aW5nKCUwQSUyMCUyMCUyMCUyMHRyYW5zZm9ybWVyJTJDJTBBJTIwJTIwJTIwJTIwc3RvcmFnZV9kdHlwZSUzRHRvcmNoLmZsb2F0OF9lNG0zZm4lMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEElMjAlMjAlMjAlMjBza2lwX21vZHVsZXNfcGF0dGVybiUzRCU1QiUyMnBhdGNoX2VtYmVkJTIyJTJDJTIwJTIybm9ybSUyMiUyQyUyMCUyMnByb2pfb3V0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwbm9uX2Jsb2NraW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXTransformer3DModel | |
| <span class="hljs-meta">>>> </span>transformer = CogVideoXTransformer3DModel.from_pretrained( | |
| <span class="hljs-meta">... </span> model_id, subfolder=<span class="hljs-string">"transformer"</span>, torch_dtype=torch.bfloat16 | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </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">"patch_embed"</span>, <span class="hljs-string">"norm"</span>, <span class="hljs-string">"proj_out"</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,b=n(),o(h.$$.fragment)},l(f){c=g(f,"P",{"data-svelte-h":!0}),U(c)!=="svelte-11lpom8"&&(c.textContent=P),b=r(f),i(h.$$.fragment,f)},m(f,y){a(f,c,y),a(f,b,y),l(h,f,y),$=!0},p:Qe,i(f){$||(p(h.$$.fragment,f),$=!0)},o(f){d(h.$$.fragment,f),$=!1},d(f){f&&(s(c),s(b)),m(h,f)}}}function nt(le){let c,P,b,h,$,f,y,Be="Utility and helper functions for working with 🤗 Diffusers.",pe,V,de,x,E,Ue,ee,Re="Convert a numpy image or a batch of images to a PIL image.",me,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,ve,M,W,Ee,ae,He="Prepares a single grid of images. Useful for visualization purposes.",be,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,v,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,ie,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/vr_10766/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/vr_10766/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>) — | |
| 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>) — | |
| A conversion method to apply to the image after loading it. When set to <code>None</code> the image will be converted | |
| “RGB”.`,name:"convert_method"}],source:"https://github.com/huggingface/diffusers/blob/vr_10766/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/vr_10766/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/vr_10766/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/vr_10766/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/vr_10766/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>) — | |
| 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>) — | |
| 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>) — | |
| 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>"auto"</code>) — | |
| A list of patterns to match the names of the modules to skip during the layerwise casting process. If set | |
| to <code>"auto"</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>) — | |
| 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>) — | |
| If <code>True</code>, the weight casting operations are non-blocking.`,name:"non_blocking"}],source:"https://github.com/huggingface/diffusers/blob/vr_10766/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(),b=u("p"),h=n(),o($.$$.fragment),f=n(),y=u("p"),y.textContent=Be,pe=n(),o(V.$$.fragment),de=n(),x=u("div"),o(E.$$.fragment),Ue=n(),ee=u("p"),ee.textContent=Re,me=n(),o(N.$$.fragment),fe=n(),T=u("div"),o(Z.$$.fragment),Pe=n(),te=u("p"),te.textContent=Fe,ue=n(),o(D.$$.fragment),ge=n(),k=u("div"),o(B.$$.fragment),Ve=n(),se=u("p"),se.innerHTML=Ge,ce=n(),o(R.$$.fragment),_e=n(),F=u("div"),o(G.$$.fragment),he=n(),o(H.$$.fragment),$e=n(),X=u("div"),o(z.$$.fragment),ye=n(),o(A.$$.fragment),ve=n(),M=u("div"),o(W.$$.fragment),Ee=n(),ae=u("p"),ae.textContent=He,be=n(),o(q.$$.fragment),we=n(),J=u("div"),o(S.$$.fragment),Ne=n(),ne=u("p"),ne.innerHTML=Xe,Ie=n(),o(Q.$$.fragment),xe=n(),v=u("div"),o(Y.$$.fragment),Ze=n(),re=u("p"),re.textContent=ze,De=n(),o(j.$$.fragment),Te=n(),o(O.$$.fragment),ke=n(),ie=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),b=g(e,"P",{}),w(b).forEach(s),h=r(e),i($.$$.fragment,e),f=r(e),y=g(e,"P",{"data-svelte-h":!0}),U(y)!=="svelte-sj662i"&&(y.textContent=Be),pe=r(e),i(V.$$.fragment,e),de=r(e),x=g(e,"DIV",{class:!0});var K=w(x);i(E.$$.fragment,K),Ue=r(K),ee=g(K,"P",{"data-svelte-h":!0}),U(ee)!=="svelte-49eriv"&&(ee.textContent=Re),K.forEach(s),me=r(e),i(N.$$.fragment,e),fe=r(e),T=g(e,"DIV",{class:!0});var Je=w(T);i(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),i(D.$$.fragment,e),ge=r(e),k=g(e,"DIV",{class:!0});var Ce=w(k);i(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),i(R.$$.fragment,e),_e=r(e),F=g(e,"DIV",{class:!0});var Ae=w(F);i(G.$$.fragment,Ae),Ae.forEach(s),he=r(e),i(H.$$.fragment,e),$e=r(e),X=g(e,"DIV",{class:!0});var We=w(X);i(z.$$.fragment,We),We.forEach(s),ye=r(e),i(A.$$.fragment,e),ve=r(e),M=g(e,"DIV",{class:!0});var je=w(M);i(W.$$.fragment,je),Ee=r(je),ae=g(je,"P",{"data-svelte-h":!0}),U(ae)!=="svelte-rk2372"&&(ae.textContent=He),je.forEach(s),be=r(e),i(q.$$.fragment,e),we=r(e),J=g(e,"DIV",{class:!0});var Le=w(J);i(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),i(Q.$$.fragment,e),xe=r(e),v=g(e,"DIV",{class:!0});var oe=w(v);i(Y.$$.fragment,oe),Ze=r(oe),re=g(oe,"P",{"data-svelte-h":!0}),U(re)!=="svelte-owzrds"&&(re.textContent=ze),De=r(oe),i(j.$$.fragment,oe),oe.forEach(s),Te=r(e),i(O.$$.fragment,e),ke=r(e),ie=g(e,"P",{}),w(ie).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(v,"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,b,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,de,t),a(e,x,t),l(E,x,null),_(x,Ue),_(x,ee),a(e,me,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,ve,t),a(e,M,t),l(W,M,null),_(M,Ee),_(M,ae),a(e,be,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,v,t),l(Y,v,null),_(v,Ze),_(v,re),_(v,De),l(j,v,null),a(e,Te,t),l(O,e,t),a(e,ke,t),a(e,ie,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){d($.$$.fragment,e),d(V.$$.fragment,e),d(E.$$.fragment,e),d(N.$$.fragment,e),d(Z.$$.fragment,e),d(D.$$.fragment,e),d(B.$$.fragment,e),d(R.$$.fragment,e),d(G.$$.fragment,e),d(H.$$.fragment,e),d(z.$$.fragment,e),d(A.$$.fragment,e),d(W.$$.fragment,e),d(q.$$.fragment,e),d(S.$$.fragment,e),d(Q.$$.fragment,e),d(Y.$$.fragment,e),d(j.$$.fragment,e),d(O.$$.fragment,e),Me=!1},d(e){e&&(s(P),s(b),s(h),s(f),s(y),s(pe),s(de),s(x),s(me),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(ve),s(M),s(be),s(we),s(J),s(Ie),s(xe),s(v),s(Te),s(ke),s(ie)),s(c),m($,e),m(V,e),m(E),m(N,e),m(Z),m(D,e),m(B),m(R,e),m(G),m(H,e),m(z),m(A,e),m(W),m(q,e),m(S),m(Q,e),m(Y),m(j),m(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 ot(le){return Se(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ut extends Ye{constructor(c){super(),Oe(this,c,ot,nt,qe,{})}}export{ut as component}; | |
Xet Storage Details
- Size:
- 16.9 kB
- Xet hash:
- 5f5d62a620db3b50687d963c49a0ba2651bcf8dd1f6ca2a7f0b1230198c06b50
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.