nemo_automodel.components.models.kimi_k3.state_dict_adapter
nemo_automodel.components.models.kimi_k3.state_dict_adapter
State-dict conversion for native Kimi K3 and its MXFP4 checkpoint.
Module Contents
Classes
Functions
Data
API
Bases: MoESplitExpertsStateDictMixin, StateDictAdapter
Convert K3 split/packed experts to AutoModel grouped experts.
HF stores routed experts as per-expert Kimi names:
block_sparse_moe.experts.{E}.w1.weight: SwiGLU gate projection, shape [inter, hidden].block_sparse_moe.experts.{E}.w3.weight: SwiGLU up projection, shape [inter, hidden].block_sparse_moe.experts.{E}.w2.weight: down projection, shape [hidden, inter].
Automodel stores grouped experts as:
mlp.experts.gate_and_up_projswith shape [experts, hidden, 2 * inter].mlp.experts.down_projswith shape [experts, inter, hidden].
The decoder block names both its dense and its MoE feed-forward mlp (the
naming the custom-MoE parallelizer looks for), so the checkpoint’s
block_sparse_moe path segment is translated here in both directions.
Prefix native text keys while leaving vision/projector keys unchanged.
Decode packed experts, writing directly into model views when available.
Create packed checkpoint destinations matching one plain [out, in] expert weight.
Remove K3’s zero padding from the per-head KDA decay parameter.
Restore the 128-entry checkpoint storage layout for KDA A_log.
Split grouped experts, tolerating DTensors whose mesh dim is not named ep.
Parameters:
Grouped routed-expert tensor of shape [experts, …]. May be a plain tensor or a DTensor sharded or replicated over the expert axis; for Shard(0), the local shard covers this rank’s expert slice.
Global number of routed experts.
Returns: list[torch.Tensor]
List of per-expert tensors of shape […] for the experts local to this rank.
Remove the K3 checkpoint’s language_model. namespace.
Convert one Automodel tensor to one or more Kimi HF tensors.
Parameters:
Fully qualified native tensor name.
Native tensor. Grouped routed expert tensors use [experts, hidden, 2 * inter] for gate/up and [experts, inter, hidden] for down.
Adapter options forwarded by checkpoint save/load.
Returns: list[tuple[str, Any]]
HF key/tensor pairs. Split expert tensors use Kimi w1/w2/w3 names.
Convert Kimi HF checkpoint keys to Automodel native keys.
Parameters:
HF state dict whose routed expert tensors use split Kimi names.
Optional EP/FSDP mesh used to load only local expert shards.
Adapter options forwarded by checkpoint load.
Returns: dict[str, Any]
Native state dict with grouped routed expert tensors.
Convert Automodel native tensors to Kimi HF checkpoint keys.
Rewrite a checkpoint MoE key onto the decoder block’s mlp submodule.
Inverse of :func:_hf_moe_key_to_native.
Decode K3 [out, in / 2] MXFP4 bytes into [out, in] weights.