{"record":{"id":"f8bd2ccf5db0bac7","repo":"sgl-project/sglang","slug":"norm-type-must-be-one-of-layer-and-rms","errorCode":null,"errorMessage":"norm_type must be one of \"layer\" and \"rms\"","messagePattern":"norm_type must be one of \"layer\" and \"rms\"","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/diffusion/norm/scale_residual_norm_cutedsl.py","lineNumber":314,"sourceCode":"        weight = 1 if weight is None else weight\n        bias = 0 if bias is None else bias\n        ResOut, Residual, Gate = 0, 0, 1\n        torch_tensors = [y, ResOut, Residual, x, Gate, weight, bias, scale, shift]\n        # Compile cache\n        hash_key = ScaleResidualNormScaleShift.make_hash_key(norm_type, *torch_tensors)\n        compiled_fn = _COMPILE_CACHE.get(hash_key)\n        if compiled_fn is None:\n            kernel = ScaleResidualNormScaleShift(D, norm_type)\n            fake_sig_args = [to_fake_cute_args(t) for t in torch_tensors]\n            compiled_fn = cute.compile(\n                kernel, *fake_sig_args, options=\"--enable-tvm-ffi\"\n            )\n            _COMPILE_CACHE[hash_key] = compiled_fn\n        # Execute\n        compiled_fn(*torch_tensors, eps, stream)\n        return y\n    else:\n        raise ValueError('norm_type must be one of \"layer\" and \"rms\"')\n\n\n@fused_norm_scale_shift.register_fake\ndef _fused_norm_scale_shift_fake(x, weight, bias, scale, shift, norm_type, eps=1e-5):\n    y = x.new_empty(x.shape)\n    return y\n\n\n@torch.library.custom_op(\n    \"sglang::fused_scale_residual_norm_scale_shift\", mutates_args=()\n)\ndef fused_scale_residual_norm_scale_shift(\n    residual: torch.Tensor,\n    x: torch.Tensor,\n    gate: Optional[torch.Tensor],  # Union[Optional[torch.Tensor], int] indeed\n    weight: Optional[torch.Tensor],\n    bias: Optional[torch.Tensor],\n    scale: torch.Tensor,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/diffusion/norm/scale_residual_norm_cutedsl.py#L296-L332","documentation":"fused_norm_scale_shift dispatches on a norm_type string and only 'layer' (LayerNorm) and 'rms' (RMSNorm) have kernel implementations. Any other string reaches the else branch and raises.","triggerScenarios":"Calling fused_norm_scale_shift(x, ..., norm_type) with norm_type not exactly 'layer' or 'rms' — e.g. 'layernorm', 'RMS', 'group', or a typo.","commonSituations":"Config-driven norm names ('LayerNorm' capitalized) passed through without normalization; new norm variants wired to this entry point.","solutions":["Pass exactly 'layer' or 'rms'","Normalize/alias config strings before the call (e.g. map 'layernorm'->'layer')","Add a new branch + kernel only if you actually extended the kernel file"],"exampleFix":"# before\nfused_norm_scale_shift(x, w, b, s, sh, cfg.norm_type)  # 'LayerNorm'\n# after\nnt = cfg.norm_type.lower().replace('norm', '')  # -> 'layer' / 'rms'\nfused_norm_scale_shift(x, w, b, s, sh, nt)","handlingStrategy":"type-guard","validationCode":"assert norm_type in (\"layer\", \"rms\"), f\"bad norm_type {norm_type!r}\"","typeGuard":"def is_valid_norm_type(nt: str) -> bool:\n    return nt in (\"layer\", \"rms\")","tryCatchPattern":null,"preventionTips":["Centralize norm-type string normalization at config load","Avoid free-form config strings reaching kernel dispatch"],"tags":["enum","norm","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}