Buckets:

download
raw
13.8 kB
import"../chunks/DsnmJJEf.js";import{i as v,h as D,H as n,a as k,D as s,E as F,s as j}from"../chunks/BLbO27j4.js";import{p as J,o as E,s as e,f as q,a as g,b as Z,c as r,d as x,n as a,r as d}from"../chunks/jDjavuwI.js";const A='{"title":"Flux3Transformer2DModel","local":"flux3transformer2dmodel","sections":[{"title":"Flux3Transformer2DModel","local":"diffusers.Flux3Transformer2DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';var O=x('<meta name="hf:doc:metadata"/>'),z=x(`<p></p> <!> <p>A Transformer model for image-like data from <a href="https://bfl.ai/" rel="nofollow">FLUX.3</a>, for text-to-image and image-to-image generation. Three token modes share one joint sequence: the noisy image tokens, the VAE-encoded reference image tokens and the text context. Each mode first passes through its own per-mode transformer blocks, then the modes are concatenated for the joint single blocks, and the image tokens pass through the output layers. Timesteps are per token: the image tokens carry the flow timestep, the reference tokens and the text context sit at <code>0</code>.</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 Transformer model introduced in FLUX.3 for text-to-image and image-to-image generation.</p> <p>Three token modes share one joint sequence: the noisy image tokens (<code>hidden_states</code>), the optional VAE-encoded
reference image tokens (<code>image_cond_hidden_states</code>) and the text context (<code>encoder_hidden_states</code>). Each mode first
passes through its own per-mode transformer blocks (<code>mode_blocks</code> for the image modes, <code>txt_mode_blocks</code> for the
text context), then the text context and the active image modes are concatenated for the joint single blocks, and
only the image tokens pass through the output layers. The modulation is per mode: the image tokens are modulated by
the flow timestep, the reference image tokens and the text context by timestep <code>0</code>. A flow-map checkpoint
(<code>flow_map=True</code>, the step-distilled models) additionally embeds the timestep each denoising step jumps to and adds
it to every mode’s modulation.</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_14521/en/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a> forward method.</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>The output of <a href="/docs/diffusers/pr_14521/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.</p></div> <!> <p></p>`,1);function L(T,b){J(b,!1),E(()=>{new URLSearchParams(window.location.search).get("fw")}),v();var i=z();D("1qtfnmt",u=>{var _=O();j(_,"content",A),g(u,_)});var c=e(q(i),2);n(c,{title:"Flux3Transformer2DModel",local:"flux3transformer2dmodel",headingTag:"h1"});var l=e(c,4);k(l,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eDNUcmFuc2Zvcm1lcjJETW9kZWwlMEElMEF0cmFuc2Zvcm1lciUyMCUzRCUyMEZsdXgzVHJhbnNmb3JtZXIyRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJibGFjay1mb3Jlc3QtbGFicyUyRmZsdXgtMy1pbWFnZS1rbGVpbi1iYXNlJTIyJTJDJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Flux3Transformer2DModel
transformer = Flux3Transformer2DModel.from_pretrained(
<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, dtype=torch.bfloat16
)`,lang:"python",wrap:!1});var m=e(l,2);n(m,{title:"Flux3Transformer2DModel",local:"diffusers.Flux3Transformer2DModel",headingTag:"h2"});var o=e(m,2),f=r(o);s(f,{name:"class diffusers.Flux3Transformer2DModel",anchor:"diffusers.Flux3Transformer2DModel",source:"https://github.com/huggingface/diffusers/blob/vr_14521/src/diffusers/models/transformers/transformer_flux3.py#L341",parameters:[{name:"in_channels",val:": int = 128"},{name:"cond_in_channels",val:": int = 128"},{name:"num_layers",val:": int = 5"},{name:"num_single_layers",val:": int = 28"},{name:"attention_head_dim",val:": int = 128"},{name:"num_attention_heads",val:": int = 24"},{name:"joint_attention_dim",val:": int = 20480"},{name:"timestep_channels",val:": int = 256"},{name:"mlp_ratio",val:": float = 3.0"},{name:"axes_dims_rope",val:": tuple = (32, 32, 32, 32)"},{name:"rope_theta",val:": int = 10000"},{name:"eps",val:": float = 1e-06"},{name:"flow_map",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.Flux3Transformer2DModel.in_channels",description:`<strong>in_channels</strong> (<code>int</code>, defaults to <code>128</code>) &#x2014;
Channel width of the image tokens (the packed VAE latents, <code>latent_channels * 4</code>).`,name:"in_channels"},{anchor:"diffusers.Flux3Transformer2DModel.cond_in_channels",description:`<strong>cond_in_channels</strong> (<code>int</code>, defaults to <code>128</code>) &#x2014;
Channel width of the reference image tokens.`,name:"cond_in_channels"},{anchor:"diffusers.Flux3Transformer2DModel.num_layers",description:`<strong>num_layers</strong> (<code>int</code>, defaults to <code>5</code>) &#x2014;
The number of per-mode transformer blocks.`,name:"num_layers"},{anchor:"diffusers.Flux3Transformer2DModel.num_single_layers",description:`<strong>num_single_layers</strong> (<code>int</code>, defaults to <code>28</code>) &#x2014;
The number of joint single transformer blocks.`,name:"num_single_layers"},{anchor:"diffusers.Flux3Transformer2DModel.attention_head_dim",description:`<strong>attention_head_dim</strong> (<code>int</code>, defaults to <code>128</code>) &#x2014;
The number of dimensions to use for each attention head.`,name:"attention_head_dim"},{anchor:"diffusers.Flux3Transformer2DModel.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, defaults to <code>24</code>) &#x2014;
The number of attention heads to use.`,name:"num_attention_heads"},{anchor:"diffusers.Flux3Transformer2DModel.joint_attention_dim",description:`<strong>joint_attention_dim</strong> (<code>int</code>, defaults to <code>20480</code>) &#x2014;
The embedding/channel dimension of <code>encoder_hidden_states</code> (stacked Qwen3-VL hidden states).`,name:"joint_attention_dim"},{anchor:"diffusers.Flux3Transformer2DModel.timestep_channels",description:`<strong>timestep_channels</strong> (<code>int</code>, defaults to <code>256</code>) &#x2014;
The number of channels of the sinusoidal timestep embedding.`,name:"timestep_channels"},{anchor:"diffusers.Flux3Transformer2DModel.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>float</code>, defaults to <code>3.0</code>) &#x2014;
The expansion ratio of the feedforward sub-blocks.`,name:"mlp_ratio"},{anchor:"diffusers.Flux3Transformer2DModel.axes_dims_rope",description:`<strong>axes_dims_rope</strong> (<code>tuple[int]</code>, defaults to <code>(32, 32, 32, 32)</code>) &#x2014;
The dimensions to use for the rotary positional embeddings, per <code>(t, h, w, l)</code> position axis.`,name:"axes_dims_rope"},{anchor:"diffusers.Flux3Transformer2DModel.rope_theta",description:`<strong>rope_theta</strong> (<code>int</code>, defaults to <code>10000</code>) &#x2014;
The base frequency of the rotary positional embeddings.`,name:"rope_theta"},{anchor:"diffusers.Flux3Transformer2DModel.eps",description:`<strong>eps</strong> (<code>float</code>, defaults to <code>1e-6</code>) &#x2014;
The epsilon of the layer norms and the QK norms.`,name:"eps"},{anchor:"diffusers.Flux3Transformer2DModel.flow_map",description:`<strong>flow_map</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether the model is a flow map (step-distilled): adds the <code>target_timestep_embedder</code> and requires
<code>target_timestep</code> in the forward pass.`,name:"flow_map"}]});var h=e(f,6),M=r(h);s(M,{name:"forward",anchor:"diffusers.Flux3Transformer2DModel.forward",source:"https://github.com/huggingface/diffusers/blob/vr_14521/src/diffusers/models/transformers/transformer_flux3.py#L494",parameters:[{name:"hidden_states",val:": Tensor"},{name:"encoder_hidden_states",val:": Tensor"},{name:"timestep",val:": Tensor"},{name:"img_ids",val:": Tensor"},{name:"txt_ids",val:": Tensor"},{name:"image_cond_hidden_states",val:": typing.Optional[torch.Tensor] = None"},{name:"image_cond_ids",val:": typing.Optional[torch.Tensor] = None"},{name:"target_timestep",val:": typing.Optional[torch.Tensor] = None"},{name:"attention_kwargs",val:": dict[str, typing.Any] | None = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.Flux3Transformer2DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, image_seq_len, in_channels)</code>) &#x2014;
Noisy image latent tokens.`,name:"hidden_states"},{anchor:"diffusers.Flux3Transformer2DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, text_seq_len, joint_attention_dim)</code>) &#x2014;
Text context embeddings (stacked Qwen3-VL hidden states).`,name:"encoder_hidden_states"},{anchor:"diffusers.Flux3Transformer2DModel.forward.timestep",description:`<strong>timestep</strong> (<code>torch.Tensor</code> of shape <code>(batch_size,)</code>) &#x2014;
Flow timestep in <code>[0, 1]</code> of the image tokens. The reference image tokens and the text context sit at
timestep <code>0</code>.`,name:"timestep"},{anchor:"diffusers.Flux3Transformer2DModel.forward.img_ids",description:`<strong>img_ids</strong> (<code>torch.Tensor</code> of shape <code>(image_seq_len, 4)</code>) &#x2014;
Position ids <code>(t, h, w, l)</code> of the image tokens, used for the rotary positional embeddings and shared
by all samples in the batch.`,name:"img_ids"},{anchor:"diffusers.Flux3Transformer2DModel.forward.txt_ids",description:`<strong>txt_ids</strong> (<code>torch.Tensor</code> of shape <code>(text_seq_len, 4)</code>) &#x2014;
Position ids of the text context tokens.`,name:"txt_ids"},{anchor:"diffusers.Flux3Transformer2DModel.forward.image_cond_hidden_states",description:`<strong>image_cond_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, cond_seq_len, cond_in_channels)</code>, <em>optional</em>) &#x2014;
VAE-encoded reference image tokens (clean conditioning content, for image-to-image generation).`,name:"image_cond_hidden_states"},{anchor:"diffusers.Flux3Transformer2DModel.forward.image_cond_ids",description:`<strong>image_cond_ids</strong> (<code>torch.Tensor</code> of shape <code>(cond_seq_len, 4)</code>, <em>optional</em>) &#x2014;
Position ids of the reference image tokens. Required with <code>image_cond_hidden_states</code>.`,name:"image_cond_ids"},{anchor:"diffusers.Flux3Transformer2DModel.forward.target_timestep",description:`<strong>target_timestep</strong> (<code>torch.Tensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Flow timestep in <code>[0, 1]</code> that the current denoising step jumps to. Required by, and only by, a
flow-map model (<code>flow_map=True</code>).`,name:"target_timestep"},{anchor:"diffusers.Flux3Transformer2DModel.forward.attention_kwargs",description:`<strong>attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
A kwargs dictionary whose <code>scale</code> entry, if specified, scales the LoRA layers for this forward pass.`,name:"attention_kwargs"},{anchor:"diffusers.Flux3Transformer2DModel.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"}],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 predicted velocity of the image tokens, of the same shape as
<code>hidden_states</code>.</p>
`}),a(2),d(h),d(o);var p=e(o,2);n(p,{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"});var t=e(p,2),w=r(t);s(w,{name:"class diffusers.models.modeling_outputs.Transformer2DModelOutput",anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput",source:"https://github.com/huggingface/diffusers/blob/vr_14521/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_14521/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"}]}),a(2),d(t);var y=e(t,2);F(y,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/flux3_transformer.md"}),a(2),g(T,i),Z()}export{L as component};

Xet Storage Details

Size:
13.8 kB
·
Xet hash:
e2d33ac86c3727a3ad73ae87b17998b7dbdf0497d5a3f12de6befc18aa001763

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