vllm.model_executor.models.glm4_1v
¶
Inference-only GLM-4.1V & GLM-4.6V-Flash, AutoGLM-Phone-9B model compatible with HuggingFace weights.
Classes:
-
Glm4vForConditionalGeneration– -
Glm4vImageEmbeddingInputs–Dimensions:
-
Glm4vImagePixelInputs–Dimensions:
-
Glm4vMultiModalDataParser–Placeholder metadata shared by GLM-4V and GLM-5.3-Flash.
-
Glm4vMultiModalProcessor– -
Glm4vProcessingInfo– -
Glm4vVideoEmbeddingInputs–Dimensions:
-
Glm4vVideoPixelInputs–Dimensions:
-
Glm4vVisionTransformer–
Glm4vForConditionalGeneration
¶
Bases: Module, SupportsMultiModal, Qwen2VLEncoderCudaGraphMixin, SupportsLoRA, SupportsPP, SupportsMRoPE
Methods:
-
forward–Run forward pass for GLM-4V.
-
get_mm_mapping–Get the module prefix in multimodal models.
forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)
¶
Run forward pass for GLM-4V.
Parameters:
-
(input_ids¶Tensor | None) –Flattened (concatenated) input_ids corresponding to a batch.
-
(positions¶Tensor) –Flattened (concatenated) position ids corresponding to a batch. NOTE: If mrope is enabled (default setting for GLM-4V opensource models), the shape will be
(3, seq_len), otherwise it will be `(seq_len,). -
(intermediate_tensors¶IntermediateTensors | None, default:None) –Optional intermediate tensors for pipeline parallelism.
-
(inputs_embeds¶Tensor | None, default:None) –Optional pre-computed input embeddings.
-
(**kwargs¶object, default:{}) –Additional keyword arguments.
get_mm_mapping()
¶
Get the module prefix in multimodal models.
Glm4vImageEmbeddingInputs
¶
Bases: TensorSchema
Dimensions: - f: Number of image features (varies based on image resolution) - h: Hidden size (must match language model backbone) - n: Number of images - g: Grid dimensions (3 for grid_t, grid_h, grid_w)
Glm4vImagePixelInputs
¶
Bases: TensorSchema
Dimensions: - np: Number of patches - cpp: Number of channels * patch_size * patch_size - ni: Number of images - g: Grid dimensions (3 for grid_t, grid_h, grid_w)
Glm4vMultiModalDataParser
¶
Bases: MultiModalDataParser
Placeholder metadata shared by GLM-4V and GLM-5.3-Flash.
The patch grid sizes image placeholders. Video placeholders also embed one timestamp string per temporal patch, so those timestamps travel with the grid when embeddings arrive through the EC connector.
_check_supplied_embeds(data, *, embed_key, grid_key, modality)
¶
Reject dict embeddings whose shape cannot match this grid.
Metadata-only requests omit the embedding tensor and stay valid.
Glm4vMultiModalProcessor
¶
Bases: BaseMultiModalProcessor[Glm4vProcessingInfo]
_sampled_frame_metadata_overrides(mm_items, video_metadata)
staticmethod
¶
Build timestamp-helper metadata from HF-sampled frame indices.
Input frames_indices can be the pre-sample range. The processor
returns a VideoMetadata with the sample it kept. GLM-5.3's direct
path must feed those indices into the timestamp helper and clear
do_sample_frames so the helper keeps them instead of sampling again.
Overrides are returned and never written back onto mm_items. The
same items are reused by test_processing_correctness (baseline then
cache); persisting do_sample_frames=False while the video tensor
stays full-length made pass-2 HF emit grid_t != len(timestamps) for
odd-length videos.
Glm4vProcessingInfo
¶
Bases: BaseProcessingInfo
_get_image_max_pixels()
¶
Read max_pixels from the HF image processor config.
Despite the name, longest_edge is a pixel area (total pixel
count), not an edge length. The HF processor passes it directly to
smart_resize as the max_pixels argument, which constrains
t_bar * h_bar * w_bar <= max_pixels.
_get_video_second_idx_glmga(metadata, total_frames)
¶
Fixed fps=2 frame selection matching GlmgaVideoProcessor.sample_frames.
_is_glmga_model(processor)
¶
Detect GLMGA variant via its Glmga sub-processors.
Glm4vVideoEmbeddingInputs
¶
Bases: TensorSchema
Dimensions: - p: Number of video patches across all frames - h: Hidden size (must match language model backbone) - f: Number of frames - g: Grid dimensions (3 for grid_t which is usually 1 for processed video, grid_h, grid_w)
Glm4vVideoPixelInputs
¶
Bases: TensorSchema
Dimensions: - np: Number of patches - ctpp: Number of channels * temporal_patch_size * patch_size * patch_size - f: Number of frames - g: Grid dimensions (3 for grid_t which is usually 1 for processed video, grid_h, grid_w)
Glm4vVisionTransformer
¶
Bases: Module
Methods:
-
pos_embeds_interpolate–Pre-compute absolute position embeddings for all input samples.
-
prepare_encoder_metadata–Compute encoder metadata from grid_thw_list.
pos_embeds_interpolate(grid_thw)
¶
Pre-compute absolute position embeddings for all input samples.
The original self.embeddings fused token embeddings and position embeddings
in one call, which prevented preparing position embeddings as static metadata
required by CUDA graph capture / replay. This method decouples the two by
feeding an all-zero token tensor to self.embeddings. The module therefore only
performs bicubic interpolation based on the coordinates and returns pure
position embeddings. These are cached in prepare_encoder_metadata and later
added to the patch tokens in forward via x = x + pos_embeds, keeping the
forward graph compatible with CUDA graph replay. Coordinate generation matches
rot_pos_emb exactly to guarantee spatial alignment.
prepare_encoder_metadata(grid_thw_list, *, max_batch_size=None, max_frames_per_batch=None, max_seqlen_override=None, device=None)
¶
Compute encoder metadata from grid_thw_list.
Shared by the eager forward path, CUDA graph capture, and CUDA graph replay to avoid duplicated implementation.
Parameters:
-
(grid_thw_list¶list[list[int]]) –Grid configurations as list of [t, h, w].
-
(max_batch_size¶int | None, default:None) –If set, pad cu_seqlens to this size (needed for CUDA graph capture/replay).
-
(max_frames_per_batch¶int | None, default:None) –If set, overrides max_batch_size for cu_seqlens padding. For video inputs each item contributes T attention sequences (frames); this sizes the buffer to the total frame budget so video replays never overflow.
-
(max_seqlen_override¶int | None, default:None) –If set, use this value for max_seqlen instead of computing from cu_seqlens (needed for CUDA graph capture to cover worst-case replay scenarios).
-
(device¶device | None, default:None) –Device to place tensors on. Defaults to self.device.