VisionConfig

Struct VisionConfig 

Source
pub struct VisionConfig {
Show 23 fields pub depth: usize, pub hidden_size: usize, pub num_heads: usize, pub patch_size: usize, pub temporal_patch_size: usize, pub spatial_merge_size: usize, pub intermediate_size: usize, pub out_hidden_size: usize, pub deepstack_visual_indexes: Vec<usize>, pub image_pad_token_id: u32, pub video_pad_token_id: u32, pub max_pixels: Option<usize>, pub hidden_act: String, pub rms_norm_eps: f32, pub attention_bias: bool, pub projection_intermediate_size: usize, pub swiglu_limit: f32, pub rope_theta: f32, pub image_mean: [f32; 3], pub image_std: [f32; 3], pub min_image_tokens: usize, pub max_image_tokens: usize, pub block_major_patches: bool,
}
Expand description

Vision encoder configuration for Qwen3-VL models.

Fields§

§depth: usize

Number of ViT transformer blocks (depth=27).

§hidden_size: usize

ViT hidden dimension (1152).

§num_heads: usize

Number of attention heads (16).

§patch_size: usize

Spatial patch size in pixels (16).

§temporal_patch_size: usize

Temporal patch size: still images are replicated this many times (2).

§spatial_merge_size: usize

2×2 spatial merge: this many patch-lengths merged into one token (2).

§intermediate_size: usize

ViT MLP intermediate size (4304).

§out_hidden_size: usize

Projection output dimension = LLM hidden_size (2048).

§deepstack_visual_indexes: Vec<usize>

Layer indices after which deepstack mergers are applied ([8, 16, 24]).

§image_pad_token_id: u32

Placeholder token ID that marks where vision embeddings get spliced into the text embedding stream. Qwen3-VL uses 151655; Qwen3.6 uses 248056. When 0 the runtime falls back to the legacy Qwen3-VL value.

§video_pad_token_id: u32

Placeholder token ID for VIDEO frames, the temporal sibling of Self::image_pad_token_id. Qwen3.6/3.8 use 248057. A distinct token is what lets the position builder tell a video item from an image one in the token stream, which matters because their MRoPE treatment differs: an image holds T constant across its whole pad run, a video advances T once per temporal group. When 0 the runtime falls back to the family default.

§max_pixels: Option<usize>

Resolved vision AREA bound in pixels: the operator’s --vision-max-pixels, else the checkpoint’s preprocessor_config.json, else None.

★ THE SINGLE SOURCE OF TRUTH, and it exists because there used to be two. The CPU preprocessor clamped every image to 1280px on the long side while the GPU encoder allocated its buffers for 6400 patches — exactly 1280×1280 — with nothing in the code connecting them. They agreed only by coincidence, so raising one on 2026-08-14 made every image above 1280px fail an H2D copy with CUDA_ERROR_INVALID_VALUE from deep inside the scheduler.

Both now derive from this field, resolved once at config load, before the encoder is constructed. None keeps the historical behaviour on both sides.

§hidden_act: String

Block-MLP activation. "silu" for GLM (a clamped SwiGLU); "gelu_pytorch_tanh" for the Qwen family’s 2-matrix GELU MLP.

§rms_norm_eps: f32

Epsilon of every RMSNorm in the tower (GLM: 1e-5). Unused by the Qwen tower, whose norms are LayerNorms at a compiled 1e-6.

§attention_bias: bool

Whether the ViT’s qkv/proj/MLP Linears carry biases (GLM: true).

§projection_intermediate_size: usize

Hidden width of GLM’s merger SwiGLU (10240). 0 when the family has no such stage.

§swiglu_limit: f32

Symmetric clamp applied inside GLM’s SwiGLU, on both the block MLP and the merger (10.0). 0 disables it.

§rope_theta: f32

Base of the ViT’s own rotary embedding. GLM’s vision_config carries rope_parameters = {rope_theta: 10000.0, rope_type: "axial"}.

§image_mean: [f32; 3]

Per-channel normalization the image processor applies. GLM ships CLIP-style stats; the Qwen family ships SigLIP’s 0.5/0.5/0.5, which is the default here so an absent preprocessor_config.json is unchanged.

§image_std: [f32; 3]§min_image_tokens: usize

Dynamic-resolution token budget (processor_config.json). GLM states its bound in MERGED tokens (16 / 8000) rather than as a pixel area; min_pixels/max_pixels = tokens * (patch_size * merge_size)^2.

§max_image_tokens: usize§block_major_patches: bool

Patch tokens are emitted in 2x2-block-major order rather than raster.

GLM’s image processor and its get_vision_position_ids share this nesting, which is the ONLY reason the tower’s view(-1, 2, 2, C) downsample reshape is free. A raster-ordered buffer through the same tower produces a perfectly plausible, wrong embedding — so the order is a declared property of the checkpoint, not an implementation detail of whoever writes the loop.

Implementations§

Source§

impl VisionConfig

Source

pub fn merger_input_size(&self) -> usize

Dimension of the merger input (spatial_merge_size² × hidden_size).

Trait Implementations§

Source§

impl Clone for VisionConfig

Source§

fn clone(&self) -> VisionConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VisionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VisionConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.