mstar.model.qwen3_5.components.vision#
Qwen3.5’s vision tower: a ViT over packed image patches.
Ported from transformers’ modeling_qwen3_5.py and vision_utils.py
(Apache-2.0); the grid helpers are copied because transformers.vision_utils
is internal. Dropped, as Qwen3.5 does not use them: bicubic resampling, the
temporal rotary axis, and deepstack.
Images arrive packed: pixel_values is [total_patches, patch_numel] and
grid_thw gives each image’s (t, h, w) patch grid.
Functions
|
Gather indices and weights that resample the square learned position table onto each image's |
|
|
|
One attending segment per frame, on the host: |
Classes
|
|
|
Full attention within each frame, over packed patches. |
|
|
|
Plain, not gated: one up projection, an activation, one down. |
|
|
|
Folds each |
|
Axial 2D rope: the same frequencies drive the H and W axes, and the two halves are concatenated to cover the whole head — no partial rotation. |
- class mstar.model.qwen3_5.components.vision.Qwen3_5VisionModel(config)[source]#
Bases:
Module- Parameters:
config (Qwen3_5VisionConfig)
- embed(pixel_values, indices, weights, position_ids)[source]#
Patch embed plus the resampled position table, and the rope for the blocks: everything before the block loop, per patch.
- encode(hidden, cos, sin)[source]#
The block loop,
[patches, hidden]in and out – the part a CUDA graph can hold (seeVisionEncoderSubmodule).
- forward(pixel_values, indices, weights, position_ids)[source]#
[total_patches, patch_numel]in,[merged_tokens, out_hidden]out — one token perspatial_merge_size ** 2block of patches.Grid-derived inputs are built by the caller (
VisionEncoderSubmodule.prepare_inputs):grid_thw.tolist()here would break the graph and make h, w unbacked symints, and inductor then refuses (CantSplit) to codegen packed multi-image runs.
- class mstar.model.qwen3_5.components.vision.VisionAttention(config)[source]#
Bases:
ModuleFull attention within each frame, over packed patches.
The ragged attention resource plans the per-frame layout, so this forward never sees the boundaries. That is what lets the tower compile: splitting per frame here gave each frame its own symint, and inductor then refused (
CantSplit) to codegen packed runs of three or more images.- Parameters:
config (Qwen3_5VisionConfig)
- bind_resources(resources)[source]#
See
NodeSubmodule.bind_node_resources..get: a deployment that never builds the vision node binds nothing here.- Parameters:
resources (dict)
- Return type:
None
- forward(hidden_states, cos, sin)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.qwen3_5.components.vision.VisionBlock(config)[source]#
Bases:
Module- Parameters:
config (Qwen3_5VisionConfig)
- forward(hidden_states, cos, sin)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.qwen3_5.components.vision.VisionMLP(config)[source]#
Bases:
ModulePlain, not gated: one up projection, an activation, one down.
- Parameters:
config (Qwen3_5VisionConfig)
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.qwen3_5.components.vision.VisionPatchEmbed(config)[source]#
Bases:
Module- Parameters:
config (Qwen3_5VisionConfig)
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.qwen3_5.components.vision.VisionPatchMerger(config)[source]#
Bases:
ModuleFolds each
m x mblock of patches into one LLM-width token.- Parameters:
config (Qwen3_5VisionConfig)
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.qwen3_5.components.vision.VisionRotaryEmbedding(config)[source]#
Bases:
ModuleAxial 2D rope: the same frequencies drive the H and W axes, and the two halves are concatenated to cover the whole head — no partial rotation.
- Parameters:
config (Qwen3_5VisionConfig)
- forward(position_ids)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- mstar.model.qwen3_5.components.vision.vision_interpolation(grid, num_grid_per_side, spatial_merge_size, device)[source]#
Gather indices and weights that resample the square learned position table onto each image’s
(h, w)grid.Returns
[total_patches, 4]each — the 2x2 bilinear neighbourhood per patch, as the outer product of the two axes’ taps.