sgl-project/sglang · error · ValueError

DFLASH requires explicit layer_ids for aux hidden capture.

Error message

DFLASH requires explicit layer_ids for aux hidden capture.

What it means

Laguna's set_dflash_layers_to_capture (laguna.py:867) enables DFLASH aux-hidden capture and, like Kimi's DSPARK equivalent, requires an explicit layer id list; None raises ValueError. Note SGLang captures 'before layer i', so callers must pass k+1 to get HF-style after-layer-k states.

Source

Thrown at python/sglang/srt/models/laguna.py:867

                f"num_experts={self.config.num_experts}, shards=3)."
            )

    def get_embed_and_head(self):
        return self.model.embed_tokens.weight, self.lm_head.weight

    def set_embed_and_head(self, embed, head):
        del self.model.embed_tokens.weight
        del self.lm_head.weight
        self.model.embed_tokens.weight = embed
        self.lm_head.weight = head
        torch.cuda.empty_cache()
        torch.cuda.synchronize()

    def set_dflash_layers_to_capture(self, layer_ids: List[int]):
        if not self.pp_group.is_last_rank:
            return
        if layer_ids is None:
            raise ValueError(
                "DFLASH requires explicit layer_ids for aux hidden capture."
            )

        self.capture_aux_hidden_states = True
        # SGLang captures "before layer i". To capture the hidden state after
        # target layer `k` (HF-style), capture before layer `k + 1`.
        self.model.layers_to_capture = [val + 1 for val in layer_ids]


EntryClass = LagunaForCausalLM

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass an explicit list of layers, offset by +1 for after-layer semantics
  2. Gate the call on the option being set
  3. Validate ids < num_hidden_layers before calling

Example fix

# before
model.set_dflash_layers_to_capture(args.layers)  # None if unset
# after
if args.layers:
    model.set_dflash_layers_to_capture([k + 1 for k in args.layers])
Defensive patterns

Strategy: validation

Validate before calling

assert layer_ids is not None, "DFLASH capture needs explicit layer ids"

Type guard

def valid_capture_layers(ids) -> bool:
    return isinstance(ids, (list, tuple)) and len(ids) > 0

Prevention

When it happens

Trigger: Calling set_dflash_layers_to_capture(None), typically via an unset optional CLI/config value forwarded directly.

Common situations: Generic training-hook frameworks assuming default capture layers; optional flags left empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/62c1556a59792aea. Report an issue: GitHub.