{"record":{"id":"c652ec1e811746a3","repo":"sgl-project/sglang","slug":"only-gate-value-of-1-is-supported-for-int-type-bu","errorCode":null,"errorMessage":"Only gate value of 1 is supported for int type, but got {gate}","messagePattern":"Only gate value of 1 is supported for int type, but got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/layernorm.py","lineNumber":622,"sourceCode":"        shift: torch.Tensor,\n        scale: torch.Tensor,\n    ) -> tuple[torch.Tensor, torch.Tensor]:\n        if residual.numel() == 0 or x.numel() == 0:\n            return self.forward_native(residual, x, gate, shift, scale)\n\n        if x.shape[-1] % 256 != 0 or x.shape[-1] > 8192:\n            import warnings\n\n            warnings.warn(\n                \"FusedScaleResidualNormScaleShift cuda not available, using native fallback\",\n                stacklevel=2,\n            )\n            return self.forward_native(residual, x, gate, shift, scale)\n\n        from sglang.kernels.ops.diffusion import fused_scale_residual_norm_scale_shift\n\n        if isinstance(gate, int) and gate != 1:\n            raise ValueError(\n                f\"Only gate value of 1 is supported for int type, but got {gate}\"\n            )\n\n        return fused_scale_residual_norm_scale_shift(\n            residual.contiguous(),\n            x.contiguous(),\n            gate.contiguous() if isinstance(gate, torch.Tensor) else None,\n            _ensure_contiguous(getattr(self.norm, \"weight\", None)),\n            _ensure_contiguous(getattr(self.norm, \"bias\", None)),\n            scale.contiguous(),\n            shift.contiguous(),\n            self.norm_type,\n            self.eps,\n        )\n\n    def forward_hip(\n        self,\n        residual: torch.Tensor,","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/layernorm.py#L604-L640","documentation":"forward_cuda of the diffusion residual norm accepts an int gate only as the neutral value 1 (no gating); any other int (e.g. 0) cannot be expressed by the fused kernel and is rejected before launch.","triggerScenarios":"Calling forward_cuda with gate as an int != 1; the native fallback path already ran for non-kernel cases, so this specific check guards the fused_scale_residual_norm_scale_shift launch.","commonSituations":"Code passing a learned gate as an int scalar; using 0 to 'disable' gating — instead pass gate=1 or a tensor; converting a tensor gate of value 1.0 to int 1 is fine, other values are not.","solutions":["Pass gate=1 for ungated forward","Pass the gate as a tensor (shape [batch, 1, inner_dim]) when it isn't exactly 1","Branch: use native path (`self.forward_native(...)`) when gate is an int != 1"],"exampleFix":"# before\nout = layer.forward_cuda(residual, x, gate=0, shift=s, scale=sc)\n# after\nout = layer.forward_cuda(residual, x, gate=1, shift=s, scale=sc)","handlingStrategy":"type-guard","validationCode":"if isinstance(gate, int) and gate != 1:\n    gate = 1  # or raise early with a clear message","typeGuard":"def is_valid_gate(g) -> bool:\\n    return isinstance(g, torch.Tensor) or (isinstance(g, int) and g == 1)","tryCatchPattern":null,"preventionTips":["Pass gates as tensors unless exactly int 1","Use gate=1 as the ungated convention"],"tags":["layernorm","gate","argument-validation","cuda-kernel"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}