Skip to navigation

nemo_automodel.components.models.qwen3_8_flash_next.vision

View as MarkdownOpen in Claude

Image inputs of Qwen3.8-Flash-Next: the vision tower and multimodal rotary positions.

The reference vision stack of this family (Qwen4ExpVisionModel in Transformers) is the Qwen3.5-MoE tower with different sizes only, so the released Qwen3_5MoeVisionModel is used as is. Video inputs are not implemented.

Module Contents

Classes

NameDescription
Qwen3_8_FlashNextVisionModelQwen3-VL-style vision tower: 3D patch embedding, 2D rotary blocks and a 2x2 patch merger.

Functions

NameDescription
qwen3_8_flash_next_image_position_idsBuild the three-axis rotary positions of rows that mix text and images.

Data

_IMAGE_TOKEN_TYPE

_TEXT_TOKEN_TYPE

API

class nemo_automodel.components.models.qwen3_8_flash_next.vision.Qwen3_8_FlashNextVisionModel(
)

Bases: Qwen3_5MoeVisionModel

Qwen3-VL-style vision tower: 3D patch embedding, 2D rotary blocks and a 2x2 patch merger.

Tensor layout

forward(hidden_states, grid_thw) takes flattened patches [patches, in_channels * temporal_patch_size * patch_size * patch_size] of every image in order and the per-image unmerged patch grid [images, 3] as (frames, height, width). pooler_output holds the merged features [patches / spatial_merge_size ** 2, out_hidden_size] in the same order; last_hidden_state is [patches, hidden_size].

Parameters:

config
Qwen3_8_FlashNextVisionConfig

Vision architecture configuration. deepstack_visual_indexes must be empty: the tower returns only its final merged features.

rotary_pos_emb
= Fp32SafeQwen3_5MoeVisionRotaryEmbedding(hf_config)
nemo_automodel.components.models.qwen3_8_flash_next.vision.Qwen3_8_FlashNextVisionModel.reset_parameters() -> None

Initialize every weight and the rotary frequencies with the reference initializer.

nemo_automodel.components.models.qwen3_8_flash_next.vision.qwen3_8_flash_next_image_position_ids(
mm_token_type_ids: torch.Tensor,
image_grid_thw: torch.Tensor,
attention_mask: torch.Tensor | None,
spatial_merge_size: int
) -> torch.Tensor

Build the three-axis rotary positions of rows that mix text and images.

Each row is read left to right over its valid tokens with a running start position. A text run of n tokens takes the next n positions on all three axes. An image whose merged grid is (frames, rows, cols) and that starts at position p gets p + frame on the temporal axis, p + row on the height axis and p + col on the width axis, in frame, row, column raster order; the token after it continues at p + max(rows, cols). Padding keeps position zero on every axis.

Parameters:

mm_token_type_ids
torch.Tensor

Integer tensor [batch, sequence]; 0 marks a text token and 1 an image placeholder.

image_grid_thw
torch.Tensor

Integer tensor [images, 3] with the unmerged (frames, height, width) patch counts of every image, in order of appearance over the rows of the batch.

attention_mask
torch.Tensor | None

Optional tensor [batch, sequence]; nonzero marks a real token. None treats every token as real.

spatial_merge_size
int

Side of the square of patches merged into one language token.

Returns: torch.Tensor

Long tensor [3, batch, sequence] on the device of

Raises:

  • ValueError: If an image placeholder run does not have the token count of its grid, or the number of runs differs from the number of grids.
  • NotImplementedError: If a token type other than text or image appears.
nemo_automodel.components.models.qwen3_8_flash_next.vision._IMAGE_TOKEN_TYPE = 1
nemo_automodel.components.models.qwen3_8_flash_next.vision._TEXT_TOKEN_TYPE = 0