nemo_automodel.components.models.glm5_next.state_dict_adapter

View as Markdown

Checkpoint conversion for the released GLM-5.3-Flash VLM.

The checkpoint already uses the native vision/text prefix layout. Conversion is needed for grouped EP experts, flat mHC/KDA parameters, the extra MTP layer, and 128x128 block-scaled FP8 training weights.

Module Contents

Classes

NameDescription
Glm5NextStateDictAdapterConvert GLM split experts and FP8 weights to trainable grouped BF16.

Functions

NameDescription
_apply_local_block_scalesApply global-grid block scales to one possibly misaligned local shard.
_hf_to_native_key-
_local_shard_offsetsReturn the global start coordinate of a DTensor’s contiguous local shard.
_native_to_hf_key-
_scale_placeholderCreate the global FP8 block-scale load destination for a 2-D weight.
_scale_shape-
dequantize_block_fp8Dequantize an e4m3 weight with 128x128 fp32 inverse scales.

Data

_BLOCK_SIZE

_FP8_WEIGHT

_HC_KEY

_KDA_PARAMETER

_NATIVE_HC_KEY

_NATIVE_KDA_PARAMETER

_SPARSE_O_WEIGHT

__all__

API

class nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter(
config: nemo_automodel.components.models.glm5_next.config.Glm5NextConfig,
moe_config: nemo_automodel.components.moe.config.MoEConfig,
backend: nemo_automodel.components.models.common.BackendConfig,
dtype: torch.dtype = torch.bfloat16
)

Bases: MoESplitExpertsStateDictMixin, StateDictAdapter

Convert GLM split experts and FP8 weights to trainable grouped BF16.

_expert_path_segment
str
_hf_prefix
str
nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter._dequantize(
state_dict: dict[str, typing.Any]
) -> None
nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter._is_fp8_weight(
key: str
) -> bool

Match the checkpoint’s quantized matrices, including DSA-only output projections.

nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter.convert_single_tensor_to_hf(
fqn: str,
tensor: typing.Any,
kwargs: typing.Any = {}
) -> list[tuple[str, typing.Any]]

Convert one native tensor, including split expert and FP8 load targets.

nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter.from_hf(
hf_state_dict: dict[str, typing.Any],
device_mesh: torch.distributed.device_mesh.DeviceMesh | None = None,
kwargs: typing.Any = {}
) -> dict[str, typing.Any]

Dequantize, drop MTP, route flat parameters and aggregate experts.

nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter.to_hf(
state_dict: dict[str, typing.Any],
exclude_key_regex: str | None = None,
quantization: bool = False,
kwargs: typing.Any = {}
) -> dict[str, typing.Any]

Expand grouped experts and restore released checkpoint names.

nemo_automodel.components.models.glm5_next.state_dict_adapter._apply_local_block_scales(
local_weight: torch.Tensor,
local_scale: torch.Tensor,
local_offsets: tuple[int, int],
dtype: torch.dtype
) -> torch.Tensor

Apply global-grid block scales to one possibly misaligned local shard.

nemo_automodel.components.models.glm5_next.state_dict_adapter._hf_to_native_key(
key: str
) -> str
nemo_automodel.components.models.glm5_next.state_dict_adapter._local_shard_offsets(
tensor: torch.Tensor
) -> tuple[int, ...]

Return the global start coordinate of a DTensor’s contiguous local shard.

nemo_automodel.components.models.glm5_next.state_dict_adapter._native_to_hf_key(
key: str
) -> str
nemo_automodel.components.models.glm5_next.state_dict_adapter._scale_placeholder(
weight: torch.Tensor
) -> torch.Tensor

Create the global FP8 block-scale load destination for a 2-D weight.

nemo_automodel.components.models.glm5_next.state_dict_adapter._scale_shape(
weight: torch.Tensor
) -> tuple[int, int]
nemo_automodel.components.models.glm5_next.state_dict_adapter.dequantize_block_fp8(
weight: torch.Tensor,
scale_inv: torch.Tensor,
dtype: torch.dtype = torch.bfloat16
) -> torch.Tensor

Dequantize an e4m3 weight with 128x128 fp32 inverse scales.

nemo_automodel.components.models.glm5_next.state_dict_adapter._BLOCK_SIZE = 128
nemo_automodel.components.models.glm5_next.state_dict_adapter._FP8_WEIGHT = re.compile('^model\\.language_model\\.layers\\.\\d+\\.(?:self_attn\\.(?:q_a_proj...
nemo_automodel.components.models.glm5_next.state_dict_adapter._HC_KEY = re.compile('^(model\\.language_model\\.layers\\.\\d+)\\.hc_(attn|ffn)_(fn|base|s...
nemo_automodel.components.models.glm5_next.state_dict_adapter._KDA_PARAMETER = re.compile('^(model\\.language_model\\.layers\\.\\d+\\.self_attn)\\.(A_log|dt_bi...
nemo_automodel.components.models.glm5_next.state_dict_adapter._NATIVE_HC_KEY = re.compile('^(model\\.language_model\\.layers\\.\\d+)\\.(attn_hc|ffn_hc)(?:\\._f...
nemo_automodel.components.models.glm5_next.state_dict_adapter._NATIVE_KDA_PARAMETER = re.compile('^(model\\.language_model\\.layers\\.\\d+\\.self_attn)\\._fp32_params...
nemo_automodel.components.models.glm5_next.state_dict_adapter._SPARSE_O_WEIGHT = re.compile('^model\\.language_model\\.layers\\.(\\d+)\\.self_attn\\.o_proj\\.wei...
nemo_automodel.components.models.glm5_next.state_dict_adapter.__all__ = ['Glm5NextStateDictAdapter', 'dequantize_block_fp8']