nemo_automodel.components.flow_matching.adapters.qwen_image_21
nemo_automodel.components.flow_matching.adapters.qwen_image_21
Qwen-Image-2.1 model adapter for FlowMatching Pipeline.
Qwen-Image-2.1 is a single-stream, block-causal DiT. Unlike Qwen-Image it:
- consumes 64-channel latents unpatched (one token per 16x16 pixel tile),
- runs text and image tokens through one joint sequence whose layout is
described by
img_mask(one slot per 2x2 group of target latent tokens), - predicts every joint-sequence token; only the trailing target-image tokens are supervised.
Module Contents
Classes
Data
API
Bases: ModelAdapter
Model adapter for Qwen-Image-2.1 text-to-image models.
Supports batch format from multiresolution dataloader:
- image_latents: [B, 64, H, W]
- text_embeddings: Qwen3-VL embeddings [B, seq_len, 4096], right-padded
- text_attention_mask: optional [B, seq_len] bool marking valid text tokens
Qwen-Image-2.1 transformer forward interface:
- hidden_states: Flattened latents [B, H*W, 64]
- encoder_hidden_states: Text embeddings [B, text_len, 4096]
- timestep: Normalized timesteps [0, 1]
- img_shapes: [[(1, H, W)]] per sample
- img_mask: [B, text_len + H*W/4] bool, True at target-image slots
The transformer lays out RoPE from row 0 of img_mask for the whole batch, and every text position
(padding included) advances the target image’s frame index. Each sample is therefore run as its own
unpadded transformer call, so it sees exactly the positions of single-prompt inference.
Text positions first, then one slot per 2x2 group of target latent tokens.
Flatten latents from [B, C, H, W] to [B, H*W, C] (no patching in 2.1).
Restore [B, H*W, C] token predictions to [B, C, H, W].
Execute forward pass for Qwen-Image-2.1 model.
Runs one transformer call per sample, trimmed to that sample’s prompt length, and returns the target-image prediction in [B, C, H, W] format.
The call count is always the local batch size, never the number of distinct prompt lengths: under FSDP every call issues collectives, so all ranks must make the same number of calls, and the diffusion sampler gives every rank the same local batch size.
Prepare inputs for Qwen-Image-2.1 model from FlowMatchingContext.
Expects 4D image latents: [B, C, H, W] with even H and W.