Module vision_encoder

Module vision_encoder 

Source
Expand description

2026-09-25: The Qwen3-VL-shaped vision encoder: a ViT with optional DeepStack mergers.

Owner: model-layers (vision). Invariants:

  • At most one scratch group is stored (scratch is a OnceLock); it is set on the first image or by VisionTower::ensure_scratch.

Pixels go through patch embedding, the ViT blocks and a final spatial merger. The first Σmerged_p rows of buf_out hold the final merger’s output, [Σmerged_p, out_hidden_size] BF16, which the LLM embeds. Each DeepStack merger listed in deepstack_indexes writes its own region after that in the batched path; the LLM does not read those regions.

Structs§

MergerLayer
ViTBlock
VisionEncoder
VisionScratch
2026-09-25: The ViT’s per-image scratch buffers, allocated as one group.

Constants§

IMAGE_PAD_TOKEN_ID
VIDEO_PAD_TOKEN_ID
2026-09-25: Fallback <|video_pad|> id, used when the checkpoint’s config declares none (or 0). The Qwen3-VL, Qwen3.6 and Qwen3.8 checkpoints all put the video token directly after the image token. A declared id always wins, as for the image token.