> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.flow_matching.adapters.qwen_image

Qwen-Image model adapter for FlowMatching Pipeline.

This adapter supports Qwen/Qwen-Image style T2I models with:

* Qwen2 text embeddings (text\_embeddings)
* 2D image latents (\[B, C, H, W])
* 2x2 patch packing similar to Flux

## Module Contents

### Classes

| Name                                                                                                | Description                                        |
| --------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| [`QwenImageAdapter`](#nemo_automodel-components-flow_matching-adapters-qwen_image-QwenImageAdapter) | Model adapter for Qwen-Image text-to-image models. |

### API

```python
class nemo_automodel.components.flow_matching.adapters.qwen_image.QwenImageAdapter(
    guidance_scale: float = 3.5,
    use_guidance_embeds: bool = False
)
```

**Bases:** [ModelAdapter](/nemo-automodel/nemo_automodel/components/flow_matching/adapters/base#nemo_automodel-components-flow_matching-adapters-base-ModelAdapter)

Model adapter for Qwen-Image text-to-image models.

Supports batch format from multiresolution dataloader:

* image\_latents: \[B, C, H, W]
* text\_embeddings: Qwen2 embeddings \[B, seq\_len, hidden\_dim]

Qwen-Image transformer forward interface:

* hidden\_states: Packed latents \[B, num\_patches, C\*4]
* encoder\_hidden\_states: Qwen2 text embeddings \[B, seq\_len, hidden\_dim]
* encoder\_hidden\_states\_mask: Attention mask (None for flash attention)
* timestep: Normalized timesteps \[0, 1]
* img\_shapes: List of image shape tuples \[\[(1, h//2, w//2)]] per sample
* guidance: Optional guidance scale embedding \[B]

```python
nemo_automodel.components.flow_matching.adapters.qwen_image.QwenImageAdapter._pack_latents(
    latents: torch.Tensor
) -> torch.Tensor
```

Pack latents from \[B, C, H, W] to \[B, (H//2)*(W//2), C*4].

Uses 2x2 patch grouping to match the transformer's patch embedding.

```python
nemo_automodel.components.flow_matching.adapters.qwen_image.QwenImageAdapter._unpack_latents(
    latents: torch.Tensor,
    height: int,
    width: int,
    vae_scale_factor: int = 8
) -> torch.Tensor
```

staticmethod

Unpack latents from \[B, num\_patches, channels] back to \[B, C, H, W].

**Parameters:**

Packed latents of shape \[B, num\_patches, channels]

Original image height in pixels

Original image width in pixels

VAE compression factor (default: 8)

```python
nemo_automodel.components.flow_matching.adapters.qwen_image.QwenImageAdapter.forward(
    model: torch.nn.Module,
    inputs: typing.Dict[str, typing.Any]
) -> torch.Tensor
```

Execute forward pass for Qwen-Image model.

Returns unpacked prediction in \[B, C, H, W] format.

```python
nemo_automodel.components.flow_matching.adapters.qwen_image.QwenImageAdapter.prepare_inputs(
    context: nemo_automodel.components.flow_matching.adapters.base.FlowMatchingContext
) -> typing.Dict[str, typing.Any]
```

Prepare inputs for Qwen-Image model from FlowMatchingContext.

Expects 4D image latents: \[B, C, H, W]