import{s as fe,n as ue,o as pe}from"../chunks/scheduler.53228c21.js";import{S as ge,i as he,e as a,s,c,h as _e,a as d,d as t,b as r,f as I,g as f,j as J,k as R,l as u,m as n,n as p,t as g,o as h,p as _}from"../chunks/index.100fac89.js";import{C as Te}from"../chunks/CopyLLMTxtMenu.999d3d86.js";import{D as se}from"../chunks/Docstring.46d0934e.js";import{C as we}from"../chunks/CodeBlock.d30a6509.js";import{H as re,E as be}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d27ae4df.js";function $e(ie){let l,E,Z,G,w,S,b,O,$,ae='A Diffusion Transformer model for 2D data from <a href="https://github.com/THUDM/CogView3" rel="nofollow">CogView3Plus</a> was introduced in <a href="https://huggingface.co/papers/2403.05121" rel="nofollow">CogView3: Finer and Faster Text-to-Image Generation via Relay Diffusion</a> by Tsinghua University &amp; ZhipuAI.',W,v,de="The model can be loaded with the following code snippet.",j,x,q,M,X,i,D,ee,z,le=`The Transformer model introduced in <a href="https://huggingface.co/papers/2403.05121" rel="nofollow">CogView3: Finer and Faster Text-to-Image Generation via Relay
Diffusion</a>.`,oe,T,y,te,L,me='The <a href="/docs/diffusers/main/en/api/models/cogview3plus_transformer2d#diffusers.CogView3PlusTransformer2DModel">CogView3PlusTransformer2DModel</a> forward method.',Y,C,N,m,V,ne,U,ce='The output of <a href="/docs/diffusers/main/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',Q,P,F,k,A;return w=new Te({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new re({props:{title:"CogView3PlusTransformer2DModel",local:"cogview3plustransformer2dmodel",headingTag:"h1"}}),x=new we({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvZ1ZpZXczUGx1c1RyYW5zZm9ybWVyMkRNb2RlbCUwQSUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwQ29nVmlldzNQbHVzVHJhbnNmb3JtZXIyRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZXczUGx1cy0zYiUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNikudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogView3PlusTransformer2DModel

transformer = CogView3PlusTransformer2DModel.from_pretrained(<span class="hljs-string">&quot;THUDM/CogView3Plus-3b&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, torch_dtype=torch.bfloat16).to(<span class="hljs-string">&quot;cuda&quot;</span>)`,wrap:!1}}),M=new re({props:{title:"CogView3PlusTransformer2DModel",local:"diffusers.CogView3PlusTransformer2DModel",headingTag:"h2"}}),D=new se({props:{name:"class diffusers.CogView3PlusTransformer2DModel",anchor:"diffusers.CogView3PlusTransformer2DModel",parameters:[{name:"patch_size",val:": int = 2"},{name:"in_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:"out_channels",val:": int = 16"},{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"}],parametersDescription:[{anchor:"diffusers.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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.CogView3PlusTransformer2DModel.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/main/src/diffusers/models/transformers/transformer_cogview3plus.py#L128"}}),y=new se({props:{name:"forward",anchor:"diffusers.CogView3PlusTransformer2DModel.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:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code>) &#x2014;
Input <code>hidden_states</code> of shape <code>(batch size, channel, height, width)</code>.`,name:"hidden_states"},{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>torch.Tensor</code>) &#x2014;
Conditional embeddings (embeddings computed from the input conditions such as prompts) of shape
<code>(batch_size, sequence_len, text_embed_dim)</code>`,name:"encoder_hidden_states"},{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.timestep",description:`<strong>timestep</strong> (<code>torch.LongTensor</code>) &#x2014;
Used to indicate denoising step.`,name:"timestep"},{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.original_size",description:`<strong>original_size</strong> (<code>torch.Tensor</code>) &#x2014;
CogView3 uses SDXL-like micro-conditioning for original image size as explained in section 2.2 of
<a href="https://huggingface.co/papers/2307.01952" rel="nofollow">https://huggingface.co/papers/2307.01952</a>.`,name:"original_size"},{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.target_size",description:`<strong>target_size</strong> (<code>torch.Tensor</code>) &#x2014;
CogView3 uses SDXL-like micro-conditioning for target image size as explained in section 2.2 of
<a href="https://huggingface.co/papers/2307.01952" rel="nofollow">https://huggingface.co/papers/2307.01952</a>.`,name:"target_size"},{anchor:"diffusers.CogView3PlusTransformer2DModel.forward.crop_coords",description:`<strong>crop_coords</strong> (<code>torch.Tensor</code>) &#x2014;
CogView3 uses SDXL-like micro-conditioning for crop coordinates as explained in section 2.2 of
<a href="https://huggingface.co/papers/2307.01952" rel="nofollow">https://huggingface.co/papers/2307.01952</a>.`,name:"crop_coords"},{anchor:"diffusers.CogView3PlusTransformer2DModel.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"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/transformer_cogview3plus.py#L227",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The denoised latents using provided inputs as conditioning.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>torch.Tensor</code> or <code>~models.transformer_2d.Transformer2DModelOutput</code></p>
`}}),C=new re({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),V=new se({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/main/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/main/src/diffusers/models/modeling_outputs.py#L21"}}),P=new be({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/cogview3plus_transformer2d.md"}}),{c(){l=a("meta"),E=s(),Z=a("p"),G=s(),c(w.$$.fragment),S=s(),c(b.$$.fragment),O=s(),$=a("p"),$.innerHTML=ae,W=s(),v=a("p"),v.textContent=de,j=s(),c(x.$$.fragment),q=s(),c(M.$$.fragment),X=s(),i=a("div"),c(D.$$.fragment),ee=s(),z=a("p"),z.innerHTML=le,oe=s(),T=a("div"),c(y.$$.fragment),te=s(),L=a("p"),L.innerHTML=me,Y=s(),c(C.$$.fragment),N=s(),m=a("div"),c(V.$$.fragment),ne=s(),U=a("p"),U.innerHTML=ce,Q=s(),c(P.$$.fragment),F=s(),k=a("p"),this.h()},l(e){const o=_e("svelte-u9bgzb",document.head);l=d(o,"META",{name:!0,content:!0}),o.forEach(t),E=r(e),Z=d(e,"P",{}),I(Z).forEach(t),G=r(e),f(w.$$.fragment,e),S=r(e),f(b.$$.fragment,e),O=r(e),$=d(e,"P",{"data-svelte-h":!0}),J($)!=="svelte-1vlmqph"&&($.innerHTML=ae),W=r(e),v=d(e,"P",{"data-svelte-h":!0}),J(v)!=="svelte-1vuni30"&&(v.textContent=de),j=r(e),f(x.$$.fragment,e),q=r(e),f(M.$$.fragment,e),X=r(e),i=d(e,"DIV",{class:!0});var H=I(i);f(D.$$.fragment,H),ee=r(H),z=d(H,"P",{"data-svelte-h":!0}),J(z)!=="svelte-1y8vmfa"&&(z.innerHTML=le),oe=r(H),T=d(H,"DIV",{class:!0});var B=I(T);f(y.$$.fragment,B),te=r(B),L=d(B,"P",{"data-svelte-h":!0}),J(L)!=="svelte-1x62s4k"&&(L.innerHTML=me),B.forEach(t),H.forEach(t),Y=r(e),f(C.$$.fragment,e),N=r(e),m=d(e,"DIV",{class:!0});var K=I(m);f(V.$$.fragment,K),ne=r(K),U=d(K,"P",{"data-svelte-h":!0}),J(U)!=="svelte-1x8c0js"&&(U.innerHTML=ce),K.forEach(t),Q=r(e),f(P.$$.fragment,e),F=r(e),k=d(e,"P",{}),I(k).forEach(t),this.h()},h(){R(l,"name","hf:doc:metadata"),R(l,"content",ve),R(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),R(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),R(m,"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){u(document.head,l),n(e,E,o),n(e,Z,o),n(e,G,o),p(w,e,o),n(e,S,o),p(b,e,o),n(e,O,o),n(e,$,o),n(e,W,o),n(e,v,o),n(e,j,o),p(x,e,o),n(e,q,o),p(M,e,o),n(e,X,o),n(e,i,o),p(D,i,null),u(i,ee),u(i,z),u(i,oe),u(i,T),p(y,T,null),u(T,te),u(T,L),n(e,Y,o),p(C,e,o),n(e,N,o),n(e,m,o),p(V,m,null),u(m,ne),u(m,U),n(e,Q,o),p(P,e,o),n(e,F,o),n(e,k,o),A=!0},p:ue,i(e){A||(g(w.$$.fragment,e),g(b.$$.fragment,e),g(x.$$.fragment,e),g(M.$$.fragment,e),g(D.$$.fragment,e),g(y.$$.fragment,e),g(C.$$.fragment,e),g(V.$$.fragment,e),g(P.$$.fragment,e),A=!0)},o(e){h(w.$$.fragment,e),h(b.$$.fragment,e),h(x.$$.fragment,e),h(M.$$.fragment,e),h(D.$$.fragment,e),h(y.$$.fragment,e),h(C.$$.fragment,e),h(V.$$.fragment,e),h(P.$$.fragment,e),A=!1},d(e){e&&(t(E),t(Z),t(G),t(S),t(O),t($),t(W),t(v),t(j),t(q),t(X),t(i),t(Y),t(N),t(m),t(Q),t(F),t(k)),t(l),_(w,e),_(b,e),_(x,e),_(M,e),_(D),_(y),_(C,e),_(V),_(P,e)}}}const ve='{"title":"CogView3PlusTransformer2DModel","local":"cogview3plustransformer2dmodel","sections":[{"title":"CogView3PlusTransformer2DModel","local":"diffusers.CogView3PlusTransformer2DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';function xe(ie){return pe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ze extends ge{constructor(l){super(),he(this,l,xe,$e,fe,{})}}export{ze as component};
