Buckets:

download
raw
14.2 kB
import{s as me,n as ce,o as le}from"../chunks/scheduler.53228c21.js";import{S as fe,i as pe,e as i,s as r,c as l,h as ue,a,d as t,b as s,f as I,g as f,j as F,k as J,l as z,m as n,n as p,t as u,o as g,p as h}from"../chunks/index.cac5d66a.js";import{C as ge}from"../chunks/CopyLLMTxtMenu.0ef49226.js";import{D as te}from"../chunks/Docstring.9de32ff4.js";import{C as he}from"../chunks/CodeBlock.606cbaf4.js";import{H as ne,E as _e}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.48d5cb47.js";function Te(re){let d,N,H,E,T,R,b,U,w,se='A Diffusion Transformer model for 2D data from <a href="">CogView4</a>',W,$,ie="The model can be loaded with the following code snippet.",O,M,P,v,j,m,D,K,_,y,ee,k,ae='The <a href="/docs/diffusers/pr_13921/en/api/models/cogview4_transformer2d#diffusers.CogView4Transformer2DModel">CogView4Transformer2DModel</a> forward method.',q,x,G,c,C,oe,Z,de='The output of <a href="/docs/diffusers/pr_13921/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',B,V,Y,L,A;return T=new ge({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new ne({props:{title:"CogView4Transformer2DModel",local:"cogview4transformer2dmodel",headingTag:"h1"}}),M=new he({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvZ1ZpZXc0VHJhbnNmb3JtZXIyRE1vZGVsJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBDb2dWaWV3NFRyYW5zZm9ybWVyMkRNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyVEhVRE0lMkZDb2dWaWV3NC02QiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNikudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogView4Transformer2DModel
transformer = CogView4Transformer2DModel.from_pretrained(<span class="hljs-string">&quot;THUDM/CogView4-6B&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, torch_dtype=torch.bfloat16).to(<span class="hljs-string">&quot;cuda&quot;</span>)`,lang:"python",wrap:!1}}),v=new ne({props:{title:"CogView4Transformer2DModel",local:"diffusers.CogView4Transformer2DModel",headingTag:"h2"}}),D=new te({props:{name:"class diffusers.CogView4Transformer2DModel",anchor:"diffusers.CogView4Transformer2DModel",parameters:[{name:"patch_size",val:": int = 2"},{name:"in_channels",val:": int = 16"},{name:"out_channels",val:": int = 16"},{name:"num_layers",val:": int = 30"},{name:"attention_head_dim",val:": int = 40"},{name:"num_attention_heads",val:": int = 64"},{name:"text_embed_dim",val:": int = 4096"},{name:"time_embed_dim",val:": int = 512"},{name:"condition_dim",val:": int = 256"},{name:"pos_embed_max_size",val:": int = 128"},{name:"sample_size",val:": int = 128"},{name:"rope_axes_dim",val:": tuple = (256, 256)"}],parametersDescription:[{anchor:"diffusers.CogView4Transformer2DModel.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, defaults to <code>2</code>) &#x2014;
The size of the patches to use in the patch embedding layer.`,name:"patch_size"},{anchor:"diffusers.CogView4Transformer2DModel.in_channels",description:`<strong>in_channels</strong> (<code>int</code>, defaults to <code>16</code>) &#x2014;
The number of channels in the input.`,name:"in_channels"},{anchor:"diffusers.CogView4Transformer2DModel.num_layers",description:`<strong>num_layers</strong> (<code>int</code>, defaults to <code>30</code>) &#x2014;
The number of layers of Transformer blocks to use.`,name:"num_layers"},{anchor:"diffusers.CogView4Transformer2DModel.attention_head_dim",description:`<strong>attention_head_dim</strong> (<code>int</code>, defaults to <code>40</code>) &#x2014;
The number of channels in each head.`,name:"attention_head_dim"},{anchor:"diffusers.CogView4Transformer2DModel.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, defaults to <code>64</code>) &#x2014;
The number of heads to use for multi-head attention.`,name:"num_attention_heads"},{anchor:"diffusers.CogView4Transformer2DModel.out_channels",description:`<strong>out_channels</strong> (<code>int</code>, defaults to <code>16</code>) &#x2014;
The number of channels in the output.`,name:"out_channels"},{anchor:"diffusers.CogView4Transformer2DModel.text_embed_dim",description:`<strong>text_embed_dim</strong> (<code>int</code>, defaults to <code>4096</code>) &#x2014;
Input dimension of text embeddings from the text encoder.`,name:"text_embed_dim"},{anchor:"diffusers.CogView4Transformer2DModel.time_embed_dim",description:`<strong>time_embed_dim</strong> (<code>int</code>, defaults to <code>512</code>) &#x2014;
Output dimension of timestep embeddings.`,name:"time_embed_dim"},{anchor:"diffusers.CogView4Transformer2DModel.condition_dim",description:`<strong>condition_dim</strong> (<code>int</code>, defaults to <code>256</code>) &#x2014;
The embedding dimension of the input SDXL-style resolution conditions (original_size, target_size,
crop_coords).`,name:"condition_dim"},{anchor:"diffusers.CogView4Transformer2DModel.pos_embed_max_size",description:`<strong>pos_embed_max_size</strong> (<code>int</code>, defaults to <code>128</code>) &#x2014;
The maximum resolution of the positional embeddings, from which slices of shape <code>H x W</code> are taken and added
to input patched latents, where <code>H</code> and <code>W</code> are the latent height and width respectively. A value of 128
means that the maximum supported height and width for image generation is <code>128 * vae_scale_factor * patch_size =&gt; 128 * 8 * 2 =&gt; 2048</code>.`,name:"pos_embed_max_size"},{anchor:"diffusers.CogView4Transformer2DModel.sample_size",description:`<strong>sample_size</strong> (<code>int</code>, defaults to <code>128</code>) &#x2014;
The base resolution of input latents. If height/width is not provided during generation, this value is used
to determine the resolution as <code>sample_size * vae_scale_factor =&gt; 128 * 8 =&gt; 1024</code>`,name:"sample_size"}],source:"https://github.com/huggingface/diffusers/blob/vr_13921/src/diffusers/models/transformers/transformer_cogview4.py#L615"}}),y=new te({props:{name:"forward",anchor:"diffusers.CogView4Transformer2DModel.forward",parameters:[{name:"hidden_states",val:": Tensor"},{name:"encoder_hidden_states",val:": Tensor"},{name:"timestep",val:": LongTensor"},{name:"original_size",val:": Tensor"},{name:"target_size",val:": Tensor"},{name:"crop_coords",val:": Tensor"},{name:"attention_kwargs",val:": dict[str, typing.Any] | None = None"},{name:"return_dict",val:": bool = True"},{name:"attention_mask",val:": torch.Tensor | None = None"},{name:"image_rotary_emb",val:": tuple[torch.Tensor, torch.Tensor] | list[tuple[torch.Tensor, torch.Tensor]] | None = None"}],parametersDescription:[{anchor:"diffusers.CogView4Transformer2DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, in_channels, height, width)</code>) &#x2014;
Input <code>hidden_states</code>.`,name:"hidden_states"},{anchor:"diffusers.CogView4Transformer2DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_len, embed_dims)</code>) &#x2014;
Conditional embeddings (embeddings computed from the input conditions such as prompts) to use.`,name:"encoder_hidden_states"},{anchor:"diffusers.CogView4Transformer2DModel.forward.timestep",description:`<strong>timestep</strong> (<code>torch.LongTensor</code>) &#x2014;
Used to indicate denoising step.`,name:"timestep"},{anchor:"diffusers.CogView4Transformer2DModel.forward.original_size",description:`<strong>original_size</strong> (<code>torch.Tensor</code>) &#x2014;
Original image size conditioning.`,name:"original_size"},{anchor:"diffusers.CogView4Transformer2DModel.forward.target_size",description:`<strong>target_size</strong> (<code>torch.Tensor</code>) &#x2014;
Target image size conditioning.`,name:"target_size"},{anchor:"diffusers.CogView4Transformer2DModel.forward.crop_coords",description:`<strong>crop_coords</strong> (<code>torch.Tensor</code>) &#x2014;
Crop coordinates conditioning.`,name:"crop_coords"},{anchor:"diffusers.CogView4Transformer2DModel.forward.attention_kwargs",description:`<strong>attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
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.CogView4Transformer2DModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <code>~models.transformer_2d.Transformer2DModelOutput</code> instead of a plain
tuple.`,name:"return_dict"},{anchor:"diffusers.CogView4Transformer2DModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Mask applied to attention scores.`,name:"attention_mask"},{anchor:"diffusers.CogView4Transformer2DModel.forward.image_rotary_emb",description:`<strong>image_rotary_emb</strong> (<code>tuple</code> of <code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Pre-computed rotary positional embeddings.`,name:"image_rotary_emb"}],source:"https://github.com/huggingface/diffusers/blob/vr_13921/src/diffusers/models/transformers/transformer_cogview4.py#L702",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>
`}}),x=new ne({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),C=new te({props:{name:"class diffusers.models.modeling_outputs.Transformer2DModelOutput",anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput",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_13921/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"}],source:"https://github.com/huggingface/diffusers/blob/vr_13921/src/diffusers/models/modeling_outputs.py#L21"}}),V=new _e({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/cogview4_transformer2d.md"}}),{c(){d=i("meta"),N=r(),H=i("p"),E=r(),l(T.$$.fragment),R=r(),l(b.$$.fragment),U=r(),w=i("p"),w.innerHTML=se,W=r(),$=i("p"),$.textContent=ie,O=r(),l(M.$$.fragment),P=r(),l(v.$$.fragment),j=r(),m=i("div"),l(D.$$.fragment),K=r(),_=i("div"),l(y.$$.fragment),ee=r(),k=i("p"),k.innerHTML=ae,q=r(),l(x.$$.fragment),G=r(),c=i("div"),l(C.$$.fragment),oe=r(),Z=i("p"),Z.innerHTML=de,B=r(),l(V.$$.fragment),Y=r(),L=i("p"),this.h()},l(e){const o=ue("svelte-u9bgzb",document.head);d=a(o,"META",{name:!0,content:!0}),o.forEach(t),N=s(e),H=a(e,"P",{}),I(H).forEach(t),E=s(e),f(T.$$.fragment,e),R=s(e),f(b.$$.fragment,e),U=s(e),w=a(e,"P",{"data-svelte-h":!0}),F(w)!=="svelte-1qocnal"&&(w.innerHTML=se),W=s(e),$=a(e,"P",{"data-svelte-h":!0}),F($)!=="svelte-1vuni30"&&($.textContent=ie),O=s(e),f(M.$$.fragment,e),P=s(e),f(v.$$.fragment,e),j=s(e),m=a(e,"DIV",{class:!0});var S=I(m);f(D.$$.fragment,S),K=s(S),_=a(S,"DIV",{class:!0});var X=I(_);f(y.$$.fragment,X),ee=s(X),k=a(X,"P",{"data-svelte-h":!0}),F(k)!=="svelte-13z2tu7"&&(k.innerHTML=ae),X.forEach(t),S.forEach(t),q=s(e),f(x.$$.fragment,e),G=s(e),c=a(e,"DIV",{class:!0});var Q=I(c);f(C.$$.fragment,Q),oe=s(Q),Z=a(Q,"P",{"data-svelte-h":!0}),F(Z)!=="svelte-2clpd6"&&(Z.innerHTML=de),Q.forEach(t),B=s(e),f(V.$$.fragment,e),Y=s(e),L=a(e,"P",{}),I(L).forEach(t),this.h()},h(){J(d,"name","hf:doc:metadata"),J(d,"content",be),J(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),J(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),J(c,"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,o){z(document.head,d),n(e,N,o),n(e,H,o),n(e,E,o),p(T,e,o),n(e,R,o),p(b,e,o),n(e,U,o),n(e,w,o),n(e,W,o),n(e,$,o),n(e,O,o),p(M,e,o),n(e,P,o),p(v,e,o),n(e,j,o),n(e,m,o),p(D,m,null),z(m,K),z(m,_),p(y,_,null),z(_,ee),z(_,k),n(e,q,o),p(x,e,o),n(e,G,o),n(e,c,o),p(C,c,null),z(c,oe),z(c,Z),n(e,B,o),p(V,e,o),n(e,Y,o),n(e,L,o),A=!0},p:ce,i(e){A||(u(T.$$.fragment,e),u(b.$$.fragment,e),u(M.$$.fragment,e),u(v.$$.fragment,e),u(D.$$.fragment,e),u(y.$$.fragment,e),u(x.$$.fragment,e),u(C.$$.fragment,e),u(V.$$.fragment,e),A=!0)},o(e){g(T.$$.fragment,e),g(b.$$.fragment,e),g(M.$$.fragment,e),g(v.$$.fragment,e),g(D.$$.fragment,e),g(y.$$.fragment,e),g(x.$$.fragment,e),g(C.$$.fragment,e),g(V.$$.fragment,e),A=!1},d(e){e&&(t(N),t(H),t(E),t(R),t(U),t(w),t(W),t($),t(O),t(P),t(j),t(m),t(q),t(G),t(c),t(B),t(Y),t(L)),t(d),h(T,e),h(b,e),h(M,e),h(v,e),h(D),h(y),h(x,e),h(C),h(V,e)}}}const be='{"title":"CogView4Transformer2DModel","local":"cogview4transformer2dmodel","sections":[{"title":"CogView4Transformer2DModel","local":"diffusers.CogView4Transformer2DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';function we(re){return le(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ce extends fe{constructor(d){super(),pe(this,d,we,Te,me,{})}}export{Ce as component};

Xet Storage Details

Size:
14.2 kB
·
Xet hash:
4777378132e6ac80c548ce37e402ddc09579058fb187123a3b096b22edf684b6

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