{"record":{"id":"62c1556a59792aea","repo":"sgl-project/sglang","slug":"dflash-requires-explicit-layer-ids-for-aux-hidden-62c155","errorCode":null,"errorMessage":"DFLASH requires explicit layer_ids for aux hidden capture.","messagePattern":"DFLASH requires explicit layer_ids for aux hidden capture\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/laguna.py","lineNumber":867,"sourceCode":"                f\"num_experts={self.config.num_experts}, shards=3).\"\n            )\n\n    def get_embed_and_head(self):\n        return self.model.embed_tokens.weight, self.lm_head.weight\n\n    def set_embed_and_head(self, embed, head):\n        del self.model.embed_tokens.weight\n        del self.lm_head.weight\n        self.model.embed_tokens.weight = embed\n        self.lm_head.weight = head\n        torch.cuda.empty_cache()\n        torch.cuda.synchronize()\n\n    def set_dflash_layers_to_capture(self, layer_ids: List[int]):\n        if not self.pp_group.is_last_rank:\n            return\n        if layer_ids is None:\n            raise ValueError(\n                \"DFLASH requires explicit layer_ids for aux hidden capture.\"\n            )\n\n        self.capture_aux_hidden_states = True\n        # SGLang captures \"before layer i\". To capture the hidden state after\n        # target layer `k` (HF-style), capture before layer `k + 1`.\n        self.model.layers_to_capture = [val + 1 for val in layer_ids]\n\n\nEntryClass = LagunaForCausalLM\n","sourceCodeStart":849,"sourceCodeEnd":878,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/laguna.py#L849-L878","documentation":"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.","triggerScenarios":"Calling set_dflash_layers_to_capture(None), typically via an unset optional CLI/config value forwarded directly.","commonSituations":"Generic training-hook frameworks assuming default capture layers; optional flags left empty.","solutions":["Pass an explicit list of layers, offset by +1 for after-layer semantics","Gate the call on the option being set","Validate ids < num_hidden_layers before calling"],"exampleFix":"# before\nmodel.set_dflash_layers_to_capture(args.layers)  # None if unset\n# after\nif args.layers:\n    model.set_dflash_layers_to_capture([k + 1 for k in args.layers])","handlingStrategy":"validation","validationCode":"assert layer_ids is not None, \"DFLASH capture needs explicit layer ids\"","typeGuard":"def valid_capture_layers(ids) -> bool:\n    return isinstance(ids, (list, tuple)) and len(ids) > 0","tryCatchPattern":null,"preventionTips":["Remember the +1 offset (capture 'before layer i') when translating HF-style layer ids"],"tags":["laguna","dflash","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}