nemo_automodel.components.models.hy_v4_flash.processing
nemo_automodel.components.models.hy_v4_flash.processing
Image-text processor of Hy4-flash.
The released chat template renders each image as <image_start><image_pad><image_end>; 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
Functions
Data
API
Bases: typing.TypedDict
One text or image block of a chat message (the Hugging Face multimodal chat format).
Bases: typing.TypedDict
One chat message with string content or an ordered list of content blocks.
Preprocessing constants of processor_config.json: patch and merge size, pixel bounds, mean and std.
Bases: ProcessorMixin
Expand image placeholders and build vision inputs for the Hy4-flash chat format.
Parameters:
Fast tokenizer of the checkpoint (carries the chat template and the image tokens).
Id of the image pad token (config.image_token_id).
Image preprocessing constants.
Tokenize rendered prompts, expanding every image pad.
Parameters:
Rendered prompt(s), each containing one image pad token per image.
Images grouped per prompt (or one prompt’s flat list).
"pt" or None (ragged lists).
False, True / "longest" or "max_length" (right padding).
Whether max_length removes trailing tokens; cutting through an image raises.
Token limit after image expansion.
Extra tokenizer arguments.
Returns: BatchFeature
BatchFeature with input_ids / attention_mask / mm_token_type_ids of shape [batch, sequence]
Replace image payloads with bare {"type": "image"} blocks and collect the sources in order.
Render conversations with the checkpoint’s jinja template and, optionally, tokenize them.
Parameters:
Chat messages (or a batch of them) with string or text / image content blocks.
Whether to tokenize (expanding images) instead of returning the rendered text.
Whether to return the whole BatchFeature.
"pt" or None.
Append the assistant header.
Padding / truncation arguments for __call__.
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.
Load the tokenizer, the image token id and the image constants of a checkpoint.
processor_config.json content: the image_processor block that from_pretrained reads.
Bases: typing.TypedDict
The fields of the image_processor block of the released processor_config.json that are consumed.
Bases: typing.TypedDict
{"url": ...} form of an image reference.
Bases: typing.TypedDict
processor_config.json as this processor writes it.
Bases: typing.TypedDict
Tokenization options forwarded by the collator through processor_kwargs.
Decode an image source (PIL image, path or encoded bytes).
Patch grid (grid_h, grid_w) of an image of the given pixel size.
Preprocessing constants of a checkpoint’s processor_config.json image_processor block.
Placeholder count of one image: (h / merge) * (w / merge + 1) (one newline slot per merged row).
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.
Round both sides to multiples of factor while keeping the area inside [min_pixels, max_pixels].
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<think>reasoning</think>answer, which the label builders of the training recipes do not supervise.