Buckets:
| import"../chunks/DsnmJJEf.js";import{i as q,h as k,C as U,H as c,a as Z,D as o,E as z,s as N}from"../chunks/BtE7mKSK.js";import{p as j,o as I,s as e,f as J,a as v,b as W,c as t,d as x,n,r}from"../chunks/jDjavuwI.js";const O='{"title":"CogVideoXTransformer3DModel","local":"cogvideoxtransformer3dmodel","sections":[{"title":"CogVideoXTransformer3DModel","local":"diffusers.CogVideoXTransformer3DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';var R=x('<meta name="hf:doc:metadata"/>'),L=x(`<p></p> <!> <!> <p>A Diffusion Transformer model for 3D data from <a href="https://github.com/THUDM/CogVideo" rel="nofollow">CogVideoX</a> was introduced in <a href="https://github.com/THUDM/CogVideo/blob/main/resources/CogVideoX.pdf" rel="nofollow">CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer</a> by Tsinghua University & ZhipuAI.</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 in <a href="https://github.com/THUDM/CogVideo" rel="nofollow">CogVideoX</a>.</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>The <a href="/docs/diffusers/pr_14261/en/api/models/cogvideox_transformer3d#diffusers.CogVideoXTransformer3DModel">CogVideoXTransformer3DModel</a> forward 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>Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query, key, value) | |
| are fused. For cross-attention modules, key and value projection matrices are fused.</p> <blockquote class="warning"><p>> This API is 🧪 experimental.</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>Disables the fused QKV projection if enabled.</p> <blockquote class="warning"><p>> This API is 🧪 experimental.</p></blockquote></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_14261/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.</p></div> <!> <p></p>`,1);function S(y,D){j(D,!1),I(()=>{new URLSearchParams(window.location.search).get("fw")}),q();var m=L();k("s5vpeu",b=>{var T=R();N(T,"content",O),v(b,T)});var l=e(J(m),2);U(l,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var f=e(l,2);c(f,{title:"CogVideoXTransformer3DModel",local:"cogvideoxtransformer3dmodel",headingTag:"h1"});var p=e(f,6);Z(p,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvZ1ZpZGVvWFRyYW5zZm9ybWVyM0RNb2RlbCUwQSUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZGVvWC0yYiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMjJjdWRhJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXTransformer3DModel | |
| transformer = CogVideoXTransformer3DModel.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-2b"</span>, subfolder=<span class="hljs-string">"transformer"</span>, torch_dtype=torch.float16).to(<span class="hljs-string">"cuda"</span>)`,lang:"python",wrap:!1});var u=e(p,2);c(u,{title:"CogVideoXTransformer3DModel",local:"diffusers.CogVideoXTransformer3DModel",headingTag:"h2"});var s=e(u,2),h=t(s);o(h,{name:"class diffusers.CogVideoXTransformer3DModel",anchor:"diffusers.CogVideoXTransformer3DModel",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/models/transformers/cogvideox_transformer_3d.py#L160",parameters:[{name:"num_attention_heads",val:": int = 30"},{name:"attention_head_dim",val:": int = 64"},{name:"in_channels",val:": int = 16"},{name:"out_channels",val:": int | None = 16"},{name:"flip_sin_to_cos",val:": bool = True"},{name:"freq_shift",val:": int = 0"},{name:"time_embed_dim",val:": int = 512"},{name:"ofs_embed_dim",val:": int | None = None"},{name:"text_embed_dim",val:": int = 4096"},{name:"num_layers",val:": int = 30"},{name:"dropout",val:": float = 0.0"},{name:"attention_bias",val:": bool = True"},{name:"sample_width",val:": int = 90"},{name:"sample_height",val:": int = 60"},{name:"sample_frames",val:": int = 49"},{name:"patch_size",val:": int = 2"},{name:"patch_size_t",val:": int | None = None"},{name:"temporal_compression_ratio",val:": int = 4"},{name:"max_text_seq_length",val:": int = 226"},{name:"activation_fn",val:": str = 'gelu-approximate'"},{name:"timestep_activation_fn",val:": str = 'silu'"},{name:"norm_elementwise_affine",val:": bool = True"},{name:"norm_eps",val:": float = 1e-05"},{name:"spatial_interpolation_scale",val:": float = 1.875"},{name:"temporal_interpolation_scale",val:": float = 1.0"},{name:"use_rotary_positional_embeddings",val:": bool = False"},{name:"use_learned_positional_embeddings",val:": bool = False"},{name:"patch_bias",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.CogVideoXTransformer3DModel.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, defaults to <code>30</code>) — | |
| The number of heads to use for multi-head attention.`,name:"num_attention_heads"},{anchor:"diffusers.CogVideoXTransformer3DModel.attention_head_dim",description:`<strong>attention_head_dim</strong> (<code>int</code>, defaults to <code>64</code>) — | |
| The number of channels in each head.`,name:"attention_head_dim"},{anchor:"diffusers.CogVideoXTransformer3DModel.in_channels",description:`<strong>in_channels</strong> (<code>int</code>, defaults to <code>16</code>) — | |
| The number of channels in the input.`,name:"in_channels"},{anchor:"diffusers.CogVideoXTransformer3DModel.out_channels",description:`<strong>out_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16</code>) — | |
| The number of channels in the output.`,name:"out_channels"},{anchor:"diffusers.CogVideoXTransformer3DModel.flip_sin_to_cos",description:`<strong>flip_sin_to_cos</strong> (<code>bool</code>, defaults to <code>True</code>) — | |
| Whether to flip the sin to cos in the time embedding.`,name:"flip_sin_to_cos"},{anchor:"diffusers.CogVideoXTransformer3DModel.time_embed_dim",description:`<strong>time_embed_dim</strong> (<code>int</code>, defaults to <code>512</code>) — | |
| Output dimension of timestep embeddings.`,name:"time_embed_dim"},{anchor:"diffusers.CogVideoXTransformer3DModel.ofs_embed_dim",description:`<strong>ofs_embed_dim</strong> (<code>int</code>, defaults to <code>512</code>) — | |
| Output dimension of “ofs” embeddings used in CogVideoX-5b-I2B in version 1.5`,name:"ofs_embed_dim"},{anchor:"diffusers.CogVideoXTransformer3DModel.text_embed_dim",description:`<strong>text_embed_dim</strong> (<code>int</code>, defaults to <code>4096</code>) — | |
| Input dimension of text embeddings from the text encoder.`,name:"text_embed_dim"},{anchor:"diffusers.CogVideoXTransformer3DModel.num_layers",description:`<strong>num_layers</strong> (<code>int</code>, defaults to <code>30</code>) — | |
| The number of layers of Transformer blocks to use.`,name:"num_layers"},{anchor:"diffusers.CogVideoXTransformer3DModel.dropout",description:`<strong>dropout</strong> (<code>float</code>, defaults to <code>0.0</code>) — | |
| The dropout probability to use.`,name:"dropout"},{anchor:"diffusers.CogVideoXTransformer3DModel.attention_bias",description:`<strong>attention_bias</strong> (<code>bool</code>, defaults to <code>True</code>) — | |
| Whether to use bias in the attention projection layers.`,name:"attention_bias"},{anchor:"diffusers.CogVideoXTransformer3DModel.sample_width",description:`<strong>sample_width</strong> (<code>int</code>, defaults to <code>90</code>) — | |
| The width of the input latents.`,name:"sample_width"},{anchor:"diffusers.CogVideoXTransformer3DModel.sample_height",description:`<strong>sample_height</strong> (<code>int</code>, defaults to <code>60</code>) — | |
| The height of the input latents.`,name:"sample_height"},{anchor:"diffusers.CogVideoXTransformer3DModel.sample_frames",description:`<strong>sample_frames</strong> (<code>int</code>, defaults to <code>49</code>) — | |
| The number of frames in the input latents. Note that this parameter was incorrectly initialized to 49 | |
| instead of 13 because CogVideoX processed 13 latent frames at once in its default and recommended settings, | |
| but cannot be changed to the correct value to ensure backwards compatibility. To create a transformer with | |
| K latent frames, the correct value to pass here would be: ((K - 1) * temporal_compression_ratio + 1).`,name:"sample_frames"},{anchor:"diffusers.CogVideoXTransformer3DModel.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, defaults to <code>2</code>) — | |
| The size of the patches to use in the patch embedding layer.`,name:"patch_size"},{anchor:"diffusers.CogVideoXTransformer3DModel.temporal_compression_ratio",description:`<strong>temporal_compression_ratio</strong> (<code>int</code>, defaults to <code>4</code>) — | |
| The compression ratio across the temporal dimension. See documentation for <code>sample_frames</code>.`,name:"temporal_compression_ratio"},{anchor:"diffusers.CogVideoXTransformer3DModel.max_text_seq_length",description:`<strong>max_text_seq_length</strong> (<code>int</code>, defaults to <code>226</code>) — | |
| The maximum sequence length of the input text embeddings.`,name:"max_text_seq_length"},{anchor:"diffusers.CogVideoXTransformer3DModel.activation_fn",description:`<strong>activation_fn</strong> (<code>str</code>, defaults to <code>"gelu-approximate"</code>) — | |
| Activation function to use in feed-forward.`,name:"activation_fn"},{anchor:"diffusers.CogVideoXTransformer3DModel.timestep_activation_fn",description:`<strong>timestep_activation_fn</strong> (<code>str</code>, defaults to <code>"silu"</code>) — | |
| Activation function to use when generating the timestep embeddings.`,name:"timestep_activation_fn"},{anchor:"diffusers.CogVideoXTransformer3DModel.norm_elementwise_affine",description:`<strong>norm_elementwise_affine</strong> (<code>bool</code>, defaults to <code>True</code>) — | |
| Whether to use elementwise affine in normalization layers.`,name:"norm_elementwise_affine"},{anchor:"diffusers.CogVideoXTransformer3DModel.norm_eps",description:`<strong>norm_eps</strong> (<code>float</code>, defaults to <code>1e-5</code>) — | |
| The epsilon value to use in normalization layers.`,name:"norm_eps"},{anchor:"diffusers.CogVideoXTransformer3DModel.spatial_interpolation_scale",description:`<strong>spatial_interpolation_scale</strong> (<code>float</code>, defaults to <code>1.875</code>) — | |
| Scaling factor to apply in 3D positional embeddings across spatial dimensions.`,name:"spatial_interpolation_scale"},{anchor:"diffusers.CogVideoXTransformer3DModel.temporal_interpolation_scale",description:`<strong>temporal_interpolation_scale</strong> (<code>float</code>, defaults to <code>1.0</code>) — | |
| Scaling factor to apply in 3D positional embeddings across temporal dimensions.`,name:"temporal_interpolation_scale"}]});var a=e(h,4),M=t(a);o(M,{name:"forward",anchor:"diffusers.CogVideoXTransformer3DModel.forward",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/models/transformers/cogvideox_transformer_3d.py#L366",parameters:[{name:"hidden_states",val:": Tensor"},{name:"encoder_hidden_states",val:": Tensor"},{name:"timestep",val:": typing.Union[int, float, torch.LongTensor]"},{name:"timestep_cond",val:": typing.Optional[torch.Tensor] = None"},{name:"ofs",val:": typing.Union[int, float, torch.LongTensor, NoneType] = None"},{name:"image_rotary_emb",val:": tuple[torch.Tensor, torch.Tensor] | None = None"},{name:"attention_kwargs",val:": dict[str, typing.Any] | None = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.CogVideoXTransformer3DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_frames, channels, height, width)</code>) — | |
| Input <code>hidden_states</code>.`,name:"hidden_states"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_len, embed_dims)</code>) — | |
| Conditional embeddings (embeddings computed from the input conditions such as prompts) to use.`,name:"encoder_hidden_states"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.timestep",description:`<strong>timestep</strong> (<code>torch.LongTensor</code>) — | |
| Used to indicate denoising step.`,name:"timestep"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.timestep_cond",description:`<strong>timestep_cond</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Conditional embeddings for timestep. If provided, the embeddings will be summed with the samples passed | |
| through the <code>self.time_embedding</code> layer to obtain the final timestep embeddings.`,name:"timestep_cond"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.ofs",description:`<strong>ofs</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| Offset embeddings used in CogVideoX-5b-I2V.`,name:"ofs"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.image_rotary_emb",description:`<strong>image_rotary_emb</strong> (<code>tuple</code> of <code>torch.Tensor</code>, <em>optional</em>) — | |
| Pre-computed rotary positional embeddings.`,name:"image_rotary_emb"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.attention_kwargs",description:`<strong>attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) — | |
| A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under | |
| <code>self.processor</code> in | |
| <a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py" rel="nofollow">diffusers.models.attention_processor</a>.`,name:"attention_kwargs"},{anchor:"diffusers.CogVideoXTransformer3DModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether or not 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>If <code>return_dict</code> is True, an <code>~models.transformer_2d.Transformer2DModelOutput</code> is returned, otherwise a | |
| <code>tuple</code> where the first element is the sample tensor.</p> | |
| `}),n(2),r(a);var d=e(a,2),V=t(d);o(V,{name:"fuse_qkv_projections",anchor:"diffusers.CogVideoXTransformer3DModel.fuse_qkv_projections",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/models/transformers/cogvideox_transformer_3d.py#L335",parameters:[]}),n(4),r(d);var _=e(d,2),C=t(_);o(C,{name:"unfuse_qkv_projections",anchor:"diffusers.CogVideoXTransformer3DModel.unfuse_qkv_projections",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/models/transformers/cogvideox_transformer_3d.py#L357",parameters:[]}),n(4),r(_),r(s);var g=e(s,2);c(g,{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"});var i=e(g,2),w=t(i);o(w,{name:"class diffusers.models.modeling_outputs.Transformer2DModelOutput",anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput",source:"https://github.com/huggingface/diffusers/blob/vr_14261/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_14261/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> is discrete) — | |
| 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"}]}),n(2),r(i);var X=e(i,2);z(X,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/cogvideox_transformer3d.md"}),n(2),v(y,m),W()}export{S as component}; | |
Xet Storage Details
- Size:
- 16.9 kB
- Xet hash:
- 12b8a437bd36c9f5b32fe9b6b7052ded281c34182a67e56822397507355934b2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.