{"record":{"id":"b318b4f842689251","repo":"sgl-project/sglang","slug":"dspark-requires-explicit-layer-ids-for-aux-hidden-b318b4","errorCode":null,"errorMessage":"DSPARK requires explicit layer_ids for aux hidden capture.","messagePattern":"DSPARK requires explicit layer_ids for aux hidden capture\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/kimi_k3.py","lineNumber":2892,"sourceCode":"            )\n        else:\n            self.lm_head = PPMissingLayer()\n        logit_scale = getattr(config, \"logit_scale\", 1.0)\n        self.logits_processor = LogitsProcessor(config=config, logit_scale=logit_scale)\n        self.capture_aux_hidden_states = False\n\n    def get_input_embeddings(self):\n        return self.model.embed_tokens\n\n    def set_dspark_layers_to_capture(self, layer_ids: list[int]) -> None:\n        if self.pp_group.world_size > 1:\n            # Capture layers living on non-last PP ranks would be silently\n            # skipped (the flag is only set on the last rank).\n            raise NotImplementedError(\"DSPARK aux hidden capture requires PP=1.\")\n        if not self.pp_group.is_last_rank:\n            return\n        if layer_ids is None:\n            raise ValueError(\n                \"DSPARK requires explicit layer_ids for aux hidden capture.\"\n            )\n        self.capture_aux_hidden_states = True\n        self.model.dspark_layers_to_capture = list(layer_ids)\n\n    @torch.no_grad()\n    def forward(\n        self,\n        input_ids: torch.Tensor,\n        positions: torch.Tensor,\n        forward_batch: ForwardBatch,\n        input_embeds: Optional[torch.Tensor] = None,\n        inputs_embeds: Optional[torch.Tensor] = None,\n        pp_proxy_tensors: Optional[PPProxyTensors] = None,\n    ) -> torch.Tensor:\n        embeds = input_embeds if input_embeds is not None else inputs_embeds\n        hidden_states = self.model(\n            input_ids, positions, forward_batch, embeds, pp_proxy_tensors","sourceCodeStart":2874,"sourceCodeEnd":2910,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/kimi_k3.py#L2874-L2910","documentation":"DSPARK's aux hidden capture needs to know exactly which decoder layers' hidden states to capture; unlike some speculative paths it cannot infer them. If layer_ids is None (the caller omitted the argument) after the PP and last-rank checks, this ValueError is raised and capture_aux_hidden_states is never set.","triggerScenarios":"Calling set_dspark_layers_to_capture(None) or omitting layer_ids from the DSPARK/spec worker when wiring up Kimi K3 — the method explicitly rejects None even though the signature types it as list[int].","commonSituations":"A DSPARK integration/spec-worker version that doesn't pass layer_ids; user scripts calling the capture API directly without layer selection; default-argument path after an sglang upgrade changed the call convention.","solutions":["Pass an explicit list of layer ids, e.g. set_dspark_layers_to_capture([0, 1, 2]) matching the DSPARK draft's tdt/esvd layer choices.","Upgrade the DSPARK runtime/spec worker to a version that supplies layer_ids for Kimi K3.","Validate layer_ids against model.config.num_hidden_layers before calling."],"exampleFix":"# before\nmodel.set_dspark_layers_to_capture(None)\n\n# after\nmodel.set_dspark_layers_to_capture([0, 1, 2])","handlingStrategy":"validation","validationCode":"assert layer_ids is not None and len(layer_ids) > 0, \"DSPARK requires explicit layer_ids\"\nassert all(0 <= i < model.config.num_hidden_layers for i in layer_ids)","typeGuard":"def valid_layer_ids(layer_ids, num_layers) -> bool:\n    return layer_ids is not None and all(isinstance(i, int) and 0 <= i < num_layers for i in layer_ids)","tryCatchPattern":null,"preventionTips":["Always pass explicit capture layers when configuring DSPARK.","Cross-check layer ids against config.num_hidden_layers."],"tags":["dspark","speculative-decoding","argument-validation","kimi"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}