nemo_automodel.components.models.glm5_next
nemo_automodel.components.models.glm5_next
Native AutoModel support for zai-org/GLM-5.3-Flash.
Submodules
nemo_automodel.components.models.glm5_next.backendnemo_automodel.components.models.glm5_next.confignemo_automodel.components.models.glm5_next.cpnemo_automodel.components.models.glm5_next.flopsnemo_automodel.components.models.glm5_next.image_processingnemo_automodel.components.models.glm5_next.layersnemo_automodel.components.models.glm5_next.modelnemo_automodel.components.models.glm5_next.mtpnemo_automodel.components.models.glm5_next.optimized_kernelsnemo_automodel.components.models.glm5_next.parallelizationnemo_automodel.components.models.glm5_next.processingnemo_automodel.components.models.glm5_next.state_dict_adapternemo_automodel.components.models.glm5_next.vision
Package Contents
Classes
Data
API
Bases: PretrainedConfig
Top-level GLM-5.3 vision-language configuration.
Return the decoder config using the Transformers multimodal protocol.
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
Trainable GLM-5.3 VLM with PP, EP and contiguous packed CP support.
Expose the text module through the multimodal discovery protocol.
Embed the full sequence and replace image placeholder positions.
Shift the full-sequence embeddings once per MTP depth and keep this rank’s slice.
Parameters:
Spliced embeddings [batch, padded_sequence, hidden]
covering the whole (CP-padded) sequence.
Document map whose doc_ids are [batch, padded_sequence].
Returns: torch.Tensor
One [batch, local_sequence, hidden] tensor per depth; position t
Decode ids [B,S] or a PP activation [B,Slocal,hc_mult,H].
Vision splice and CP slicing run only on the embedding stage. Packed
metadata arrives as a chunkable tuple under multi-microbatch PP, then
gets a fresh per-microbatch boundary cache. streams below is
config.text_config.hc_mult; padded_global_sequence is the
global length padded to a multiple of the CP size, and
local_sequence is that length divided by the CP size.
Parameters:
Integer tensor of shape [microbatch, global_sequence] (or [global_sequence]) on the embedding stage; it is not CP sharded. Later PP stages receive residual streams of shape [microbatch, local_sequence, streams, hidden] in this position, already local to this CP rank.
Optional integer tensor of shape [microbatch,
global_sequence], binary or holding one-based document ids.
Read only when glm5_next_packed_context is None.
Ignored; positions follow the document map.
Optional tensor of shape [microbatch, global_sequence, hidden] on the embedding stage, padded and sliced here to this rank’s interval; or already-local [microbatch, local_sequence, streams, hidden] on later stages.
Optional Boolean tensor of shape [microbatch, local_sequence], with True marking padding. Defaults to nonpositive local document ids.
Optional flattened image patches of shape
[vision_patches, channels * temporal_patch * patch * patch].
Under PP microbatching the embedding stage reads its chunk
from _vlm_pixel_values_chunks instead.
Integer tensor of shape [images, 3] holding each
image’s (t, h, w) patch grid; required with pixel_values.
Unsupported; must be None. Empty PP chunks are treated as None.
0 to project every local position, or the
positions to keep as in slice_logits_to_keep.
Whether to attach final hidden states.
Per-microbatch context or
Glm5NextPackedMetadata (doc_ids, seq_start, cp_size,
original_seq_len). doc_ids is an
integer tensor of shape [microbatch, padded_global_sequence],
replicated across CP ranks; nonpositive values mark padding.
seq_start is the global offset of this rank’s contiguous
interval, and original_seq_len is the length before CP
padding. The global map is used even on later PP stages,
whose activations are already local. When None, a non-CP
context is built from input_ids, attention_mask,
padding_mask and cu_seqlens/_packed_seq_ids.
cu_seqlens and _packed_seq_ids feed the
fallback context. All kwargs reach the decoder layers.
Returns: Glm5NextCausalLMOutputWithPast | torch.Tensor
With _pp_return_hidden_states, the text-model tensor: [microbatch,
Raises:
ValueError: If the MTP head is enabled while the model is split into pipeline stages.
Construct from an already resolved native config.
Resolve the local config and generation settings; checkpoint loading is owned by AutoModel.
Return raw and merged features for flattened image patches.
Return the token embedding table.
Return the untied language-model head.
Describe token ids [B,S] and local mHC activations [B,S/CP,M,H].
CP pads the global length to a multiple of its size. Only the last
stage emits collapsed hidden states [B,S/CP,H] or logits
[B,S/CP,V]; the first stage still receives unsharded token ids.
Parameters:
Whether the stage owns the token embedding.
PP microbatch size.
Global sequence length before CP padding.
Activation dtype.
Returns: tuple[torch.Tensor, ...]
One-element input and output tuples of meta tensors. The input is
Initialize all tensors for checkpoint-free construction.
Install GLM’s contiguous packed sharder while leaving media and ids global.
Shift MTP targets globally with the same document map the GLM CP sharder uses.
Parameters:
Unsharded batch with input_ids and labels of shape
[batch, sequence] (or [sequence] from THD collaters) and
the packing metadata read by the GLM CP sharder.
Target fill value past each document end.
Returns: MTPContextParallelInputs
Global per-depth token ids, position ids, targets and validity masks of
Replace the token embedding table.
Replace the language-model head.
Update no-aux-loss router correction biases after an optimizer step.
Bases: PretrainedConfig
Configuration for the GLM-5.3 hybrid KDA/KPool-DSA text backbone.
Alias used by Hugging Face expert implementations.
Bases: PretrainedConfig
Configuration for the GLM-5.3 image/video encoder.