{"record":{"id":"065dc0246fbc1af2","repo":"sgl-project/sglang","slug":"scale-shift-table-must-be-cuda-bf16-fp32-last-di","errorCode":null,"errorMessage":"scale_shift_table must be CUDA, bf16/fp32, last-dim contiguous","messagePattern":"scale_shift_table must be CUDA, bf16/fp32, last-dim contiguous","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/diffusion/modulate/ltx2_ada_values_triton.py","lineNumber":155,"sourceCode":"\ndef ltx2_ada_values9(\n    scale_shift_table: torch.Tensor,\n    timestep: torch.Tensor,\n) -> tuple[torch.Tensor, ...]:\n    if timestep.ndim != 3:\n        raise ValueError(\"timestep must have shape [B, S, 9 * D]\")\n    if not timestep.is_cuda or timestep.dtype != torch.bfloat16:\n        raise ValueError(\"timestep must be a CUDA bfloat16 tensor\")\n    if not timestep.is_contiguous():\n        raise ValueError(\"timestep must be contiguous\")\n    if scale_shift_table.ndim != 2 or scale_shift_table.shape[0] != 9:\n        raise ValueError(\"scale_shift_table must have shape [9, D]\")\n    if (\n        not scale_shift_table.is_cuda\n        or scale_shift_table.dtype not in (torch.bfloat16, torch.float32)\n        or scale_shift_table.stride(-1) != 1\n    ):\n        raise ValueError(\n            \"scale_shift_table must be CUDA, bf16/fp32, last-dim contiguous\"\n        )\n\n    total_params = int(scale_shift_table.shape[0])\n    hidden = int(scale_shift_table.shape[1])\n    if hidden <= 0 or timestep.shape[-1] != total_params * hidden:\n        raise ValueError(\"timestep last dim must equal 9 * hidden\")\n    if hidden % 256 != 0 or hidden > 8192:\n        raise ValueError(\"hidden size is outside the supported LTX2 fast-path range\")\n\n    batch, seq, _ = timestep.shape\n    rows = int(batch * seq)\n    # Each returned output is a disjoint, contiguous view, so one allocation\n    # avoids nine allocator round trips per transformer block.\n    output_storage = torch.empty(\n        (9, batch, seq, hidden), device=timestep.device, dtype=timestep.dtype\n    )\n    outs = tuple(output_storage.unbind(dim=0))","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/diffusion/modulate/ltx2_ada_values_triton.py#L137-L173","documentation":"Beyond shape, scale_shift_table must be a CUDA tensor in bfloat16 or float32 with unit stride on the last dim. CPU tensors, other dtypes, or last-dim non-contiguous tables trigger this error.","triggerScenarios":"Table on CPU (common right after checkpoint load without .to('cuda')), an fp16 table, or a table produced by a transpose making the last dim strided.","commonSituations":"Forgetting to move model parameters to GPU after loading; keeping the table in fp16 while timestep is bf16; transposed layouts from external checkpoints.","solutions":["table = table.to(device='cuda') and cast to bf16 or fp32 (match timestep precision convention)","If transposed, apply table.t().contiguous() to get [9, D] with stride-1 rows","Add a startup assert on table.is_cuda and dtype"],"exampleFix":"# before\nvals = ltx2_ada_values9(table_cpu_fp16, t)\n# after\ntable = table_cpu_fp16.to('cuda').to(torch.bfloat16)\nvals = ltx2_ada_values9(table, t)","handlingStrategy":"validation","validationCode":"assert scale_shift_table.is_cuda and scale_shift_table.dtype in (torch.bfloat16, torch.float32) and scale_shift_table.stride(-1) == 1\nscale_shift_table = scale_shift_table.to('cuda', torch.bfloat16).contiguous()","typeGuard":"def table_props_ok(t: torch.Tensor) -> bool:\n    return t.is_cuda and t.dtype in (torch.bfloat16, torch.float32) and t.stride(-1) == 1","tryCatchPattern":null,"preventionTips":["Move all params to CUDA right after checkpoint load","Transpose checkpoint tables to [9, D] with contiguous rows"],"tags":["device","dtype","contiguity","ltx2"],"backgroundTag":"tensor-input-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}