Module glm_vit

Module glm_vit 

Source
Expand description

2026-09-25: The GLM-5.3-Flash vision tower: ViT blocks with per-head QK-RMSNorm, 2D axial RoPE and clamped SwiGLU, then a 2×2 strided-conv downsample and a SwiGLU merger.

A separate type from super::VisionEncoder (the Qwen3-VL tower), with its own kernel module (glm_vit); both use the gemm module’s dense_gemm_bf16_pipelined and dense_gemm_bf16_f32out. Callers reach either through super::VisionTower, which gives both the same forward_batched result and out_row contract.

Owner: model-layers (vision). Invariants:

  • Assumes every weight pointer is a BF16 tensor. GlmVit::new does not check; the loader (load_glm5_next_vision) refuses other dtypes.
  • The scratch is set at most once, for p_max patch rows.

Re-exports§

pub use init::GlmVitGeometry;

Modules§

init
2026-09-25: GlmVit::new and the device scratch allocated on first use.

Structs§

GlmVit
GlmVitBlock
2026-09-25: One ViT block’s BF16 weights.
GlmVitMerger
2026-09-25: Everything after the last block: the post-norm, the 2×2 conv downsample and the merger MLP whose output fills buf_out.
GlmVitScratch
2026-09-25: Device scratch, allocated by scratch_init on first use rather than at load. buf_scores and buf_probs hold p_max² elements.

Functions§

block_major_position_ids
2026-09-25: Per-token (h_id, w_id) in block-major order: the outer loops walk the merge × merge blocks in raster order, the inner loops the positions inside a block. This is the order vision_preprocess_glm::block_major_patch_index gives the pixel patches.
build_axial_rope_tables
2026-09-25: (cos, sin) tables of [num_tokens, head_dim] f32, in the layout glm_vit_qknorm_rope_deint reads.