> 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.models.deepseek_v4.processing

Processor for DeepSeek-V4-Flash-Vision-Exp.

## Module Contents

### Classes

| Name                                                                                                              | Description                                                          |
| ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`DeepseekV4VisionProcessor`](#nemo_automodel-components-models-deepseek_v4-processing-DeepseekV4VisionProcessor) | Exact prompt and dynamic-resolution image processor for DSV4 Vision. |

### Functions

| Name                                                                                                | Description                                                         |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| [`_load_pil_image`](#nemo_automodel-components-models-deepseek_v4-processing-_load_pil_image)       | Load a supported local, byte, dictionary, or PIL image as RGB.      |
| [`build_image_block`](#nemo_automodel-components-models-deepseek_v4-processing-build_image_block)   | Build reference N-layout token types and aligned-image permutation. |
| [`grid_tokens`](#nemo_automodel-components-models-deepseek_v4-processing-grid_tokens)               | Return the aligned LLM grid and N-layout token count for one image. |
| [`preprocess_image`](#nemo_automodel-components-models-deepseek_v4-processing-preprocess_image)     | Transform one image into normalized ViT patches.                    |
| [`safe_resize`](#nemo_automodel-components-models-deepseek_v4-processing-safe_resize)               | Fit an image to the reference N-layout visual-token budget.         |
| [`solve_resize_ratio`](#nemo_automodel-components-models-deepseek_v4-processing-solve_resize_ratio) | Solve the reference resize approximation for a visual-token budget. |

### Data

[`ASSISTANT_TOKEN`](#nemo_automodel-components-models-deepseek_v4-processing-ASSISTANT_TOKEN)

[`BOS_TOKEN`](#nemo_automodel-components-models-deepseek_v4-processing-BOS_TOKEN)

[`COMPRESS_PAD_TO`](#nemo_automodel-components-models-deepseek_v4-processing-COMPRESS_PAD_TO)

[`DEEPSEEK_V4_LABEL_CHAT_TEMPLATE`](#nemo_automodel-components-models-deepseek_v4-processing-DEEPSEEK_V4_LABEL_CHAT_TEMPLATE)

[`EOS_TOKEN`](#nemo_automodel-components-models-deepseek_v4-processing-EOS_TOKEN)

[`IMAGE_PLACEHOLDER`](#nemo_automodel-components-models-deepseek_v4-processing-IMAGE_PLACEHOLDER)

[`THINKING_END_TOKEN`](#nemo_automodel-components-models-deepseek_v4-processing-THINKING_END_TOKEN)

[`USER_TOKEN`](#nemo_automodel-components-models-deepseek_v4-processing-USER_TOKEN)

[`__all__`](#nemo_automodel-components-models-deepseek_v4-processing-__all__)

### API

```python
class nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor(
    tokenizer: typing.Any,
    config: nemo_automodel.components.models.deepseek_v4.config.DeepseekV4Config,
    chat_template: str | None = None,
    kwargs: typing.Any = {}
)
```

**Bases:** `ProcessorMixin`

Exact prompt and dynamic-resolution image processor for DSV4 Vision.

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

---

**`image_token_id`** `int`

Return the textual placeholder ID that is expanded before padding.

---

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

---

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor.__call__(
    text: str | list[str],
    images: typing.Any = None,
    return_tensors: str | None = None,
    kwargs: typing.Any = {}
) -> transformers.feature_extraction_utils.BatchFeature
```

Tokenize text and expand each image placeholder into pseudo IDs.

Returns a batch whose `input_ids`, `attention_mask`, and
`vision_token_types` use layout `[batch, sequence]`;
`pixel_values` uses `[all_patches, 3, patch_size, patch_size]` and
`image_grid_hws` uses `[all_images, 2]`.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor._content_text_and_images(
    content: typing.Any
) -> tuple[str, list[typing.Any]]
```

staticmethod

Render ordered content blocks and collect their image values.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor._render_conversation(
    conversation: typing.Sequence[dict[str, typing.Any]]
) -> tuple[str, list[typing.Any]]
```

Render one standard conversation into the released chat format.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor.apply_chat_template(
    conversation: typing.Sequence[dict[str, typing.Any]] | typing.Sequence[typing.Sequence[dict[str, typing.Any]]],
    tokenize: bool = False,
    return_dict: bool = False,
    return_tensors: str | None = None,
    processor_kwargs: dict[str, typing.Any] | None = None,
    kwargs: typing.Any = {}
) -> typing.Any
```

Render or tokenize one conversation or a batch of conversations.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor.batch_decode(
    args: typing.Any = (),
    kwargs: typing.Any = {}
) -> list[str]
```

Forward batched decoding to the underlying tokenizer.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor.decode(
    args: typing.Any = (),
    kwargs: typing.Any = {}
) -> str
```

Forward decoding to the underlying tokenizer.

```python
nemo_automodel.components.models.deepseek_v4.processing.DeepseekV4VisionProcessor.from_pretrained(
    pretrained_model_name_or_path: str,
    kwargs: typing.Any = {}
) -> 'DeepseekV4VisionProcessor'
```

classmethod

Load the tokenizer and vision settings from one checkpoint.

```python
nemo_automodel.components.models.deepseek_v4.processing._load_pil_image(
    value: typing.Any
) -> PIL.Image.Image
```

Load a supported local, byte, dictionary, or PIL image as RGB.

```python
nemo_automodel.components.models.deepseek_v4.processing.build_image_block(
    n_llm_h: int,
    n_llm_w: int,
    start_pos: int
) -> tuple[torch.Tensor, torch.Tensor]
```

Build reference N-layout token types and aligned-image permutation.

**Returns:** `torch.Tensor`

`types` with layout `[image_block_tokens]` and `perm` with layout

```python
nemo_automodel.components.models.deepseek_v4.processing.grid_tokens(
    best_height: int,
    best_width: int,
    patch_size: int,
    downsample_ratio: int
) -> tuple[int, int, int]
```

Return the aligned LLM grid and N-layout token count for one image.

```python
nemo_automodel.components.models.deepseek_v4.processing.preprocess_image(
    value: typing.Any,
    config: nemo_automodel.components.models.deepseek_v4.config.DeepseekV4Config
) -> tuple[torch.Tensor, int, int, int, int]
```

Transform one image into normalized ViT patches.

**Returns:** `torch.Tensor`

Patches with layout `[n_vit_h * n_vit_w, 3, patch_size, patch_size]`

```python
nemo_automodel.components.models.deepseek_v4.processing.safe_resize(
    height: int | float,
    width: int | float,
    best_height: int,
    best_width: int,
    patch_size: int,
    downsample_ratio: int,
    max_n_token: int
) -> tuple[int, int, int, int]
```

Fit an image to the reference N-layout visual-token budget.

```python
nemo_automodel.components.models.deepseek_v4.processing.solve_resize_ratio(
    height: int | float,
    width: int | float,
    patch_size: int,
    downsample_ratio: int,
    max_n_token: int
) -> tuple[int, int, int, int, int]
```

Solve the reference resize approximation for a visual-token budget.

```python
nemo_automodel.components.models.deepseek_v4.processing.ASSISTANT_TOKEN = '<｜Assistant｜>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.BOS_TOKEN = '<｜begin▁of▁sentence｜>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.COMPRESS_PAD_TO = 4
```

```python
nemo_automodel.components.models.deepseek_v4.processing.DEEPSEEK_V4_LABEL_CHAT_TEMPLATE = "{%- if messages %}{{- bos_token }}{%- endif -%}\n{%- for message in messages -%...
```

```python
nemo_automodel.components.models.deepseek_v4.processing.EOS_TOKEN = '<｜end▁of▁sentence｜>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.IMAGE_PLACEHOLDER = '<｜deepseek_image｜>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.THINKING_END_TOKEN = '</think>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.USER_TOKEN = '<｜User｜>'
```

```python
nemo_automodel.components.models.deepseek_v4.processing.__all__ = ['ASSISTANT_TOKEN', 'BOS_TOKEN', 'COMPRESS_PAD_TO', 'DeepseekV4VisionProcessor',...
```