Buckets:

download
raw
15.5 kB
import"../chunks/DsnmJJEf.js";import{i as w,h as A,C as y,H as r,a as k,D as t,E as q,s as z}from"../chunks/BtE7mKSK.js";import{p as J,o as R,s as e,f as I,a as g,b as V,c as a,d as v,r as s,n as T}from"../chunks/jDjavuwI.js";const Z='{"title":"WanAnimate2Transformer3DModel","local":"wananimate2transformer3dmodel","sections":[{"title":"WanAnimate2Transformer3DModel","local":"diffusers.WanAnimate2Transformer3DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';var N=v('<meta name="hf:doc:metadata"/>'),O=v(`<p></p> <!> <!> <p>A Diffusion Transformer model for 3D video-like data used in <a href="https://github.com/Wan-Video/Wan2.2" rel="nofollow">Wan-Animate-2</a> by the Alibaba Wan Team. It animates a character image with the motion of a driving video through an in-context reference mechanism: each segment first runs a reference pass (<code>kv_cache_mode="extract"</code>) that caches every layer’s reference K/V, then the denoising passes (<code>kv_cache_mode="cached"</code>) attend jointly over the generation tokens and the cached reference tokens through a flex <code>BlockMask</code>.</p> <p>The model can be loaded with the following code snippet.</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>A Transformer model for video-like data used in the Wan-Animate-2 model.</p> <p>Wan-Animate-2 uses an in-context attention mechanism with a KV cache: a reference video is first encoded
(<code>kv_cache_mode="extract"</code>) to populate a [<em>WanAnimate2KVCache</em>], then each denoising step
(<code>kv_cache_mode="cached"</code>) attends jointly over the generation tokens and the cached reference K/V through a flex <code>BlockMask</code>. The generation self-attention therefore runs on the <code>flex</code> attention backend only; every other
attention in the model works on any backend.</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"><!></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>The output of <a href="/docs/diffusers/pr_14539/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.</p></div> <!> <p></p>`,1);function C(b,x){J(x,!1),R(()=>{new URLSearchParams(window.location.search).get("fw")}),w();var d=O();A("1op7i3w",_=>{var p=N();z(p,"content",Z),g(_,p)});var i=e(I(d),2);y(i,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var m=e(i,2);r(m,{title:"WanAnimate2Transformer3DModel",local:"wananimate2transformer3dmodel",headingTag:"h1"});var c=e(m,6);k(c,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFdhbkFuaW1hdGUyVHJhbnNmb3JtZXIzRE1vZGVsJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBXYW5BbmltYXRlMlRyYW5zZm9ybWVyM0RNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyV2FuLUFJJTJGV2FuMi4yLUFuaW1hdGUtMi0xNEItRGlmZnVzZXJzJTIyJTJDJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmJmbG9hdDE2KQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> WanAnimate2Transformer3DModel
transformer = WanAnimate2Transformer3DModel.from_pretrained(<span class="hljs-string">&quot;Wan-AI/Wan2.2-Animate-2-14B-Diffusers&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, dtype=torch.bfloat16)`,lang:"python",wrap:!1});var f=e(c,2);r(f,{title:"WanAnimate2Transformer3DModel",local:"diffusers.WanAnimate2Transformer3DModel",headingTag:"h2"});var n=e(f,2),l=a(n);t(l,{name:"class diffusers.WanAnimate2Transformer3DModel",anchor:"diffusers.WanAnimate2Transformer3DModel",source:"https://github.com/huggingface/diffusers/blob/vr_14539/src/diffusers/models/transformers/transformer_wan_animate_2.py#L570",parameters:[{name:"patch_size",val:": tuple = (1, 2, 2)"},{name:"text_len",val:": int = 512"},{name:"in_dim",val:": int = 36"},{name:"dim",val:": int = 5120"},{name:"ffn_dim",val:": int = 13824"},{name:"freq_dim",val:": int = 256"},{name:"text_dim",val:": int = 4096"},{name:"out_dim",val:": int = 16"},{name:"num_heads",val:": int = 40"},{name:"num_layers",val:": int = 40"},{name:"cross_attn_norm",val:": bool = True"},{name:"eps",val:": float = 1e-06"},{name:"use_img_emb",val:": bool = True"},{name:"refer_offset_t",val:": int = 1"},{name:"refer_offset_h",val:": int = 0"},{name:"refer_offset_w",val:": int = -1"},{name:"refer_stride",val:": int = 1"}],parametersDescription:[{anchor:"diffusers.WanAnimate2Transformer3DModel.patch_size",description:`<strong>patch_size</strong> (<em>tuple[int]</em>, defaults to <em>(1, 2, 2)</em>) &#x2014;
3D patch dimensions for video embedding (t_patch, h_patch, w_patch).`,name:"patch_size"},{anchor:"diffusers.WanAnimate2Transformer3DModel.text_len",description:`<strong>text_len</strong> (<em>int</em>, defaults to <em>512</em>) &#x2014;
Fixed length for text embeddings.`,name:"text_len"},{anchor:"diffusers.WanAnimate2Transformer3DModel.in_dim",description:`<strong>in_dim</strong> (<em>int</em>, defaults to <em>36</em>) &#x2014;
The number of channels in the input (2 * latent_channels + 4 for mask channel).`,name:"in_dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.dim",description:`<strong>dim</strong> (<em>int</em>, defaults to <em>5120</em>) &#x2014;
The number of channels in the transformer.`,name:"dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.ffn_dim",description:`<strong>ffn_dim</strong> (<em>int</em>, defaults to <em>13824</em>) &#x2014;
Intermediate dimension in feed-forward network.`,name:"ffn_dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.freq_dim",description:`<strong>freq_dim</strong> (<em>int</em>, defaults to <em>256</em>) &#x2014;
Dimension for sinusoidal time embeddings.`,name:"freq_dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.text_dim",description:`<strong>text_dim</strong> (<em>int</em>, defaults to <em>4096</em>) &#x2014;
Input dimension for text embeddings.`,name:"text_dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.out_dim",description:`<strong>out_dim</strong> (<em>int</em>, defaults to <em>16</em>) &#x2014;
The number of channels in the output.`,name:"out_dim"},{anchor:"diffusers.WanAnimate2Transformer3DModel.num_heads",description:`<strong>num_heads</strong> (<em>int</em>, defaults to <em>40</em>) &#x2014;
The number of attention heads.`,name:"num_heads"},{anchor:"diffusers.WanAnimate2Transformer3DModel.num_layers",description:`<strong>num_layers</strong> (<em>int</em>, defaults to <em>40</em>) &#x2014;
The number of layers of transformer blocks to use.`,name:"num_layers"},{anchor:"diffusers.WanAnimate2Transformer3DModel.cross_attn_norm",description:`<strong>cross_attn_norm</strong> (<em>bool</em>, defaults to <em>True</em>) &#x2014;
Enable cross-attention normalization.`,name:"cross_attn_norm"},{anchor:"diffusers.WanAnimate2Transformer3DModel.eps",description:`<strong>eps</strong> (<em>float</em>, defaults to <em>1e-6</em>) &#x2014;
Epsilon value for normalization layers.`,name:"eps"},{anchor:"diffusers.WanAnimate2Transformer3DModel.use_img_emb",description:`<strong>use_img_emb</strong> (<em>bool</em>, defaults to <em>True</em>) &#x2014;
Whether to use CLIP image embedding.`,name:"use_img_emb"},{anchor:"diffusers.WanAnimate2Transformer3DModel.refer_offset_t",description:`<strong>refer_offset_t</strong> (<em>int</em>, defaults to <em>1</em>) &#x2014;
RoPE offset for the temporal dimension of the reference.`,name:"refer_offset_t"},{anchor:"diffusers.WanAnimate2Transformer3DModel.refer_offset_h",description:`<strong>refer_offset_h</strong> (<em>int</em>, defaults to <em>0</em>) &#x2014;
RoPE offset for the height dimension of the reference.`,name:"refer_offset_h"},{anchor:"diffusers.WanAnimate2Transformer3DModel.refer_offset_w",description:`<strong>refer_offset_w</strong> (<em>int</em>, defaults to <em>-1</em>) &#x2014;
RoPE offset for the width dimension of the reference. -1 means use the generation grid size.`,name:"refer_offset_w"},{anchor:"diffusers.WanAnimate2Transformer3DModel.refer_stride",description:`<strong>refer_stride</strong> (<em>int</em>, defaults to <em>1</em>) &#x2014;
Stride for RoPE application on the reference.`,name:"refer_stride"}]});var h=e(l,6),M=a(h);t(M,{name:"forward",anchor:"diffusers.WanAnimate2Transformer3DModel.forward",source:"https://github.com/huggingface/diffusers/blob/vr_14539/src/diffusers/models/transformers/transformer_wan_animate_2.py#L766",parameters:[{name:"hidden_states",val:": list"},{name:"timestep",val:": Tensor"},{name:"encoder_hidden_states",val:": list"},{name:"condition_latents",val:": list"},{name:"kv_cache",val:": WanAnimate2KVCache"},{name:"kv_cache_mode",val:": str"},{name:"seq_len",val:": int"},{name:"encoder_hidden_states_image",val:": typing.Optional[torch.Tensor] = None"},{name:"offset_grid_sizes",val:": typing.Optional[torch.Tensor] = None"},{name:"reference_grid_sizes",val:": typing.Optional[torch.Tensor] = None"},{name:"origin_len",val:": int | None = None"},{name:"origin_area",val:": list[int] | None = None"},{name:"is_uncondtion",val:": bool = False"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>list[torch.Tensor]</code>) &#x2014;
Latents for this pass &#x2014; the reference latents when <code>kv_cache_mode=&quot;extract&quot;</code>, the noisy generation
latents when <code>kv_cache_mode=&quot;cached&quot;</code>.`,name:"hidden_states"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.timestep",description:`<strong>timestep</strong> (<code>torch.Tensor</code>) &#x2014;
Denoising timestep. Ignored under <code>kv_cache_mode=&quot;extract&quot;</code>, which uses a fixed timestep of 1.`,name:"timestep"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>list[torch.Tensor]</code>) &#x2014;
Text embeddings for this pass.`,name:"encoder_hidden_states"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.condition_latents",description:`<strong>condition_latents</strong> (<code>list[torch.Tensor]</code>) &#x2014;
Conditioning latents concatenated to <code>hidden_states</code> before patch embedding.`,name:"condition_latents"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.kv_cache",description:`<strong>kv_cache</strong> (<code>WanAnimate2KVCache</code>) &#x2014;
Written under <code>kv_cache_mode=&quot;extract&quot;</code>, read under <code>&quot;cached&quot;</code>.`,name:"kv_cache"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.kv_cache_mode",description:`<strong>kv_cache_mode</strong> (<code>str</code>) &#x2014;
<code>&quot;extract&quot;</code> runs the reference pass and populates <code>kv_cache</code>; <code>&quot;cached&quot;</code> runs a denoising step against
the cached reference tokens.`,name:"kv_cache_mode"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.seq_len",description:`<strong>seq_len</strong> (<code>int</code>) &#x2014;
Token count each sample must hold after patch embedding.`,name:"seq_len"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.encoder_hidden_states_image",description:`<strong>encoder_hidden_states_image</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
CLIP image embeddings, used when the model is configured with <code>use_img_emb</code>.`,name:"encoder_hidden_states_image"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.offset_grid_sizes",description:`<strong>offset_grid_sizes</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Patch grid of the reference latents, used to resolve any <code>refer_offset_*</code> set to -1. Required under
<code>kv_cache_mode=&quot;extract&quot;</code>; under <code>&quot;cached&quot;</code>, <code>reference_grid_sizes</code> describes the same grid and is used
instead.`,name:"offset_grid_sizes"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.reference_grid_sizes",description:`<strong>reference_grid_sizes</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Patch grid of the reference latents, used for the reference rotary embeddings. Required under
<code>kv_cache_mode=&quot;cached&quot;</code>.`,name:"reference_grid_sizes"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.origin_len",description:`<strong>origin_len</strong> (<code>int</code>, <em>optional</em>) &#x2014;
Frame count of the full video, which the in-context block mask is built over. Required under
<code>kv_cache_mode=&quot;cached&quot;</code>.`,name:"origin_len"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.origin_area",description:`<strong>origin_area</strong> (<code>list[int]</code>, <em>optional</em>) &#x2014;
Spatial size <code>[height, width]</code> of the full video, which the in-context block mask is built over.
Required under <code>kv_cache_mode=&quot;cached&quot;</code>.`,name:"origin_area"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.is_uncondtion",description:`<strong>is_uncondtion</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether this is the unconditional branch of classifier-free guidance.`,name:"is_uncondtion"},{anchor:"diffusers.WanAnimate2Transformer3DModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to return a <code>~models.transformer_2d.Transformer2DModelOutput</code> instead of a plain tuple.`,name:"return_dict"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>The predicted sample per input latent, unpatchified; a plain tuple if <code>return_dict</code> is <code>False</code>.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p><a
href="/docs/diffusers/pr_14539/en/api/models/hunyuan_video15_transformer_3d#diffusers.models.modeling_outputs.Transformer2DModelOutput"
>Transformer2DModelOutput</a> or <code>tuple(list[torch.Tensor])</code></p>
`}),s(h),s(n);var u=e(n,2);r(u,{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"});var o=e(u,2),D=a(o);t(D,{name:"class diffusers.models.modeling_outputs.Transformer2DModelOutput",anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput",source:"https://github.com/huggingface/diffusers/blob/vr_14539/src/diffusers/models/modeling_outputs.py#L21",parameters:[{name:"sample",val:": torch.Tensor"}],parametersDescription:[{anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput.sample",description:`<strong>sample</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, height, width)</code> or <code>(batch size, num_vector_embeds - 1, num_latent_pixels)</code> if <a href="/docs/diffusers/pr_14539/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> is discrete) &#x2014;
The hidden states output conditioned on the <code>encoder_hidden_states</code> input. If discrete, returns probability
distributions for the unnoised latent pixels.`,name:"sample"}]}),T(2),s(o);var W=e(o,2);q(W,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/wan_animate_2_transformer_3d.md"}),T(2),g(b,d),V()}export{C as component};

Xet Storage Details

Size:
15.5 kB
·
Xet hash:
c16ee7bf2a06c350853d6bb749d6a6582de91a3c2e911e594822bd65e39410da

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.