Buckets:
| import"../chunks/DsnmJJEf.js";import{i as Ue,h as je,C as We,H as z,c as Ge,D as t,E as Ve,s as Ie,a as p}from"../chunks/BtE7mKSK.js";import{p as Ce,o as Re,s as e,f as c,a as d,b as Ne,c as o,d as u,n,r as s}from"../chunks/jDjavuwI.js";import{E as m}from"../chunks/SrSJA0zO.js";const ze='{"title":"Models","local":"models","sections":[{"title":"ModelMixin","local":"diffusers.ModelMixin","sections":[],"depth":2},{"title":"PushToHubMixin","local":"diffusers.utils.PushToHubMixin","sections":[],"depth":2}],"depth":1}';var Fe=u('<meta name="hf:doc:metadata"/>'),F=u("<p>Example:</p> <!>",1),He=u('<p>Using <a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin.enable_layerwise_casting">enable_layerwise_casting()</a>:</p> <!>',1),oe=u("<p>Examples:</p> <!>",1),Be=u("<p>If you get the error message below, you need to finetune the weights for your downstream task:</p> <!>",1),Xe=u(`<p></p> <!> <!> <p>🤗 Diffusers provides pretrained models for popular algorithms and modules to create custom diffusion systems. The primary function of models is to denoise an input sample as modeled by the distribution <!>.</p> <p>All models are built from the base <a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a> class which is a <a href="https://pytorch.org/docs/stable/generated/torch.nn.Module.html" rel="nofollow"><code>torch.nn.Module</code></a> providing basic functionality for saving and loading models, locally and from the Hugging Face Hub.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Base class for all models.</p> <p><a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a> takes care of storing the model configuration and provides methods for loading, downloading and | |
| saving models.</p> <ul><li><strong>config_name</strong> (<code>str</code>) — Filename to save a model to when calling <a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin.save_pretrained">save_pretrained()</a>.</li></ul> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Compiles <em>only</em> the frequently repeated sub-modules of a model (e.g. the Transformer layers) instead of | |
| compiling the entire model. This technique—often called <strong>regional compilation</strong> (see the PyTorch recipe <a href="https://docs.pytorch.org/tutorials/recipes/regional_compilation.html" rel="nofollow">https://docs.pytorch.org/tutorials/recipes/regional_compilation.html</a>) can reduce end-to-end compile time | |
| substantially, while preserving the runtime speed-ups you would expect from a full <code>torch.compile</code>.</p> <p>The set of sub-modules to compile is discovered by the presence of <strong><code>_repeated_blocks</code></strong> attribute in the | |
| model definition. Define this attribute on your model subclass as a list/tuple of class names (strings). Every | |
| module whose class name matches will be compiled.</p> <p>Once discovered, each matching sub-module is compiled by calling <code>submodule.compile(*args, **kwargs)</code>. Any | |
| positional or keyword arguments you supply to <code>compile_repeated_blocks</code> are forwarded verbatim to <code>torch.compile</code>.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A mock value for a dotted path (e.g. <code>torch.float32</code>): attribute access chains, | |
| calls behave as pass-through decorators, <code>repr</code> is the dotted path, and using it | |
| as a base class substitutes a plain-<code>type</code> base (PEP 560 <code>__mro_entries__</code>), so | |
| real subclasses keep a normal metaclass and <code>inspect.signature</code> reads their real <code>__init__</code> instead of a mock’s.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Potentially dequantize the model in case it has been quantized by a quantization method that support | |
| dequantization.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Deactivates gradient checkpointing for the current model (may be referred to as <em>activation checkpointing</em> or <em>checkpoint activations</em> in other frameworks).</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>disable npu flash attention from torch_npu</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Disable memory efficient attention from <a href="https://facebookresearch.github.io/xformers/" rel="nofollow">xFormers</a>.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Disable the flash attention pallals kernel for torch_xla.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Activates gradient checkpointing for the current model (may be referred to as <em>activation checkpointing</em> or <em>checkpoint activations</em> in other frameworks).</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Activates group offloading for the current model.</p> <p>See <a href="/docs/diffusers/pr_13881/en/api/utilities#diffusers.hooks.apply_group_offloading">apply_group_offloading()</a> for more information.</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Activates layerwise casting for the current model.</p> <p>Layerwise casting is a technique that casts the model weights to a lower precision dtype for storage but | |
| upcasts them on-the-fly to a higher precision dtype for computation. This process can significantly reduce the | |
| memory footprint from model weights, but may lead to some quality degradation in the outputs. Most degradations | |
| are negligible, mostly stemming from weight casting in normalization and modulation layers.</p> <p>By default, most models in diffusers set the <code>_skip_layerwise_casting_patterns</code> attribute to ignore patch | |
| embedding, positional embedding and normalization layers. This is because these layers are most likely | |
| precision-critical for quality. If you wish to change this behavior, you can set the <code>_skip_layerwise_casting_patterns</code> attribute to <code>None</code>, or call <a href="/docs/diffusers/pr_13881/en/api/utilities#diffusers.hooks.apply_layerwise_casting">apply_layerwise_casting()</a> with custom arguments.</p> <p>Example:</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Enable npu flash attention from torch_npu</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Enable memory efficient attention from <a href="https://facebookresearch.github.io/xformers/" rel="nofollow">xFormers</a>.</p> <p>When this option is enabled, you should observe lower GPU memory usage and a potential speed up during | |
| inference. Speed up during training is not guaranteed.</p> <blockquote class="warning"><p>> ⚠️ When memory efficient attention and sliced attention are both enabled, memory efficient | |
| attention takes > precedent.</p></blockquote> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Enable the flash attention pallals kernel for torch_xla.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Instantiate a pretrained PyTorch model from a pretrained model configuration.</p> <p>The model is set in evaluation mode - <code>model.eval()</code> - by default, and dropout modules are deactivated. To | |
| train the model, set it back in training mode with <code>model.train()</code>.</p> <blockquote class="tip"><p>> To use private or <a href="https://huggingface.co/docs/hub/models-gated#gated-models" rel="nofollow">gated models</a>, log-in | |
| with <code>hf > auth login</code>. You can also activate the special > <a href="https://huggingface.co/diffusers/installation.html#offline-mode" rel="nofollow">“offline-mode”</a> to use this method in a > | |
| firewalled environment.</p></blockquote> <!> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get the memory footprint of a model. This will return the memory footprint of the current model in bytes. | |
| Useful to benchmark the memory footprint of the current model and design some tests. Solution inspired from the | |
| PyTorch discussions: <a href="https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2" rel="nofollow">https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2</a></p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get number of (trainable or non-embedding) parameters in the module.</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Resets the attention backend for the model. Following calls to <code>forward</code> will use the environment default, if | |
| set, or the torch native scaled dot product attention.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Save a model and its configuration file to a directory so that it can be reloaded using the <a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin.from_pretrained">from_pretrained()</a> class method.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Set the attention backend for the model.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Set the switch for the npu flash attention.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A mock value for a dotted path (e.g. <code>torch.float32</code>): attribute access chains, | |
| calls behave as pass-through decorators, <code>repr</code> is the dotted path, and using it | |
| as a base class substitutes a plain-<code>type</code> base (PEP 560 <code>__mro_entries__</code>), so | |
| real subclasses keep a normal metaclass and <code>inspect.signature</code> reads their real <code>__init__</code> instead of a mock’s.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A Mixin to push a model, scheduler, or pipeline to the Hugging Face Hub.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Upload model, scheduler, or pipeline files to the 🤗 Hugging Face Hub.</p> <!></div></div> <!> <p></p>`,1);function Le(se,te){Ce(te,!1),Re(()=>{new URLSearchParams(window.location.search).get("fw")}),Ue();var H=Xe();je("13hezzs",r=>{var l=Fe();Ie(l,"content",ze),d(r,l)});var B=e(c(H),2);We(B,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var X=e(B,2);z(X,{title:"Models",local:"models",headingTag:"h1"});var h=e(X,2),ae=e(o(h));Ge(ae,()=>'<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>p</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msub><mi mathvariant="normal">∣</mi><msub><mi>x</mi><mi>t</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p_{\\theta}(x_{t-1}|x_{t})</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">p</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.0278em;">θ</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2083em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span>'),n(),s(h);var E=e(h,4);z(E,{title:"ModelMixin",local:"diffusers.ModelMixin",headingTag:"h2"});var f=e(E,2),Y=o(f);t(Y,{name:"class diffusers.ModelMixin",anchor:"diffusers.ModelMixin",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L232",parameters:[]});var g=e(Y,8),ne=o(g);t(ne,{name:"compile_repeated_blocks",anchor:"diffusers.ModelMixin.compile_repeated_blocks",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L1586",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),n(6),s(g);var b=e(g,2),re=o(b);t(re,{name:"cuda",anchor:"diffusers.ModelMixin.cuda",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),n(2),s(b);var _=e(b,2),ie=o(_);t(ie,{name:"dequantize",anchor:"diffusers.ModelMixin.dequantize",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L862",parameters:[]}),n(2),s(_);var y=e(_,2),le=o(y);t(le,{name:"disable_gradient_checkpointing",anchor:"diffusers.ModelMixin.disable_gradient_checkpointing",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L315",parameters:[]}),n(2),s(y);var v=e(y,2),de=o(v);t(de,{name:"disable_npu_flash_attention",anchor:"diffusers.ModelMixin.disable_npu_flash_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L346",parameters:[]}),n(2),s(v);var M=e(v,2),ce=o(M);t(ce,{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.ModelMixin.disable_xformers_memory_efficient_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L429",parameters:[]}),n(2),s(M);var x=e(M,2),pe=o(x);t(pe,{name:"disable_xla_flash_attention",anchor:"diffusers.ModelMixin.disable_xla_flash_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L376",parameters:[]}),n(2),s(x);var w=e(x,2),me=o(w);t(me,{name:"enable_gradient_checkpointing",anchor:"diffusers.ModelMixin.enable_gradient_checkpointing",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L285",parameters:[{name:"gradient_checkpointing_func",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.ModelMixin.enable_gradient_checkpointing.gradient_checkpointing_func",description:`<strong>gradient_checkpointing_func</strong> (<code>Callable</code>, <em>optional</em>) — | |
| The function to use for gradient checkpointing. If <code>None</code>, the default PyTorch checkpointing function | |
| is used (<code>torch.utils.checkpoint.checkpoint</code>).`,name:"gradient_checkpointing_func"}]}),n(2),s(w);var k=e(w,2),q=o(k);t(q,{name:"enable_group_offload",anchor:"diffusers.ModelMixin.enable_group_offload",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L520",parameters:[{name:"onload_device",val:": device"},{name:"offload_device",val:": device = torch.device()"},{name:"offload_type",val:": str = 'block_level'"},{name:"num_blocks_per_group",val:": int | None = None"},{name:"non_blocking",val:": bool = False"},{name:"use_stream",val:": bool = False"},{name:"record_stream",val:": bool = False"},{name:"low_cpu_mem_usage",val:" = False"},{name:"offload_to_disk_path",val:": str | None = None"},{name:"block_modules",val:": str | None = None"},{name:"exclude_kwargs",val:": str | None = None"}]});var ue=e(q,6);m(ue,{anchor:"diffusers.ModelMixin.enable_group_offload.example",children:(r,l)=>{var a=F(),i=e(c(a),2);p(i,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvZ1ZpZGVvWFRyYW5zZm9ybWVyM0RNb2RlbCUwQSUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJUSFVETSUyRkNvZ1ZpZGVvWC01YiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUwQSklMEElMEF0cmFuc2Zvcm1lci5lbmFibGVfZ3JvdXBfb2ZmbG9hZCglMEElMjAlMjAlMjAlMjBvbmxvYWRfZGV2aWNlJTNEdG9yY2guZGV2aWNlKCUyMmN1ZGElMjIpJTJDJTBBJTIwJTIwJTIwJTIwb2ZmbG9hZF9kZXZpY2UlM0R0b3JjaC5kZXZpY2UoJTIyY3B1JTIyKSUyQyUwQSUyMCUyMCUyMCUyMG9mZmxvYWRfdHlwZSUzRCUyMmxlYWZfbGV2ZWwlMjIlMkMlMEElMjAlMjAlMjAlMjB1c2Vfc3RyZWFtJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<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> <span class="hljs-string">"THUDM/CogVideoX-5b"</span>, subfolder=<span class="hljs-string">"transformer"</span>, torch_dtype=torch.bfloat16 | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>transformer.enable_group_offload( | |
| <span class="hljs-meta">... </span> onload_device=torch.device(<span class="hljs-string">"cuda"</span>), | |
| <span class="hljs-meta">... </span> offload_device=torch.device(<span class="hljs-string">"cpu"</span>), | |
| <span class="hljs-meta">... </span> offload_type=<span class="hljs-string">"leaf_level"</span>, | |
| <span class="hljs-meta">... </span> use_stream=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span>)`,lang:"python",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(k);var T=e(k,2),Q=o(T);t(Q,{name:"enable_layerwise_casting",anchor:"diffusers.ModelMixin.enable_layerwise_casting",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L435",parameters:[{name:"storage_dtype",val:": dtype = torch.float8_e4m3fn"},{name:"compute_dtype",val:": typing.Optional[torch.dtype] = None"},{name:"skip_modules_pattern",val:": tuple[str, ...] | None = None"},{name:"skip_modules_classes",val:": tuple[typing.Type[torch.nn.Module], ...] | None = None"},{name:"non_blocking",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.ModelMixin.enable_layerwise_casting.storage_dtype",description:`<strong>storage_dtype</strong> (<code>torch.dtype</code>) — | |
| The dtype to which the model should be cast for storage.`,name:"storage_dtype"},{anchor:"diffusers.ModelMixin.enable_layerwise_casting.compute_dtype",description:`<strong>compute_dtype</strong> (<code>torch.dtype</code>) — | |
| The dtype to which the model weights should be cast during the forward pass.`,name:"compute_dtype"},{anchor:"diffusers.ModelMixin.enable_layerwise_casting.skip_modules_pattern",description:`<strong>skip_modules_pattern</strong> (<code>tuple[str, ...]</code>, <em>optional</em>) — | |
| A list of patterns to match the names of the modules to skip during the layerwise casting process. If | |
| set to <code>None</code>, default skip patterns are used to ignore certain internal layers of modules and PEFT | |
| layers.`,name:"skip_modules_pattern"},{anchor:"diffusers.ModelMixin.enable_layerwise_casting.skip_modules_classes",description:`<strong>skip_modules_classes</strong> (<code>tuple[Type[torch.nn.Module], ...]</code>, <em>optional</em>) — | |
| A list of module classes to skip during the layerwise casting process.`,name:"skip_modules_classes"},{anchor:"diffusers.ModelMixin.enable_layerwise_casting.non_blocking",description:`<strong>non_blocking</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| If <code>True</code>, the weight casting operations are non-blocking.`,name:"non_blocking"}]});var he=e(Q,10);m(he,{anchor:"diffusers.ModelMixin.enable_layerwise_casting.example",children:(r,l)=>{var a=He(),i=e(c(a),2);p(i,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvZ1ZpZGVvWFRyYW5zZm9ybWVyM0RNb2RlbCUwQSUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJUSFVETSUyRkNvZ1ZpZGVvWC01YiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUwQSklMEElMEElMjMlMjBFbmFibGUlMjBsYXllcndpc2UlMjBjYXN0aW5nJTIwdmlhJTIwdGhlJTIwbW9kZWwlMkMlMjB3aGljaCUyMGlnbm9yZXMlMjBjZXJ0YWluJTIwbW9kdWxlcyUyMGJ5JTIwZGVmYXVsdCUwQXRyYW5zZm9ybWVyLmVuYWJsZV9sYXllcndpc2VfY2FzdGluZyhzdG9yYWdlX2R0eXBlJTNEdG9yY2guZmxvYXQ4X2U0bTNmbiUyQyUyMGNvbXB1dGVfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNik=",highlighted:`<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> <span class="hljs-string">"THUDM/CogVideoX-5b"</span>, subfolder=<span class="hljs-string">"transformer"</span>, torch_dtype=torch.bfloat16 | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Enable layerwise casting via the model, which ignores certain modules by default</span> | |
| <span class="hljs-meta">>>> </span>transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16)`,lang:"python",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(T);var Z=e(T,2),fe=o(Z);t(fe,{name:"enable_npu_flash_attention",anchor:"diffusers.ModelMixin.enable_npu_flash_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L339",parameters:[]}),n(2),s(Z);var J=e(Z,2),L=o(J);t(L,{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.ModelMixin.enable_xformers_memory_efficient_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L397",parameters:[{name:"attention_op",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.ModelMixin.enable_xformers_memory_efficient_attention.attention_op",description:`<strong>attention_op</strong> (<code>Callable</code>, <em>optional</em>) — | |
| Override the default <code>None</code> operator for use as <code>op</code> argument to the | |
| <a href="https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention" rel="nofollow"><code>memory_efficient_attention()</code></a> | |
| function of xFormers.`,name:"attention_op"}]});var ge=e(L,8);m(ge,{anchor:"diffusers.ModelMixin.enable_xformers_memory_efficient_attention.example",children:(r,l)=>{var a=oe(),i=e(c(a),2);p(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwlMEFmcm9tJTIweGZvcm1lcnMub3BzJTIwaW1wb3J0JTIwTWVtb3J5RWZmaWNpZW50QXR0ZW50aW9uRmxhc2hBdHRlbnRpb25PcCUwQSUwQW1vZGVsJTIwJTNEJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi0yLTElMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKSUwQW1vZGVsJTIwJTNEJTIwbW9kZWwudG8oJTIyY3VkYSUyMiklMEFtb2RlbC5lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24oYXR0ZW50aW9uX29wJTNETWVtb3J5RWZmaWNpZW50QXR0ZW50aW9uRmxhc2hBdHRlbnRpb25PcCk=",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> UNet2DConditionModel | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> xformers.ops <span class="hljs-keyword">import</span> MemoryEfficientAttentionFlashAttentionOp | |
| <span class="hljs-meta">>>> </span>model = UNet2DConditionModel.from_pretrained( | |
| <span class="hljs-meta">... </span> <span class="hljs-string">"stabilityai/stable-diffusion-2-1"</span>, subfolder=<span class="hljs-string">"unet"</span>, torch_dtype=torch.float16 | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>model = model.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>model.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)`,lang:"py",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(J);var U=e(J,2),be=o(U);t(be,{name:"enable_xla_flash_attention",anchor:"diffusers.ModelMixin.enable_xla_flash_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L370",parameters:[{name:"partition_spec",val:": typing.Optional[typing.Callable] = None"},{name:"**kwargs",val:""}]}),n(2),s(U);var j=e(U,2),S=o(j);t(S,{name:"from_pretrained",anchor:"diffusers.ModelMixin.from_pretrained",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L874",parameters:[{name:"pretrained_model_name_or_path",val:": str | os.PathLike | None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModelMixin.from_pretrained.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code>, <em>optional</em>) — | |
| Can be either:</p> | |
| <ul> | |
| <li>A string, the <em>model id</em> (for example <code>google/ddpm-celebahq-256</code>) of a pretrained model hosted on | |
| the Hub.</li> | |
| <li>A path to a <em>directory</em> (for example <code>./my_model_directory</code>) containing the model weights saved | |
| with <a href="/docs/diffusers/pr_13881/en/api/models/overview#diffusers.ModelMixin.save_pretrained">save_pretrained()</a>.</li> | |
| </ul>`,name:"pretrained_model_name_or_path"},{anchor:"diffusers.ModelMixin.from_pretrained.cache_dir",description:`<strong>cache_dir</strong> (<code>str | os.PathLike</code>, <em>optional</em>) — | |
| Path to a directory where a downloaded pretrained model configuration is cached if the standard cache | |
| is not used.`,name:"cache_dir"},{anchor:"diffusers.ModelMixin.from_pretrained.torch_dtype",description:`<strong>torch_dtype</strong> (<code>torch.dtype</code>, <em>optional</em>) — | |
| Override the default <code>torch.dtype</code> and load the model with another dtype.`,name:"torch_dtype"},{anchor:"diffusers.ModelMixin.from_pretrained.force_download",description:`<strong>force_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to force the (re-)download of the model weights and configuration files, overriding the | |
| cached versions if they exist.`,name:"force_download"},{anchor:"diffusers.ModelMixin.from_pretrained.proxies",description:`<strong>proxies</strong> (<code>dict[str, str]</code>, <em>optional</em>) — | |
| A dictionary of proxy servers to use by protocol or endpoint, for example, <code>{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}</code>. The proxies are used on each request.`,name:"proxies"},{anchor:"diffusers.ModelMixin.from_pretrained.output_loading_info",description:`<strong>output_loading_info</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.`,name:"output_loading_info"},{anchor:"diffusers.ModelMixin.from_pretrained.local_files_only(bool,",description:`<strong>local_files_only(<code>bool</code>,</strong> <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to only load local model weights and configuration files or not. If set to <code>True</code>, the model | |
| won’t be downloaded from the Hub.`,name:"local_files_only(bool,"},{anchor:"diffusers.ModelMixin.from_pretrained.token",description:`<strong>token</strong> (<code>str</code> or <em>bool</em>, <em>optional</em>) — | |
| The token to use as HTTP bearer authorization for remote files. If <code>True</code>, the token generated from | |
| <code>diffusers-cli login</code> (stored in <code>~/.huggingface</code>) is used.`,name:"token"},{anchor:"diffusers.ModelMixin.from_pretrained.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"main"</code>) — | |
| The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier | |
| allowed by Git.`,name:"revision"},{anchor:"diffusers.ModelMixin.from_pretrained.from_flax",description:`<strong>from_flax</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Load the model weights from a Flax checkpoint save file.`,name:"from_flax"},{anchor:"diffusers.ModelMixin.from_pretrained.subfolder",description:`<strong>subfolder</strong> (<code>str</code>, <em>optional</em>, defaults to <code>""</code>) — | |
| The subfolder location of a model file within a larger model repository on the Hub or locally.`,name:"subfolder"},{anchor:"diffusers.ModelMixin.from_pretrained.mirror",description:`<strong>mirror</strong> (<code>str</code>, <em>optional</em>) — | |
| Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not | |
| guarantee the timeliness or safety of the source, and you should refer to the mirror site for more | |
| information.`,name:"mirror"},{anchor:"diffusers.ModelMixin.from_pretrained.device_map",description:`<strong>device_map</strong> (<code>int | str | torch.device</code> or <code>dict[str, int | str | torch.device]</code>, <em>optional</em>) — | |
| A map that specifies where each submodule should go. It doesn’t need to be defined for each | |
| parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the | |
| same device. Defaults to <code>None</code>, meaning that the model will be loaded on CPU.</p> | |
| <p>Examples:`,name:"device_map"}]});var P=e(S,8);m(P,{anchor:"diffusers.ModelMixin.from_pretrained.example",children:(r,l)=>{var a=F(),i=e(c(a),2);p(i,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBdW5ldCUyMCUzRCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel | |
| unet = UNet2DConditionModel.from_pretrained(<span class="hljs-string">"stable-diffusion-v1-5/stable-diffusion-v1-5"</span>, subfolder=<span class="hljs-string">"unet"</span>)`,lang:"py",wrap:!1}),d(r,a)},$$slots:{default:!0}});var _e=e(P,2);m(_e,{anchor:"diffusers.ModelMixin.from_pretrained.example-2",children:(r,l)=>{var a=Be(),i=e(c(a),2);p(i,{code:"U29tZSUyMHdlaWdodHMlMjBvZiUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTIwd2VyZSUyMG5vdCUyMGluaXRpYWxpemVkJTIwZnJvbSUyMHRoZSUyMG1vZGVsJTIwY2hlY2twb2ludCUyMGF0JTIwc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIwYW5kJTIwYXJlJTIwbmV3bHklMjBpbml0aWFsaXplZCUyMGJlY2F1c2UlMjB0aGUlMjBzaGFwZXMlMjBkaWQlMjBub3QlMjBtYXRjaCUzQSUwQS0lMjBjb252X2luLndlaWdodCUzQSUyMGZvdW5kJTIwc2hhcGUlMjB0b3JjaC5TaXplKCU1QjMyMCUyQyUyMDQlMkMlMjAzJTJDJTIwMyU1RCklMjBpbiUyMHRoZSUyMGNoZWNrcG9pbnQlMjBhbmQlMjB0b3JjaC5TaXplKCU1QjMyMCUyQyUyMDklMkMlMjAzJTJDJTIwMyU1RCklMjBpbiUyMHRoZSUyMG1vZGVsJTIwaW5zdGFudGlhdGVkJTBBWW91JTIwc2hvdWxkJTIwcHJvYmFibHklMjBUUkFJTiUyMHRoaXMlMjBtb2RlbCUyMG9uJTIwYSUyMGRvd24tc3RyZWFtJTIwdGFzayUyMHRvJTIwYmUlMjBhYmxlJTIwdG8lMjB1c2UlMjBpdCUyMGZvciUyMHByZWRpY3Rpb25zJTIwYW5kJTIwaW5mZXJlbmNlLg==",highlighted:`Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match: | |
| - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) <span class="hljs-keyword">in</span> the checkpoint and torch.Size([320, 9, 3, 3]) <span class="hljs-keyword">in</span> the model instantiated | |
| You should probably TRAIN this model on a down-stream task to be able to use it <span class="hljs-keyword">for</span> predictions and inference.`,lang:"bash",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(j);var W=e(j,2),ye=o(W);t(ye,{name:"get_memory_footprint",anchor:"diffusers.ModelMixin.get_memory_footprint",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L2013",parameters:[{name:"return_buffers",val:" = True"}],parametersDescription:[{anchor:"diffusers.ModelMixin.get_memory_footprint.return_buffers",description:`<strong>return_buffers</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to return the size of the buffer tensors in the computation of the memory footprint. Buffers | |
| are tensors that do not require gradients and not registered as parameters. E.g. mean and std in batch | |
| norm layers. Please see: <a href="https://discuss.pytorch.org/t/what-pytorch-means-by-buffers/120266/2" rel="nofollow">https://discuss.pytorch.org/t/what-pytorch-means-by-buffers/120266/2</a>`,name:"return_buffers"}]}),n(2),s(W);var G=e(W,2),D=o(G);t(D,{name:"num_parameters",anchor:"diffusers.ModelMixin.num_parameters",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L1949",parameters:[{name:"only_trainable",val:": bool = False"},{name:"exclude_embeddings",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.ModelMixin.num_parameters.only_trainable",description:`<strong>only_trainable</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to return only the number of trainable parameters.`,name:"only_trainable"},{anchor:"diffusers.ModelMixin.num_parameters.exclude_embeddings",description:`<strong>exclude_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to return only the number of non-embedding parameters.`,name:"exclude_embeddings"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The number of parameters.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>int</code></p> | |
| `});var ve=e(D,4);m(ve,{anchor:"diffusers.ModelMixin.num_parameters.example",children:(r,l)=>{var a=F(),i=e(c(a),2);p(i,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEF1bmV0JTIwJTNEJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwc3ViZm9sZGVyJTNEJTIydW5ldCUyMiklMEF1bmV0Lm51bV9wYXJhbWV0ZXJzKG9ubHlfdHJhaW5hYmxlJTNEVHJ1ZSklMEE4NTk1MjA5NjQ=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel | |
| model_id = <span class="hljs-string">"stable-diffusion-v1-5/stable-diffusion-v1-5"</span> | |
| unet = UNet2DConditionModel.from_pretrained(model_id, subfolder=<span class="hljs-string">"unet"</span>) | |
| unet.num_parameters(only_trainable=<span class="hljs-literal">True</span>) | |
| <span class="hljs-number">859520964</span>`,lang:"py",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(G);var V=e(G,2),Me=o(V);t(Me,{name:"reset_attention_backend",anchor:"diffusers.ModelMixin.reset_attention_backend",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L650",parameters:[]}),n(2),s(V);var I=e(V,2),xe=o(I);t(xe,{name:"save_pretrained",anchor:"diffusers.ModelMixin.save_pretrained",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L669",parameters:[{name:"save_directory",val:": str | os.PathLike"},{name:"is_main_process",val:": bool = True"},{name:"save_function",val:": typing.Optional[typing.Callable] = None"},{name:"safe_serialization",val:": bool = True"},{name:"variant",val:": str | None = None"},{name:"max_shard_size",val:": int | str = '10GB'"},{name:"push_to_hub",val:": bool = False"},{name:"use_flashpack",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.ModelMixin.save_pretrained.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) — | |
| Directory to save a model and its configuration file to. Will be created if it doesn’t exist.`,name:"save_directory"},{anchor:"diffusers.ModelMixin.save_pretrained.is_main_process",description:`<strong>is_main_process</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether the process calling this is the main process or not. Useful during distributed training and you | |
| need to call this function on all processes. In this case, set <code>is_main_process=True</code> only on the main | |
| process to avoid race conditions.`,name:"is_main_process"},{anchor:"diffusers.ModelMixin.save_pretrained.save_function",description:`<strong>save_function</strong> (<code>Callable</code>) — | |
| The function to use to save the state dictionary. Useful during distributed training when you need to | |
| replace <code>torch.save</code> with another method. Can be configured with the environment variable | |
| <code>DIFFUSERS_SAVE_MODE</code>.`,name:"save_function"},{anchor:"diffusers.ModelMixin.save_pretrained.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to save the model using <code>safetensors</code> or the traditional PyTorch way with <code>pickle</code>.`,name:"safe_serialization"},{anchor:"diffusers.ModelMixin.save_pretrained.variant",description:`<strong>variant</strong> (<code>str</code>, <em>optional</em>) — | |
| If specified, weights are saved in the format <code>pytorch_model.<variant>.bin</code>.`,name:"variant"},{anchor:"diffusers.ModelMixin.save_pretrained.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, defaults to <code>"10GB"</code>) — | |
| The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size | |
| lower than this size. If expressed as a string, needs to be digits followed by a unit (like <code>"5GB"</code>). | |
| If expressed as an integer, the unit is bytes. Note that this limit will be decreased after a certain | |
| period of time (starting from Oct 2024) to allow users to upgrade to the latest version of <code>diffusers</code>. | |
| This is to establish a common default size for this argument across different libraries in the Hugging | |
| Face ecosystem (<code>transformers</code>, and <code>accelerate</code>, for example).`,name:"max_shard_size"},{anchor:"diffusers.ModelMixin.save_pretrained.push_to_hub",description:`<strong>push_to_hub</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the | |
| repository you want to push to with <code>repo_id</code> (will default to the name of <code>save_directory</code> in your | |
| namespace).`,name:"push_to_hub"},{anchor:"diffusers.ModelMixin.save_pretrained.kwargs",description:`<strong>kwargs</strong> (<code>dict[str, Any]</code>, <em>optional</em>) — | |
| Additional keyword arguments passed along to the <a href="/docs/diffusers/pr_13881/en/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub">push_to_hub()</a> method.`,name:"kwargs"}]}),n(2),s(I);var C=e(I,2),we=o(C);t(we,{name:"set_attention_backend",anchor:"diffusers.ModelMixin.set_attention_backend",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L588",parameters:[{name:"backend",val:": str"}],parametersDescription:[{anchor:"diffusers.ModelMixin.set_attention_backend.backend",description:`<strong>backend</strong> (<code>str</code>) — | |
| The name of the backend to set. Must be one of the available backends defined in | |
| <code>AttentionBackendName</code>. Available backends can be found in | |
| <code>diffusers.attention_dispatch.AttentionBackendName</code>. Defaults to torch native scaled dot product | |
| attention as backend.`,name:"backend"}]}),n(2),s(C);var R=e(C,2),ke=o(R);t(ke,{name:"set_use_npu_flash_attention",anchor:"diffusers.ModelMixin.set_use_npu_flash_attention",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/models/modeling_utils.py#L323",parameters:[{name:"valid",val:": bool"}]}),n(2),s(R);var A=e(R,2),Te=o(A);t(Te,{name:"to",anchor:"diffusers.ModelMixin.to",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),n(2),s(A),s(f);var $=e(f,2);z($,{title:"PushToHubMixin",local:"diffusers.utils.PushToHubMixin",headingTag:"h2"});var N=e($,2),O=o(N);t(O,{name:"class diffusers.utils.PushToHubMixin",anchor:"diffusers.utils.PushToHubMixin",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/utils/hub_utils.py#L483",parameters:[]});var K=e(O,4),ee=o(K);t(ee,{name:"push_to_hub",anchor:"diffusers.utils.PushToHubMixin.push_to_hub",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/utils/hub_utils.py#L518",parameters:[{name:"repo_id",val:": str"},{name:"commit_message",val:": str | None = None"},{name:"private",val:": bool | None = None"},{name:"token",val:": str | None = None"},{name:"create_pr",val:": bool = False"},{name:"safe_serialization",val:": bool = True"},{name:"variant",val:": str | None = None"},{name:"subfolder",val:": str | None = None"}],parametersDescription:[{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.repo_id",description:`<strong>repo_id</strong> (<code>str</code>) — | |
| The name of the repository you want to push your model, scheduler, or pipeline files to. It should | |
| contain your organization name when pushing to an organization. <code>repo_id</code> can also be a path to a local | |
| directory.`,name:"repo_id"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.commit_message",description:`<strong>commit_message</strong> (<code>str</code>, <em>optional</em>) — | |
| Message to commit while pushing. Default to <code>"Upload {object}"</code>.`,name:"commit_message"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.private",description:`<strong>private</strong> (<code>bool</code>, <em>optional</em>) — | |
| Whether to make the repo private. If <code>None</code> (default), the repo will be public unless the | |
| organization’s default is private. This value is ignored if the repo already exists.`,name:"private"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.token",description:`<strong>token</strong> (<code>str</code>, <em>optional</em>) — | |
| The token to use as HTTP bearer authorization for remote files. The token generated when running <code>hf auth login</code> (stored in <code>~/.huggingface</code>).`,name:"token"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.create_pr",description:`<strong>create_pr</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to create a PR with the uploaded files or directly commit.`,name:"create_pr"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether or not to convert the model weights to the <code>safetensors</code> format.`,name:"safe_serialization"},{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.variant",description:`<strong>variant</strong> (<code>str</code>, <em>optional</em>) — | |
| If specified, weights are saved in the format <code>pytorch_model.<variant>.bin</code>.`,name:"variant"}]});var Ze=e(ee,4);m(Ze,{anchor:"diffusers.utils.PushToHubMixin.push_to_hub.example",children:(r,l)=>{var a=oe(),i=e(c(a),2);p(i,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBdW5ldCUyMCUzRCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24tMiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnVuZXQlMjIpJTBBJTBBJTIzJTIwUHVzaCUyMHRoZSUyMCU2MHVuZXQlNjAlMjB0byUyMHlvdXIlMjBuYW1lc3BhY2UlMjB3aXRoJTIwdGhlJTIwbmFtZSUyMCUyMm15LWZpbmV0dW5lZC11bmV0JTIyLiUwQXVuZXQucHVzaF90b19odWIoJTIybXktZmluZXR1bmVkLXVuZXQlMjIpJTBBJTBBJTIzJTIwUHVzaCUyMHRoZSUyMCU2MHVuZXQlNjAlMjB0byUyMGFuJTIwb3JnYW5pemF0aW9uJTIwd2l0aCUyMHRoZSUyMG5hbWUlMjAlMjJteS1maW5ldHVuZWQtdW5ldCUyMi4lMEF1bmV0LnB1c2hfdG9faHViKCUyMnlvdXItb3JnJTJGbXktZmluZXR1bmVkLXVuZXQlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel | |
| unet = UNet2DConditionModel.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-2"</span>, subfolder=<span class="hljs-string">"unet"</span>) | |
| <span class="hljs-comment"># Push the \`unet\` to your namespace with the name "my-finetuned-unet".</span> | |
| unet.push_to_hub(<span class="hljs-string">"my-finetuned-unet"</span>) | |
| <span class="hljs-comment"># Push the \`unet\` to an organization with the name "my-finetuned-unet".</span> | |
| unet.push_to_hub(<span class="hljs-string">"your-org/my-finetuned-unet"</span>)`,lang:"python",wrap:!1}),d(r,a)},$$slots:{default:!0}}),s(K),s(N);var Je=e(N,2);Ve(Je,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/overview.md"}),n(2),d(se,H),Ne()}export{Le as component}; | |
Xet Storage Details
- Size:
- 47.1 kB
- Xet hash:
- fa0265b654d7bc8812ba1971319825fb5cc81f28ff75190e65b6b3fe3f602088
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.