> This page is for version 0.7.0 · 26.10.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

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

# nemo_automodel.components.models.hy_v4_flash.processing

Image-text processor of Hy4-flash.

The released chat template renders each image as `&lt;image_start&gt;&lt;image_pad&gt;&lt;image_end&gt;`; this processor expands the
single pad into `(h / merge) * (w / merge + 1)` pads (one extra slot per merged row for the newline feature) and
produces the flat patches the vision tower consumes. Preprocessing follows the transformers reference
(`HYV4VLImageProcessor`): `smart_resize` to multiples of `patch_size * merge`, bicubic resize on the uint8 tensor,
rescale by 1/255, normalize with mean/std 0.5, row-major patches. The released `processor_config` names LANCZOS as
the resampling filter, but the reference (and the original implementation) always resize bicubically; so does this code.

## Module Contents

### Classes

| Name                                                                                                        | Description                                                                                           |
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [`ChatContentBlock`](#nemo_automodel-components-models-hy_v4_flash-processing-ChatContentBlock)             | One text or image block of a chat message (the Hugging Face multimodal chat format).                  |
| [`ChatMessage`](#nemo_automodel-components-models-hy_v4_flash-processing-ChatMessage)                       | One chat message with string content or an ordered list of content blocks.                            |
| [`HYV4FlashImageSettings`](#nemo_automodel-components-models-hy_v4_flash-processing-HYV4FlashImageSettings) | Preprocessing constants of `processor_config.json`: patch and merge size, pixel bounds, mean and std. |
| [`HYV4FlashProcessor`](#nemo_automodel-components-models-hy_v4_flash-processing-HYV4FlashProcessor)         | Expand image placeholders and build vision inputs for the Hy4-flash chat format.                      |
| [`ImageProcessorConfig`](#nemo_automodel-components-models-hy_v4_flash-processing-ImageProcessorConfig)     | The fields of the `image_processor` block of the released `processor_config.json` that are consumed.  |
| [`ImageUrl`](#nemo_automodel-components-models-hy_v4_flash-processing-ImageUrl)                             | `&#123;"url": ...&#125;` form of an image reference.                                                  |
| [`ProcessorConfig`](#nemo_automodel-components-models-hy_v4_flash-processing-ProcessorConfig)               | `processor_config.json` as this processor writes it.                                                  |
| [`ProcessorOptions`](#nemo_automodel-components-models-hy_v4_flash-processing-ProcessorOptions)             | Tokenization options forwarded by the collator through `processor_kwargs`.                            |

### Functions

| Name                                                                                                                                    | Description                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [`_open_image`](#nemo_automodel-components-models-hy_v4_flash-processing-_open_image)                                                   | Decode an image source (PIL image, path or encoded bytes).                                                   |
| [`image_grid`](#nemo_automodel-components-models-hy_v4_flash-processing-image_grid)                                                     | Patch grid `(grid_h, grid_w)` of an image of the given pixel size.                                           |
| [`image_settings_from_processor_config`](#nemo_automodel-components-models-hy_v4_flash-processing-image_settings_from_processor_config) | Preprocessing constants of a checkpoint's `processor_config.json` `image_processor` block.                   |
| [`num_image_tokens`](#nemo_automodel-components-models-hy_v4_flash-processing-num_image_tokens)                                         | Placeholder count of one image: `(h / merge) * (w / merge + 1)` (one newline slot per merged row).           |
| [`preprocess_image`](#nemo_automodel-components-models-hy_v4_flash-processing-preprocess_image)                                         | Resize, normalize and patchify one PIL image (converted to RGB).                                             |
| [`smart_resize`](#nemo_automodel-components-models-hy_v4_flash-processing-smart_resize)                                                 | Round both sides to multiples of `factor` while keeping the area inside `[min_pixels, max_pixels]`.          |
| [`training_reasoning_effort`](#nemo_automodel-components-models-hy_v4_flash-processing-training_reasoning_effort)                       | Reasoning mode of a complete (training) conversation: `"no_think"`, as the official fine-tuning scripts use. |

### Data

[`IMAGE_PAD_TOKEN`](#nemo_automodel-components-models-hy_v4_flash-processing-IMAGE_PAD_TOKEN)

[`ImageSource`](#nemo_automodel-components-models-hy_v4_flash-processing-ImageSource)

[`TokenizerOption`](#nemo_automodel-components-models-hy_v4_flash-processing-TokenizerOption)

### API

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ChatContentBlock
```

**Bases:** `typing.TypedDict`

One text or image block of a chat message (the Hugging Face multimodal chat format).

**`image`** `ImageSource`

---

**`image_url`** `str | ImageUrl`

---

**`path`** `str`

---

**`text`** `str`

---

**`type`** `Required[Literal['text', 'image', 'image_url']]`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage
```

**Bases:** `typing.TypedDict`

One chat message with string content or an ordered list of content blocks.

**`content`** `Required[str | list[ChatContentBlock]]`

---

**`reasoning`** `str`

---

**`reasoning_content`** `str`

---

**`role`** `Required[Literal['system', 'user', 'assistant']]`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashImageSettings(
    patch_size: int = 16,
    merge_size: int = 2,
    min_pixels: int = 4096,
    max_pixels: int = 4194304,
    mean: tuple[float, float, float] = (0.5, 0.5, 0.5),
    std: tuple[float, float, float] = (0.5, 0.5, 0.5)
)
```

Dataclass

Preprocessing constants of `processor_config.json`: patch and merge size, pixel bounds, mean and std.

**`max_pixels`** `int = 4194304`

---

**`mean`** `tuple[float, float, float] = (0.5, 0.5, 0.5)`

---

**`merge_size`** `int = 2`

---

**`min_pixels`** `int = 4096`

---

**`patch_size`** `int = 16`

---

**`std`** `tuple[float, float, float] = (0.5, 0.5, 0.5)`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor(
    tokenizer: transformers.PreTrainedTokenizerFast,
    image_token_id: int = 120120,
    settings: nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashImageSettings | None = None
)
```

**Bases:** `ProcessorMixin`

Expand image placeholders and build vision inputs for the Hy4-flash chat format.

**Parameters:**

**`tokenizer`** `PreTrainedTokenizerFast`

Fast tokenizer of the checkpoint (carries the chat template and the image tokens).

---

**`image_token_id`** `int` — default: 120120

Id of the image pad token (`config.image_token_id`).

---

**`settings`** `HYV4FlashImageSettings | None` — default: None

Image preprocessing constants.

---

**`attributes`** `= ['tokenizer']`

---

**`settings`** `= settings or HYV4FlashImageSettings()`

---

**`tokenizer_class`** `= 'AutoTokenizer'`

---

```python
nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor.__call__(
    text: str | list[str],
    images: Image.Image | list[Image.Image] | list[list[Image.Image]] | None = None,
    return_tensors: str | None = None,
    padding: bool | str = False,
    truncation: bool = False,
    max_length: int | None = None,
    kwargs: nemo_automodel.components.models.hy_v4_flash.processing.TokenizerOption = {}
) -> transformers.BatchFeature
```

Tokenize rendered prompts, expanding every image pad.

**Parameters:**

**`text`** `str | list[str]`

Rendered prompt(s), each containing one image pad token per image.

---

**`images`** `Image.Image | list[Image.Image] | list[list[Image.Image]] | None` — default: None

Images grouped per prompt (or one prompt's flat list).

---

**`return_tensors`** `str | None` — default: None

`"pt"` or `None` (ragged lists).

---

**`padding`** `bool | str` — default: False

`False`, `True` / `"longest"` or `"max_length"` (right padding).

---

**`truncation`** `bool` — default: False

Whether `max_length` removes trailing tokens; cutting through an image raises.

---

**`max_length`** `int | None` — default: None

Token limit after image expansion.

---

**`**kwargs`** `TokenizerOption` — default: \{}

Extra tokenizer arguments.

---

**Returns:** `BatchFeature`

`BatchFeature` with `input_ids` / `attention_mask` / `mm_token_type_ids` of shape \[batch, sequence]

```python
nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor._split_images(
    messages: collections.abc.Sequence[nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage]
) -> tuple[list[nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage], list[nemo_automodel.components.models.hy_v4_flash.processing.ImageSource]]
```

Replace image payloads with bare `&#123;"type": "image"&#125;` blocks and collect the sources in order.

```python
nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor.apply_chat_template(
    conversation: collections.abc.Sequence[nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage] | collections.abc.Sequence[collections.abc.Sequence[nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage]],
    tokenize: bool = False,
    return_dict: bool = False,
    return_tensors: str | None = None,
    add_generation_prompt: bool = False,
    processor_kwargs: nemo_automodel.components.models.hy_v4_flash.processing.ProcessorOptions | None = None,
    kwargs: nemo_automodel.components.models.hy_v4_flash.processing.TokenizerOption = {}
) -> str | list[str] | torch.Tensor | transformers.BatchFeature
```

Render conversations with the checkpoint's jinja template and, optionally, tokenize them.

**Parameters:**

**`conversation`** `Sequence[ChatMessage] | Sequence[Sequence[ChatMessage]]`

Chat messages (or a batch of them) with string or text / image content blocks.

---

**`tokenize`** `bool` — default: False

Whether to tokenize (expanding images) instead of returning the rendered text.

---

**`return_dict`** `bool` — default: False

Whether to return the whole `BatchFeature`.

---

**`return_tensors`** `str | None` — default: None

`"pt"` or `None`.

---

**`add_generation_prompt`** `bool` — default: False

Append the assistant header.

---

**`processor_kwargs`** `ProcessorOptions | None` — default: None

Padding / truncation arguments for `__call__`.

---

**`**kwargs`** `TokenizerOption` — default: \{}

Extra jinja template variables. Without `reasoning_effort`, a complete conversation
(`add_generation_prompt=False`, the training case) is rendered in `no_think` mode and must not
carry assistant reasoning (`training_reasoning_effort`); a generation prompt keeps the
template's own default.

---

**Returns:** `str | list[str] | torch.Tensor | BatchFeature`

Rendered text(s), `input_ids`, or the full batch.

```python
nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor.from_pretrained(
    pretrained_model_name_or_path: str | pathlib.Path,
    kwargs: nemo_automodel.components.models.hy_v4_flash.processing.TokenizerOption = {}
) -> nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor
```

classmethod

Load the tokenizer, the image token id and the image constants of a checkpoint.

```python
nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashProcessor.to_dict() -> nemo_automodel.components.models.hy_v4_flash.processing.ProcessorConfig
```

`processor_config.json` content: the `image_processor` block that `from_pretrained` reads.

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ImageProcessorConfig
```

**Bases:** `typing.TypedDict`

The fields of the `image_processor` block of the released `processor_config.json` that are consumed.

**`image_mean`** `list[float]`

---

**`image_std`** `list[float]`

---

**`max_pixels`** `int`

---

**`merge_size`** `int`

---

**`min_pixels`** `int`

---

**`patch_size`** `int`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ImageUrl
```

**Bases:** `typing.TypedDict`

`&#123;"url": ...&#125;` form of an image reference.

**`url`** `str`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ProcessorConfig
```

**Bases:** `typing.TypedDict`

`processor_config.json` as this processor writes it.

**`image_processor`** `ImageProcessorConfig`

---

**`image_token_id`** `int`

---

**`processor_class`** `str`

---

```python
class nemo_automodel.components.models.hy_v4_flash.processing.ProcessorOptions
```

**Bases:** `typing.TypedDict`

Tokenization options forwarded by the collator through `processor_kwargs`.

**`max_length`** `int`

---

**`padding`** `bool | str`

---

**`truncation`** `bool`

---

```python
nemo_automodel.components.models.hy_v4_flash.processing._open_image(
    value: Image.Image | str | pathlib.Path | bytes
) -> Image.Image
```

Decode an image source (PIL image, path or encoded bytes).

```python
nemo_automodel.components.models.hy_v4_flash.processing.image_grid(
    height: int,
    width: int,
    settings: nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashImageSettings
) -> tuple[int, int]
```

Patch grid `(grid_h, grid_w)` of an image of the given pixel size.

```python
nemo_automodel.components.models.hy_v4_flash.processing.image_settings_from_processor_config(
    block: nemo_automodel.components.models.hy_v4_flash.processing.ImageProcessorConfig
) -> nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashImageSettings
```

Preprocessing constants of a checkpoint's `processor_config.json` `image_processor` block.

```python
nemo_automodel.components.models.hy_v4_flash.processing.num_image_tokens(
    grid_h: int,
    grid_w: int,
    merge: int
) -> int
```

Placeholder count of one image: `(h / merge) * (w / merge + 1)` (one newline slot per merged row).

```python
nemo_automodel.components.models.hy_v4_flash.processing.preprocess_image(
    image: Image.Image,
    settings: nemo_automodel.components.models.hy_v4_flash.processing.HYV4FlashImageSettings
) -> tuple[torch.Tensor, tuple[int, int]]
```

Resize, normalize and patchify one PIL image (converted to RGB).

Returns `(patches, (grid_h, grid_w))` with `patches` of shape \[grid_h \* grid_w, 3 \* patch_size \* patch_size]
in row-major patch order.

```python
nemo_automodel.components.models.hy_v4_flash.processing.smart_resize(
    height: int,
    width: int,
    factor: int,
    min_pixels: int,
    max_pixels: int
) -> tuple[int, int]
```

Round both sides to multiples of `factor` while keeping the area inside `[min_pixels, max_pixels]`.

```python
nemo_automodel.components.models.hy_v4_flash.processing.training_reasoning_effort(
    messages: collections.abc.Sequence[nemo_automodel.components.models.hy_v4_flash.processing.ChatMessage]
) -> typing.Literal['no_think']
```

Reasoning mode of a complete (training) conversation: `"no_think"`, as the official fine-tuning scripts use.

The released template defaults to `'high'` (its inference default); rendering answer-only data in that mode
would train answers after an empty think block.

**Raises:**

* `ValueError`: If an assistant message carries reasoning. Such a turn renders as
  `&lt;think&gt;reasoning&lt;/think&gt;answer`, which the label builders of the training recipes do not supervise.

```python
nemo_automodel.components.models.hy_v4_flash.processing.IMAGE_PAD_TOKEN = '<｜hy_image▁pad:opensource｜>'
```

```python
nemo_automodel.components.models.hy_v4_flash.processing.ImageSource: TypeAlias = 'Image.Image | str | Path | bytes'
```

```python
nemo_automodel.components.models.hy_v4_flash.processing.TokenizerOption: TypeAlias = 'bool | int | str | list[str] | None'
```