{"record":{"id":"f84aabc194090d55","repo":"sgl-project/sglang","slug":"kernel-dispatch-requires-at-least-one-tensor-argum","errorCode":null,"errorMessage":"kernel dispatch requires at least one tensor argument","messagePattern":"kernel dispatch requires at least one tensor argument","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/dsv4_attn_metadata_kernels.py","lineNumber":19,"sourceCode":"from __future__ import annotations\n\nfrom typing import Optional\n\nimport msgspec\nimport torch\nimport triton\nimport triton.language as tl\n\n\ndef _inputs_on_cuda(*args, **kwargs) -> bool:\n    \"\"\"Route kernel dispatch by input placement: the first tensor argument\n    decides. CUDA inputs take the fused triton kernel; CPU inputs take the\n    torch reference implementation (triton is CUDA-only, and CPU-side callers\n    such as unit tests exercise the reference path).\"\"\"\n    for value in (*args, *kwargs.values()):\n        if isinstance(value, torch.Tensor):\n            return value.is_cuda\n    raise AssertionError(\"kernel dispatch requires at least one tensor argument\")\n\n\nclass ExpandPrefillCausallyResult(msgspec.Struct):\n    seq_lens_casual: torch.Tensor\n    req_pool_indices_repeated: torch.Tensor\n\n\nclass ExpandPrefillCausally:\n    @classmethod\n    def execute(cls, *args, **kwargs) -> ExpandPrefillCausallyResult:\n        if _inputs_on_cuda(*args, **kwargs):\n            return cls.triton(*args, **kwargs)\n        return cls.torch(*args, **kwargs)\n\n    @classmethod\n    def torch(\n        cls,\n        *,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/dsv4_attn_metadata_kernels.py#L1-L37","documentation":"_inputs_on_cuda scans (*args, **kwargs) for torch.Tensor arguments to decide whether to launch the fused Triton kernel or the CPU reference implementation. If no argument is a tensor at all, dispatch is impossible and it raises AssertionError — this is a programming error in the caller, not a runtime condition.","triggerScenarios":"Invoking the wrapped kernel-op (via execute) with only scalars/None and zero tensor arguments, e.g. a degenerate test call or a refactor that dropped the tensor arguments.","commonSituations":"Unit tests calling the op with placeholder args; a refactor that moved tensors into a struct the wrapper does not unpack; passing tensors inside a dataclass/list instead of as direct args.","solutions":["Pass at least one torch.Tensor argument so device dispatch can work","If arguments are nested (dataclass, list), unpack them before calling the op","Fix the call site — this assert indicates an API misuse bug, not something to catch"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert any(isinstance(a, torch.Tensor) for a in (*args, *kwargs.values())), \\\n    \"op requires at least one tensor argument\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unpack structured args (dataclasses/lists) before calling kernel ops","This assert signals a call-site bug: fix it rather than catching it"],"tags":["kernel-dispatch","api-misuse","assertion","triton"],"backgroundTag":"invalid-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}