{"record":{"id":"2bcec2ae86c8389e","repo":"sgl-project/sglang","slug":"unsupported-input-for-wan-rmsnorm-silu","errorCode":null,"errorMessage":"unsupported input for wan_rmsnorm_silu","messagePattern":"unsupported input for wan_rmsnorm_silu","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/diffusion/norm/wan_rmsnorm_silu_triton.py","lineNumber":159,"sourceCode":"        and x.stride(1) == 1\n        and _affine_supported(x, gamma)\n        and (bias is None or _affine_supported(x, bias))\n    )\n\n\ndef wan_rmsnorm_silu(\n    x: torch.Tensor,\n    gamma: torch.Tensor,\n    bias: torch.Tensor | None = None,\n    rms_scale: float | None = None,\n    eps: float = 1e-12,\n) -> torch.Tensor:\n    \"\"\"Fused ``SiLU(F.normalize(x, dim=1) * rms_scale * gamma + bias)``.\n\n    Guard with :func:`can_use_wan_rmsnorm_silu`.\n    \"\"\"\n    if not can_use_wan_rmsnorm_silu(x, gamma, bias):\n        raise ValueError(\"unsupported input for wan_rmsnorm_silu\")\n\n    channels = x.shape[1]\n    gamma = gamma.reshape(channels).contiguous()\n    has_bias = bias is not None\n    bias = gamma if bias is None else bias.reshape(channels).contiguous()\n    if rms_scale is None:\n        rms_scale = channels**0.5\n    return _triton_wan_rmsnorm_silu_cuda(\n        x, gamma, bias, float(rms_scale), eps, has_bias\n    )\n\n\n__all__ = [\"can_use_wan_rmsnorm_silu\", \"wan_rmsnorm_silu\"]\n","sourceCodeStart":141,"sourceCodeEnd":173,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/diffusion/norm/wan_rmsnorm_silu_triton.py#L141-L173","documentation":"wan_rmsnorm_silu raises when its support predicate can_use_wan_rmsnorm_silu returns False. The Triton kernel requires: CUDA 5D non-empty x, dtype fp16/bf16/fp32, 0 < channels <= 1024, channels_last_3d contiguous with stride(1)==1, no grad tracking, and gamma/bias CUDA on the same device with matching dtype (or fp32) and numel == channels.","triggerScenarios":"Calling wan_rmsnorm_silu with a CPU tensor, non-channels-last 5D input, requires_grad enabled, channels > 1024, empty tensor, or gamma/bias of wrong dtype/size/device. The docstring explicitly says to guard with can_use_wan_rmsnorm_silu first.","commonSituations":"Running the Wan VAE decoder without channels_last_3d memory format; forgetting torch.no_grad() during inference wrappers; gamma kept on a different GPU in TP setups; channel counts above 1024 in a modified VAE.","solutions":["Call can_use_wan_rmsnorm_silu(x, gamma, bias) and fall back to eager WanRMS_norm+SiLU when False","Convert x to channels_last_3d (x = x.to(memory_format=torch.channels_last_3d)) and ensure stride(1)==1","Wrap inference in torch.no_grad()/torch.inference_mode()","Verify gamma/bias are CUDA, same device, dtype equal to x or fp32, and numel == x.shape[1]"],"exampleFix":"# before\ny = wan_rmsnorm_silu(x, gamma, bias)\n# after\nif can_use_wan_rmsnorm_silu(x, gamma, bias):\n    y = wan_rmsnorm_silu(x, gamma, bias)\nelse:\n    y = torch.nn.functional.silu(torch.nn.functional.normalize(x, dim=1) * scale * gamma.reshape(C) + (bias.reshape(C) if bias is not None else 0))","handlingStrategy":"type-guard","validationCode":"from sglang.kernels.ops.diffusion.norm.wan_rmsnorm_silu_triton import can_use_wan_rmsnorm_silu\nif can_use_wan_rmsnorm_silu(x, gamma, bias):\n    y = wan_rmsnorm_silu(x, gamma, bias, rms_scale, eps)\nelse:\n    y = eager_wan_rms_silu(x, gamma, bias, rms_scale, eps)","typeGuard":"can_use_wan_rmsnorm_silu(x, gamma, bias)  # the library's own predicate is the type guard","tryCatchPattern":"try:\n    y = wan_rmsnorm_silu(x, gamma, bias)\nexcept ValueError:\n    y = eager_wan_rms_silu(x, gamma, bias)  # WanRMS_norm + SiLU in eager torch","preventionTips":["Always guard with can_use_wan_rmsnorm_silu — the docstring mandates it","Convert VAE activations to channels_last_3d at entry","Run inference under torch.no_grad()","Keep channels <= 1024 and gamma/bias fp32-or-matching dtype with numel == C"],"tags":["memory-format","triton","vae","wan","validation"],"backgroundTag":"unsupported-kernel-input-predicate","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}