Skip to navigation

nemo_automodel.components.models.glm5_next

View as Markdown

Native AutoModel support for zai-org/GLM-5.3-Flash.

Submodules

Package Contents

Classes

NameDescription
Glm5NextConfigTop-level GLM-5.3 vision-language configuration.
Glm5NextForConditionalGenerationTrainable GLM-5.3 VLM with EP and contiguous packed CP support.
Glm5NextTextConfigConfiguration for the GLM-5.3 hybrid KDA/KPool-DSA text backbone.
Glm5NextVisionConfigConfiguration for the GLM-5.3 image/video encoder.

Data

ModelClass

API

class nemo_automodel.components.models.glm5_next.config.Glm5NextConfig(
text_config: dict[str, typing.Any] | nemo_automodel.components.models.glm5_next.config.Glm5NextTextConfig | None = None,
vision_config: dict[str, typing.Any] | nemo_automodel.components.models.glm5_next.config.Glm5NextVisionConfig | None = None,
image_token_id: int = 154854,
video_token_id: int = 154855,
image_start_token_id: int = 154830,
image_end_token_id: int = 154831,
video_start_token_id: int = 154832,
video_end_token_id: int = 154833,
tie_word_embeddings: bool = False,
kwargs: typing.Any = {}
)

Bases: PretrainedConfig

Top-level GLM-5.3 vision-language configuration.

hidden_size
= text_config.hidden_size
keys_to_ignore_at_inference
= ['past_key_values']
max_position_embeddings
= text_config.max_position_embeddings
model_type
= 'glm5_next'
sub_configs
vocab_size
= text_config.vocab_size
nemo_automodel.components.models.glm5_next.config.Glm5NextConfig.get_text_config(
decoder: bool = False

Return the decoder config using the Transformers multimodal protocol.

nemo_automodel.components.models.glm5_next.config.Glm5NextConfig.to_dict() -> dict[str, typing.Any]
class nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration(
kwargs: typing.Any = {}
)

Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin

Trainable GLM-5.3 VLM with EP and contiguous packed CP support.

_keep_in_fp32_modules_strict
_packed_cp_attn_backends
= ('sdpa', 'cudnn')
backend
language_model
Glm5NextTextModel

Expose the text module through the multimodal discovery protocol.

lm_head
model
state_dict_adapter
tie_word_embeddings_support
TieSupport = TieSupport.UNTIED_ONLY
vocab_size
= text_config.vocab_size
nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration._embed_and_splice(
input_ids: torch.Tensor,
pixel_values: torch.Tensor | None,
image_grid_thw: torch.Tensor | None
) -> torch.Tensor

Embed the full sequence and replace image placeholder positions.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.forward(
input_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
position_ids: torch.Tensor | None = None,
inputs_embeds: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
pixel_values: torch.Tensor | None = None,
image_grid_thw: torch.Tensor | None = None,
pixel_values_videos: torch.Tensor | None = None,
logits_to_keep: int | torch.Tensor = 0,
output_hidden_states: bool | None = None,
kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast

Run image splice, contiguous CP slicing, text decoding and lm head.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.from_config(
kwargs: typing.Any = {}
) -> 'Glm5NextForConditionalGeneration'
classmethod

Construct from an already resolved native config.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.from_pretrained(
pretrained_model_name_or_path: str,
model_args: typing.Any = (),
kwargs: typing.Any = {}
) -> 'Glm5NextForConditionalGeneration'
classmethod

Resolve the local config; checkpoint loading is owned by AutoModel.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.get_image_features(
pixel_values: torch.Tensor,
image_grid_thw: torch.Tensor

Return raw and merged features for flattened image patches.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.get_input_embeddings() -> torch.nn.Module

Return the token embedding table.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.get_output_embeddings() -> torch.nn.Module

Return the untied language-model head.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.initialize_weights(
buffer_device: torch.device | None = None,
dtype: torch.dtype = torch.bfloat16
) -> None

Initialize all tensors for checkpoint-free construction.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.prepare_model_inputs_for_cp(
batch: dict[str, typing.Any],
num_chunks: int = 1
) -> dict[str, typing.Any]

Install GLM’s contiguous packed sharder while leaving media and ids global.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.set_input_embeddings(
value: torch.nn.Module
) -> None

Replace the token embedding table.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.set_output_embeddings(
value: torch.nn.Module
) -> None

Replace the language-model head.

nemo_automodel.components.models.glm5_next.model.Glm5NextForConditionalGeneration.update_moe_gate_bias() -> None

Update no-aux-loss router correction biases after an optimizer step.

class nemo_automodel.components.models.glm5_next.config.Glm5NextTextConfig(
vocab_size: int = 154880,
hidden_size: int = 4096,
intermediate_size: int = 12288,
moe_intermediate_size: int = 2048,
num_hidden_layers: int = 45,
num_attention_heads: int = 64,
num_key_value_heads: int = 64,
n_shared_experts: int = 1,
n_routed_experts: int = 288,
routed_scaling_factor: float = 2.5,
kv_lora_rank: int = 512,
q_lora_rank: int = 1536,
qk_rope_head_dim: int = 0,
qk_nope_head_dim: int = 256,
v_head_dim: int = 256,
n_group: int = 1,
topk_group: int = 1,
num_experts_per_tok: int = 8,
norm_topk_prob: bool = True,
mlp_layer_types: list[str] | None = None,
layer_types: list[str] | None = None,
indexer_types: list[str] | None = None,
index_topk_pattern: str | list[str] | None = None,
index_topk_freq: int = 1,
index_skip_topk_offset: int = 2,
index_topk: int = 2048,
index_head_dim: int = 128,
index_n_heads: int = 32,
index_kpool: int = 16,
index_kpool_always_select_tail: bool = True,
hidden_act: str = 'silu',
swiglu_limit: float = 10.0,
linear_head_dim: int = 128,
linear_num_heads: int = 64,
linear_conv_kernel_dim: int = 4,
linear_lower_bound: float | None = -5.0,
linear_attn_config: dict[str, typing.Any] | None = None,
hc_mult: int = 4,
hc_eps: float = 1e-06,
hc_sinkhorn_iters: int = 20,
max_position_embeddings: int = 1048576,
initializer_range: float = 0.02,
rms_norm_eps: float = 1e-05,
use_cache: bool = False,
attention_bias: bool = False,
attention_dropout: float = 0.0,
output_router_logits: bool = False,
router_aux_loss_coef: float = 0.001,
num_nextn_predict_layers: int = 1,
pad_token_id: int | None = 154820,
bos_token_id: int | None = None,
eos_token_id: int | list[int] | None = None,
tie_word_embeddings: bool = False,
kwargs: typing.Any = {}
)

Bases: PretrainedConfig

Configuration for the GLM-5.3 hybrid KDA/KPool-DSA text backbone.

attribute_map
= {'num_local_experts': 'n_routed_experts'}
indexer_types
= list(indexer_types)
keys_to_ignore_at_inference
= ['past_key_values']
layer_types
= list(layer_types)
linear_attn_config
mlp_layer_types
= list(mlp_layer_types)
model_type
= 'glm5_next_text'
num_local_experts
int

Alias used by Hugging Face expert implementations.

qk_head_dim
= qk_nope_head_dim + qk_rope_head_dim
nemo_automodel.components.models.glm5_next.config.Glm5NextTextConfig.to_dict() -> dict[str, typing.Any]
class nemo_automodel.components.models.glm5_next.config.Glm5NextVisionConfig(
depth: int = 24,
hidden_size: int = 1024,
hidden_act: str = 'silu',
attention_bias: bool = True,
attention_dropout: float = 0.0,
num_heads: int = 16,
in_channels: int = 3,
image_size: int = 448,
patch_size: int = 14,
rms_norm_eps: float = 1e-05,
spatial_merge_size: int = 2,
temporal_patch_size: int = 2,
out_hidden_size: int = 4096,
intermediate_size: int = 4096,
projection_intermediate_size: int = 10240,
initializer_range: float = 0.02,
swiglu_limit: float = 10.0,
kwargs: typing.Any = {}
)

Bases: PretrainedConfig

Configuration for the GLM-5.3 image/video encoder.

model_type
= 'glm5_next_vision'
nemo_automodel.components.models.glm5_next.config.Glm5NextVisionConfig.to_dict() -> dict[str, typing.Any]
nemo_automodel.components.models.glm5_next.ModelClass = Glm5NextForConditionalGeneration