{"record":{"id":"5a29df472df3d463","repo":"sgl-project/sglang","slug":"f-unknown-feature-map-feature-map","errorCode":null,"errorMessage":"f\"Unknown feature map: {feature_map}\"","messagePattern":"f\"Unknown feature map: (.+?)\"","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_linear_attn.py","lineNumber":151,"sourceCode":"\n        # Learnable linear projection for combining sparse + linear attention\n        self.proj_l = nn.Linear(head_size, head_size, dtype=torch.float32)\n\n        # Feature map for linear attention\n        # Type annotation for callables\n        self.feature_map_q: Callable[[torch.Tensor], torch.Tensor]\n        self.feature_map_k: Callable[[torch.Tensor], torch.Tensor]\n        if feature_map == \"elu\":\n            self.feature_map_q = lambda x: F.elu(x) + 1\n            self.feature_map_k = lambda x: F.elu(x) + 1\n        elif feature_map == \"relu\":\n            self.feature_map_q = F.relu\n            self.feature_map_k = F.relu\n        elif feature_map == \"softmax\":\n            self.feature_map_q = lambda x: F.softmax(x, dim=-1)\n            self.feature_map_k = lambda x: F.softmax(x, dim=-1)\n        else:\n            raise ValueError(f\"Unknown feature map: {feature_map}\")\n\n        self._init_weights()\n\n    def _init_weights(self) -> None:\n        \"\"\"Initialize projection weights to zero for residual-like behavior.\"\"\"\n        with torch.no_grad():\n            nn.init.zeros_(self.proj_l.weight)\n            nn.init.zeros_(self.proj_l.bias)  # type: ignore[arg-type]\n\n    def _calc_linear_attention_with_torch(self, q, k, v):\n        kv = torch.matmul(k.transpose(-1, -2), v)\n        k_sum = torch.sum(k, dim=-2, keepdim=True)\n        return torch.matmul(q, kv) / (1e-5 + torch.matmul(q, k_sum.transpose(-1, -2)))\n\n    def forward(\n        self,\n        query: torch.Tensor,\n        key: torch.Tensor,","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_linear_attn.py#L133-L169","documentation":"SparseLinearAttention's constructor accepts only a fixed set of feature map names ('relu' and 'softmax' among others). Any other string passed as feature_map reaches the else branch and raises ValueError naming the unsupported value.","triggerScenarios":"Constructing the sparse linear attention layer with feature_map set to anything other than the supported names, e.g. feature_map='gelu', feature_map='elu', feature_map='sigmoid', or a typo like 'Relu' / 'soft_max'.","commonSituations":"Porting a config from another codebase (e.g. a Transformer/linear-attention repo that uses 'gelu' feature maps), a casing mismatch, or copy-pasting a YAML/JSON config with an unsupported feature map name.","solutions":["Use one of the supported names: feature_map='relu' or feature_map='softmax' (check the full if/elif chain above the raise for other supported options such as identity/exp).","Fix casing/typos in the config string, e.g. 'Relu' -> 'relu'.","If you need a different feature map, subclass the layer and override feature_map_q/feature_map_k after construction, or extend the if/elif chain with a PR."],"exampleFix":"# before\nattn = SparseLinearAttention(..., feature_map=\"gelu\")\n\n# after\nattn = SparseLinearAttention(..., feature_map=\"relu\")\n# or set custom maps post-init:\n# attn.feature_map_q = torch.nn.functional.gelu\n# attn.feature_map_k = torch.nn.functional.gelu","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"relu\", \"softmax\"}  # mirror the if/elif chain in __init__\nassert feature_map in SUPPORTED, f\"feature_map must be one of {SUPPORTED}\"\nattn = SparseLinearAttention(..., feature_map=feature_map)","typeGuard":"def is_valid_feature_map(name: str) -> bool:\n    return name in {\"relu\", \"softmax\"}","tryCatchPattern":null,"preventionTips":["Keep feature-map names lowercase and sourced from the class's supported set.","Validate config strings at load time before constructing layers.","Document supported values next to your config schema."],"tags":["config","feature-map","validation","constructor"],"backgroundTag":"invalid-enum-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}