{"record":{"id":"2d4b368ec3d11536","repo":"sgl-project/sglang","slug":"invalid-sta-param","errorCode":null,"errorMessage":"Invalid STA_param","messagePattern":"Invalid STA_param","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py","lineNumber":220,"sourceCode":"        q: torch.Tensor,\n        k: torch.Tensor,\n        v: torch.Tensor,\n        attn_metadata: SlidingTileAttentionMetadata,\n    ) -> torch.Tensor:\n        if self.mask_strategy is None:\n            raise ValueError(\"mask_strategy cannot be None for SlidingTileAttention\")\n        if self.mask_strategy[0] is None:\n            raise ValueError(\"mask_strategy[0] cannot be None for SlidingTileAttention\")\n\n        timestep = attn_metadata.current_timestep\n        forward_context: ForwardContext = get_forward_context()\n        forward_batch = forward_context.forward_batch\n        if forward_batch is None:\n            raise ValueError(\"forward_batch cannot be None\")\n        # pattern:'.double_blocks.0.attn.impl' or '.single_blocks.0.attn.impl'\n        layer_idx = int(self.prefix.split(\".\")[-3])\n        if attn_metadata.STA_param is None or len(attn_metadata.STA_param) <= layer_idx:\n            raise ValueError(\"Invalid STA_param\")\n        STA_param = attn_metadata.STA_param[layer_idx]\n\n        text_length = q.shape[1] - self.img_seq_length\n        has_text = text_length > 0\n\n        query = q.transpose(1, 2).contiguous()\n        key = k.transpose(1, 2).contiguous()\n        value = v.transpose(1, 2).contiguous()\n\n        head_num = query.size(1)\n        sp_group = get_sp_group()\n        current_rank = sp_group.rank_in_group\n        start_head = current_rank * head_num\n\n        # searching or tuning mode\n        if len(STA_param) < head_num * sp_group.world_size:\n            sparse_attn_hidden_states_all = []\n            full_mask_window = STA_param[-1]","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py#L202-L238","documentation":"STA forward parses the layer index from self.prefix (e.g. '.double_blocks.0.attn.impl' -> int(parts[-3])) and indexes attn_metadata.STA_param with it. If STA_param is None or its length <= layer_idx, per-layer parameters are unavailable and forward raises 'Invalid STA_param'.","triggerScenarios":"Calling forward with attn_metadata.STA_param unset or shorter than layer_idx+1, or with a prefix whose parsed index exceeds the list length.","commonSituations":"Model variants with more double/single blocks than the STA_param list covers; a prefix not matching the '.blocks.{i}.attn.impl' pattern so parsing yields a wrong index; metadata reused from a different model.","solutions":["Build SlidingTileAttentionMetadata with STA_param sized to cover every STA layer index of your model","Verify self.prefix matches '.double_blocks.{i}.attn.impl' / '.single_blocks.{i}.attn.impl' so layer_idx parses correctly","Skip STA (dense fallback) for layers beyond the STA_param range if that is intended"],"exampleFix":"# before\nmeta = SlidingTileAttentionMetadata(..., STA_param=None)\nout = impl.forward(q, k, v, meta)  # Invalid STA_param\n# after\nmeta = SlidingTileAttentionMetadata(..., STA_param=sta_params_for_all_layers)  # len > max layer_idx\nout = impl.forward(q, k, v, meta)","handlingStrategy":"validation","validationCode":"layer_idx = int(self.prefix.split(\".\")[-3])\nassert attn_metadata.STA_param is not None and len(attn_metadata.STA_param) > layer_idx, \"STA_param too short for layer\"","typeGuard":"def sta_param_ready(meta, layer_idx: int) -> bool:\n    return meta.STA_param is not None and len(meta.STA_param) > layer_idx","tryCatchPattern":null,"preventionTips":["Build STA_param lists sized to the model's block count","Verify prefix format '.blocks.{i}.attn.impl' when constructing the impl"],"tags":["sliding-tile-attention","metadata","index-out-of-range","prefix-parsing"],"backgroundTag":"index-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}