{"record":{"id":"48917e4b0e6bd180","repo":"sgl-project/sglang","slug":"name-must-be-contiguous","errorCode":null,"errorMessage":"{name} must be contiguous","messagePattern":"(.+?) must be contiguous","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/sparse_mla_q8kv8_prefill_sm90.py","lineNumber":120,"sourceCode":"\n\n# Module-level cache for kernel-write-only output tensors. The active s_q rows\n# are overwritten every call; buffers grow monotonically by device/head shape.\ndef _check_out_buffer(\n    t: torch.Tensor,\n    name: str,\n    shape: tuple,\n    dtype: torch.dtype,\n    device: torch.device,\n) -> None:\n    if tuple(t.shape) != tuple(shape):\n        raise ValueError(f\"{name} must have shape {tuple(shape)}, got {tuple(t.shape)}\")\n    if t.dtype != dtype:\n        raise ValueError(f\"{name} must have dtype {dtype}, got {t.dtype}\")\n    if t.device != device:\n        raise ValueError(f\"{name} must be on device {device}, got {t.device}\")\n    if not t.is_contiguous():\n        raise ValueError(f\"{name} must be contiguous\")\n\n\n# Internal custom-op wrappers so the JIT kernel calls participate in\n# torch.library / torch.compile tracing and kernel-API debug logging.\n# The dispatch_full variant carries the optional attn_sink / topk_length\n# tensors as required args; the public API chooses which op to call.\n@register_custom_op(\n    op_name=\"sparse_mla_q8kv8_prefill\",\n    mutates_args=[\"out\", \"max_logits\", \"lse\"],\n)\ndef _sparse_mla_q8kv8_prefill_op(\n    q: torch.Tensor,\n    kv: torch.Tensor,\n    indices: torch.Tensor,\n    q_scale: torch.Tensor,\n    kv_scale: torch.Tensor,\n    out: torch.Tensor,\n    max_logits: torch.Tensor,","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/sparse_mla_q8kv8_prefill_sm90.py#L102-L138","documentation":"The SM90 kernel indexes output buffers with raw contiguous pointers, so _check_out_buffer rejects non-contiguous tensors (e.g. transposed views or strided slices) with ValueError '{name} must be contiguous'.","triggerScenarios":"Passing an out buffer that is a transpose/slice/expand of another tensor, or a torch.empty with non-default strides.","commonSituations":"Reusing a slice of a larger workspace buffer as an output; passing .t() views; buffers created via as_strided or narrow.","solutions":["Pass freshly allocated contiguous buffers or call .contiguous() on the buffer before the call","If slicing a workspace, copy into a contiguous buffer instead"],"exampleFix":"# before\nout = workspace[:s_q]  # non-contiguous view\n# after\nout = torch.empty(s_q, h_q, d_v, dtype=torch.bfloat16, device=q.device)\nsparse_mla_q8kv8_prefill_fwd(..., out=out, ...)","handlingStrategy":"validation","validationCode":"if not out.is_contiguous():\n    out = out.contiguous()  # or reallocate","typeGuard":"def is_contiguous_cuda(t: torch.Tensor) -> bool:\n    return t.is_cuda and t.is_contiguous()","tryCatchPattern":null,"preventionTips":["Never pass views/slices as out buffers","Add .contiguous() in adapter layers around kernel calls"],"tags":["contiguity","output-buffer","sparse-mla","strides"],"backgroundTag":"non-contiguous-tensor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}