The single-stream transformer used by Qwen-Image 2.1. Text and image latents share one sequence, and a single shared
QwenImage21Transformer2DModel
The single-stream transformer used by Qwen-Image 2.1. Text and image latents share one sequence, and a single shared
modulation projection feeds every block.
Two behaviours distinguish 2.1 from earlier QwenImage transformers:
- Block-causal attention — attention follows
(q_idx >= kv_idx) or same_image_block, so the joint sequence is causal while each image block stays internally bidirectional.QwenImage21AttnProcessorimplements it as one attention call per prefix segment and is the default.QwenImage21FlexAttnProcessorimplements it as a singleflex_attentioncall driven by aBlockMask, which is faster once the model is compiled. Both produce the same results. causal_condition— text and condition-image tokens are modulated fromt = 0rather than the sampled timestep. Their activations are independent of the denoising step, so the keys and values of that prefix are cacheable across steps via thekv_cacheargument.
Load it with:
import torch
from diffusers import QwenImage21Transformer2DModel
transformer = QwenImage21Transformer2DModel.from_pretrained(
"Qwen/Qwen-Image-2.1", subfolder="transformer", dtype=torch.bfloat16
)
QwenImage21Transformer2DModel
[[autodoc]] QwenImage21Transformer2DModel
Transformer2DModelOutput
[[autodoc]] models.modeling_outputs.Transformer2DModelOutput
Source and license
Source: Diffusers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.