{"record":{"id":"6a7435cd3dd376db","repo":"sgl-project/sglang","slug":"unknown-approximate-mode-approximate","errorCode":null,"errorMessage":"Unknown approximate mode: {approximate}","messagePattern":"Unknown approximate mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/activation.py","lineNumber":89,"sourceCode":"        return out\n\n\n@CustomOp.register(\"gelu_and_mul\")\nclass GeluAndMul(CustomOp):\n    \"\"\"An activation function for GeGLU.\n\n    The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.\n\n    Shapes:\n        x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)\n        return: (batch_size, seq_len, d) or (num_tokens, d)\n    \"\"\"\n\n    def __init__(self, approximate: str = \"none\"):\n        super().__init__()\n        self.approximate = approximate\n        if approximate not in (\"none\", \"tanh\"):\n            raise ValueError(f\"Unknown approximate mode: {approximate}\")\n\n    def forward_cuda(self, *args, **kwargs) -> Any:\n        return self.forward_native(*args, **kwargs)\n\n    def forward_npu(self, x: torch.Tensor) -> torch.Tensor:\n        y_npu, _ = torch_npu.npu_geglu(\n            x,\n            dim=-1,\n            approximate=1 if self.approximate == \"tanh\" else 0,\n            activate_left=True,\n        )\n        return y_npu\n\n    def forward_native(self, x: torch.Tensor) -> torch.Tensor:\n        \"\"\"PyTorch-native implementation equivalent to forward().\"\"\"\n        d = x.shape[-1] // 2\n        return F.gelu(x[..., :d], approximate=self.approximate) * x[..., d:]\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/activation.py#L71-L107","documentation":"The GELU-style activation layer in sglang's multimodal runtime accepts PyTorch's 'approximate' argument, which only supports 'none' (exact GELU) and 'tanh' (tanh approximation). __init__ validates this eagerly and raises for any other string, mirroring torch.nn.functional.gelu's constraint.","triggerScenarios":"Constructing the activation layer with approximate='silu', 'newer', or any non-{'none','tanh'} value, typically because a model config's hidden_act_gelu or activation string was forwarded verbatim into the approximate parameter.","commonSituations":"Model configs that carry activation strings like 'gelu_new'/'gelu_pytorch_tanh' being passed unnormalized; porting configs from other frameworks that use different approximation names; version changes where a new approximate mode exists upstream but not here.","solutions":["Pass approximate='none' or 'tanh' only.","Map config names before construction: 'gelu_new'/'gelu_fast' → 'tanh'; plain 'gelu' → 'none'.","If you truly need another mode, use torch.nn.GELU directly or extend the tuple at activation.py:89."],"exampleFix":"# before\nlayer = GeluLayer(approximate=model_cfg.hidden_act)  # hidden_act='gelu_new'\n# after\napprox = 'tanh' if model_cfg.hidden_act in ('gelu_new','gelu_pytorch_tanh') else 'none'\nlayer = GeluLayer(approximate=approx)","handlingStrategy":"validation","validationCode":"def norm_approx(name: str) -> str:\n    return 'tanh' if name in ('gelu_new','gelu_pytorch_tanh','tanh') else 'none'\napprox = norm_approx(cfg.hidden_act)","typeGuard":"def is_supported_approximate(v: str) -> bool:\n    return v in ('none', 'tanh')","tryCatchPattern":null,"preventionTips":["Never forward raw config activation strings into approximate=; map aliases first.","Unit-test activation construction against every activation name your model zoo uses."],"tags":["activation","gelu","argument-validation","torch"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}