{"record":{"id":"81cf3fa6a4d5287b","repo":"sgl-project/sglang","slug":"gate-type-type-gate-not-supported","errorCode":null,"errorMessage":"Gate type {type(gate)} not supported","messagePattern":"Gate type (.+?) not supported","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/layernorm.py","lineNumber":708,"sourceCode":"    ) -> tuple[torch.Tensor, torch.Tensor]:\n        # x.shape: [batch_size, seq_len, inner_dim]\n        if isinstance(gate, int):\n            # used by cross-attention, should be 1\n            assert gate == 1\n            residual_output = residual + x\n        elif isinstance(gate, torch.Tensor):\n            if gate.dim() == 4:\n                # gate.shape: [batch_size, num_frames, 1, inner_dim]\n                num_frames = gate.shape[1]\n                frame_seqlen = x.shape[1] // num_frames\n                residual_output = residual + (\n                    x.unflatten(dim=1, sizes=(num_frames, frame_seqlen)) * gate\n                ).flatten(1, 2)\n            else:\n                # gate.shape: [batch_size, 1, inner_dim]\n                residual_output = residual + x * gate\n        else:\n            raise ValueError(f\"Gate type {type(gate)} not supported\")\n        normalized = self.norm(residual_output)\n        modulated = fuse_scale_shift_kernel(normalized, scale, shift)\n        return modulated, residual_output\n\n    def forward_npu(\n        self,\n        residual: torch.Tensor,\n        x: torch.Tensor,\n        gate: torch.Tensor | int,\n        shift: torch.Tensor,\n        scale: torch.Tensor,\n    ) -> tuple[torch.Tensor, torch.Tensor]:\n        # x.shape: [batch_size, seq_len, inner_dim]\n        if isinstance(gate, int):\n            # used by cross-attention, should be 1\n            assert gate == 1\n            residual_output = residual + x\n        elif isinstance(gate, torch.Tensor):","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/layernorm.py#L690-L726","documentation":"forward_native of the residual-scale-shift norm handles gate as tensor or int(==1); any other type (str, float, None, list) reaches the else branch and raises 'Gate type ... not supported'.","triggerScenarios":"Calling forward_native (directly or via forward_cuda/cpu/hip fallback) with a gate that is neither a torch.Tensor nor int — e.g. a float 1.0 or None.","commonSituations":"Gate loaded from config as float; a code path where gate is optional and None is passed instead of 1; numpy scalar instead of int/tensor.","solutions":["Coerce: `gate = torch.as_tensor(gate)` or `int(gate)` (must be 1) before calling","Default gate to 1 when gating is disabled","Check the caller chain for None/float gate leaks"],"exampleFix":"# before\nmodulated, res = layer.forward_native(residual, x, gate=1.0, shift=s, scale=sc)\n# after\nmodulated, res = layer.forward_native(residual, x, gate=1, shift=s, scale=sc)","handlingStrategy":"type-guard","validationCode":"if not isinstance(gate, (torch.Tensor, int)):\n    gate = torch.as_tensor(gate, dtype=x.dtype) if gate is not None else 1","typeGuard":"def is_valid_gate(g) -> bool:\\n    return isinstance(g, torch.Tensor) or (isinstance(g, int) and g == 1)","tryCatchPattern":"try:\\n    out = layer.forward_native(residual, x, gate, shift, scale)\\nexcept ValueError as e:\\n    if 'Gate type' in str(e):\\n        out = layer.forward_native(residual, x, torch.as_tensor(gate), shift, scale)","preventionTips":["Normalize gate to Tensor/int at the call boundary","Avoid None/float gate defaults leaking from config"],"tags":["layernorm","gate","type-error","argument-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}