{"record":{"id":"7a12596b5122fbb2","repo":"sgl-project/sglang","slug":"validate-failed-unsupported-tensor-shape-t-shap","errorCode":null,"errorMessage":"Validate failed: unsupported tensor shape: {t.shape}.","messagePattern":"Validate failed: unsupported tensor shape: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/diffusion/norm/scale_residual_norm_cutedsl.py","lineNumber":196,"sourceCode":"        tNrN = norm(tNrN, tWrW, tBrB)\n        # Compute: value = value * (1 + <scale>) + <shift>\n        value = tNrN.load()\n        copy_if(tSCgSC, tSCrSC)  # gmem -> rmem\n        copy_if(tSHgSH, tSHrSH)  # gmem -> rmem\n        if cutlass.const_expr(isinstance(tSCrSC, cute.Tensor)):\n            value = value * (1 + tSCrSC.load())\n        if cutlass.const_expr(isinstance(tSHrSH, cute.Tensor)):\n            value = value + tSHrSH.load()\n        # Store: y\n        tYrY.store(value.to(tYrY.element_type))\n        copy_if(tYrY, tYgY)  # rmem -> gmem\n\n\ndef validate_x(t: torch.Tensor, B: int, S: int, D: int):\n    if t.dtype not in (torch.float16, torch.bfloat16, torch.float32):\n        raise ValueError(f\"Validate failed: unsupported dtype: {t.dtype}\")\n    if t.shape != (B, S, D):\n        raise ValueError(f\"Validate failed: unsupported tensor shape: {t.shape}.\")\n    if t.stride()[-1] != 1:\n        raise ValueError(\"Validate failed: not contiguous on dim D.\")\n\n\ndef validate_weight_bias(t: Optional[torch.Tensor], D: int):\n    if t is None:\n        return\n    if t.dtype not in (torch.float16, torch.bfloat16, torch.float32):\n        raise ValueError(f\"Validate failed: unsupported dtype: {t.dtype}\")\n    if t.shape != (D,):\n        raise ValueError(f\"Validate failed: unsupported tensor shape: {t.shape}.\")\n    if t.stride()[-1] != 1:\n        raise ValueError(\"Validate failed: not contiguous on dim D.\")\n\n\ndef validate_scale_shift(t: torch.Tensor, B: int, S: int, D: int):\n    if t.dtype not in (torch.float16, torch.bfloat16, torch.float32):\n        raise ValueError(f\"Validate failed: unsupported dtype: {t.dtype}\")","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/diffusion/norm/scale_residual_norm_cutedsl.py#L178-L214","documentation":"validate_x requires activations shaped exactly (B, S, D): a 3D batch/sequence/hidden tensor. The CuTe DSL kernel tiles the D dimension and iterates B*S rows, so other ranks or mismatched dims are rejected up front.","triggerScenarios":"Passing a 2D (S, D) tensor, a 4D tensor, or a 3D tensor whose dims don't match the B/S/D the caller declared to fused_norm_scale_shift / fused_scale_residual_norm_scale_shift.","commonSituations":"Feeding unbatched 2D activations, forgetting to unsqueeze a batch dim, or a mismatch between declared BSD and actual tensor shape after slicing/padding.","solutions":["Reshape/unsqueeze the activation to exactly (B, S, D) before the call","Make sure the B, S, D you pass to validators/ops come from x.shape itself, not separate bookkeeping"],"exampleFix":"# before\ny = fused_norm_scale_shift(x_2d, ...)  # x_2d: (S, D)\n# after\ny = fused_norm_scale_shift(x_2d.unsqueeze(0), ...)  # (1, S, D)","handlingStrategy":"validation","validationCode":"assert x.ndim == 3 and tuple(x.shape) == (B, S, D), f\"expected (B,S,D), got {tuple(x.shape)}\"","typeGuard":"def is_bsd(t: torch.Tensor, B: int, S: int, D: int) -> bool:\n    return t.ndim == 3 and tuple(t.shape) == (B, S, D)","tryCatchPattern":null,"preventionTips":["Derive B,S,D from x.shape rather than passing separate values","Unsqueeze batch dim for single-sample inputs"],"tags":["shape","validation","cuda-kernel","diffusion"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}