Skip to content

sharded_state cannot round-trip MLA models: attn_mha.kv_b_proj is aliased on first forward (Kimi-K3) #19

Description

@youssef62

Summary

servekit prepare followed by servekit launch -- ... --load-format sharded_state cannot serve an MLA
model. On Kimi-K3 at TP=4 / PP=8 / EP=4 across 8 nodes, prepare succeeds and writes a complete 1.5 TB
checkpoint (32 ranks, all gates pass), and the serve job then dies during model init on every pipeline
stage with:

KeyError: 'language_model.model.layers.67.self_attn.attn_mha.kv_b_proj.weight'
  ShardedStateLoader.load_model -> param_data = state_dict[key].data

Unlike #14 nothing is silently zeroed -- this is a hard failure, which is the good case. But it is the same
family: the checkpoint is written from a model whose module graph is not the one that reads it back.

This is an upstream SGLang interaction rather than a servekit bug per se -- prepare/launch only drive
SGLang's own ShardedStateLoader -- but it makes sharded_state presharding unusable for MLA models, and
servekit is where it surfaces.

Root cause

DeepSeek-V2-style MLA attention, which Kimi-K3 derives from, constructs attn_mha with an empty
kv_b_proj and fills it in lazily on the first forward:

# __init__
self.attn_mha = RadixAttention(...)
self.attn_mha.kv_b_proj = None

# first forward
if self.attn_mha.kv_b_proj is None:
    self.attn_mha.kv_b_proj = self.kv_b_proj

So whether attn_mha.kv_b_proj.weight appears in model.state_dict() depends on whether a forward has run:

side has forwarded? attn_mha.kv_b_proj key in state_dict
save (prepare serves until ready) yes aliased to self.kv_b_proj present -> written to the checkpoint
load (fresh model, pre-warmup) no None absent

ShardedStateLoader.load_model iterates the checkpoint's keys and indexes the fresh model's state dict,
so a key the checkpoint has and the model does not is an immediate KeyError.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions