> 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.hunyuan

HunyuanVideo model adapter for FlowMatching Pipeline.

This adapter supports HunyuanVideo 1.5 style models with dual text encoders
and image embeddings for image-to-video conditioning.

## Module Contents

### Classes

| Name                                                                                         | Description                                      |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| [`HunyuanAdapter`](#nemo_automodel-components-flow_matching-adapters-hunyuan-HunyuanAdapter) | Model adapter for HunyuanVideo 1.5 style models. |

### Functions

| Name                                                                                                                                                       | Description                                                                                    |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [`_is_flash_varlen_attention_backend`](#nemo_automodel-components-flow_matching-adapters-hunyuan-_is_flash_varlen_attention_backend)                       | -                                                                                              |
| [`enable_hunyuan_flash_varlen_mask_optimization`](#nemo_automodel-components-flow_matching-adapters-hunyuan-enable_hunyuan_flash_varlen_mask_optimization) | Patch Diffusers Hunyuan attention to avoid dense mask construction for flash-varlen attention. |

### Data

[`logger`](#nemo_automodel-components-flow_matching-adapters-hunyuan-logger)

### API

```python
class nemo_automodel.components.flow_matching.adapters.hunyuan.HunyuanAdapter(
    default_image_embed_shape: typing.Tuple[int, int] = (729, 1152),
    use_condition_latents: bool = True
)
```

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

Model adapter for HunyuanVideo 1.5 style models.

These models use:

* Condition latents concatenated with noisy latents
* Dual text encoders with attention masks
* Image embeddings for i2v

Expected batch keys:

* text\_embeddings: Primary text encoder output \[B, seq\_len, dim]
* text\_mask: Attention mask for primary encoder \[B, seq\_len] (optional)
* text\_embeddings\_2: Secondary text encoder output \[B, seq\_len, dim] (optional)
* text\_mask\_2: Attention mask for secondary encoder \[B, seq\_len] (optional)
* image\_embeds: Image embeddings for i2v \[B, seq\_len, dim] (optional)

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

Execute forward pass for HunyuanVideo model.

**Parameters:**

HunyuanVideo model

Dictionary from prepare\_inputs()

**Returns:** `torch.Tensor`

Model prediction tensor

```python
nemo_automodel.components.flow_matching.adapters.hunyuan.HunyuanAdapter.get_condition_latents(
    latents: torch.Tensor,
    task_type: str
) -> torch.Tensor
```

Generate conditional latents based on task type.

**Parameters:**

Input latents \[B, C, F, H, W]

Task type ("t2v" or "i2v")

**Returns:** `torch.Tensor`

Conditional latents \[B, C+1, F, H, W]

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

Prepare inputs for HunyuanVideo model.

**Parameters:**

FlowMatchingContext with batch data

**Returns:** `Dict[str, Any]`

Dictionary containing:

```python
nemo_automodel.components.flow_matching.adapters.hunyuan._is_flash_varlen_attention_backend(
    backend: typing.Any
) -> bool
```

```python
nemo_automodel.components.flow_matching.adapters.hunyuan.enable_hunyuan_flash_varlen_mask_optimization() -> bool
```

Patch Diffusers Hunyuan attention to avoid dense mask construction for flash-varlen attention.

```python
nemo_automodel.components.flow_matching.adapters.hunyuan.logger = logging.getLogger(__name__)
```