{"record":{"id":"ba214eb8b466e2f1","repo":"sgl-project/sglang","slug":"required-indexer-forward-batch-x-q-lora-posit","errorCode":null,"errorMessage":"Required: indexer, forward_batch, x, q_lora, positions","messagePattern":"Required: indexer, forward_batch, x, q_lora, positions","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/sparsity/algorithms/deepseek_dsa.py","lineNumber":39,"sourceCode":"    def retrieve_topk(\n        self,\n        queries: torch.Tensor,\n        layer_id: int,\n        req_pool_indices: torch.Tensor,\n        sparse_mask: torch.Tensor,\n        attn_metadata: Optional[Any],\n        **kwargs,\n    ) -> tuple:\n        indexer, forward_batch, x, q_lora, positions = (\n            kwargs.get(\"indexer\"),\n            kwargs.get(\"forward_batch\"),\n            kwargs.get(\"x\"),\n            kwargs.get(\"q_lora\"),\n            kwargs.get(\"positions\"),\n        )\n\n        if any(v is None for v in [indexer, x, q_lora, positions, forward_batch]):\n            raise ValueError(\"Required: indexer, forward_batch, x, q_lora, positions\")\n\n        return (\n            indexer(\n                x=x,\n                q_lora=q_lora,\n                positions=positions,\n                forward_batch=forward_batch,\n                layer_id=layer_id,\n            ),\n            None,\n        )\n\n    def initialize_representation_pool(\n        self,\n        start_layer: int,\n        end_layer: int,\n        token_to_kv_pool,\n        req_to_token_pool,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/sparsity/algorithms/deepseek_dsa.py#L21-L57","documentation":"DeepSeek DSA sparse retrieval requires five kwargs: indexer, forward_batch, x, q_lora, and positions. Any None among them raises this ValueError, because the DeepSeek indexer call needs the hidden states (x), low-rank query projection (q_lora), and position ids to compute retrieval scores.","triggerScenarios":"Calling retrieve_topk on the DeepSeek DSA algorithm without supplying indexer (the DeepSeek indexer module), x (hidden states), q_lora (LoRA-projected queries), or positions.","commonSituations":"Wiring the DSA algorithm into a custom model forward where the indexer module or q_lora projection is not plumbed through; using the generic sparse-algorithm API without model-specific arguments for DeepSeek V3.2-style DSA.","solutions":["Supply all five kwargs from the model's forward: retrieve_topk(queries, indexer=self.indexer, x=hidden_states, q_lora=q_lora, positions=positions, forward_batch=forward_batch)","Ensure the model actually has the DSA indexer components (DeepSeek V3.2 DSA architecture); otherwise pick a different sparse algorithm","Check integration examples for the DeepSeek DSA path to copy the exact argument wiring"],"exampleFix":"# before\nout = dsa.retrieve_topk(queries, forward_batch=forward_batch)\n# after\nout = dsa.retrieve_topk(queries, forward_batch=forward_batch,\n                        indexer=self.indexer, x=hidden_states,\n                        q_lora=q_lora, positions=positions)","handlingStrategy":"validation","validationCode":"required = {k: kwargs.get(k) for k in (\"indexer\", \"forward_batch\", \"x\", \"q_lora\", \"positions\")}\nmissing = [k for k, v in required.items() if v is None]\nassert not missing, f\"missing DSA kwargs: {missing}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap DSA retrieval in a helper that always supplies the five kwargs"],"tags":["deepseek","dsa","sparse-attention","retrieval","value-error"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}