{"record":{"id":"5fe6b615ebe7b931","repo":"sgl-project/sglang","slug":"f-seq-len-item-not-supported-for-sta","errorCode":null,"errorMessage":"f\"seq_len {item} not supported for STA\"","messagePattern":"f\"seq_len (.+?) not supported for STA\"","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py","lineNumber":47,"sourceCode":"\n    st_attn_backend_available = True\nexcept Exception:\n    st_attn_backend_available = False\n\nlogger = init_logger(__name__)\n\n\nclass RangeDict(dict):\n\n    def __getitem__(self, item: int) -> str:\n        for key in self.keys():\n            if isinstance(key, tuple):\n                low, high = key\n                if low <= item <= high:\n                    return str(super().__getitem__(key))\n            elif key == item:\n                return str(super().__getitem__(key))\n        raise KeyError(f\"seq_len {item} not supported for STA\")\n\n\nclass SlidingTileAttentionBackend(AttentionBackend):\n    accept_output_buffer: bool = True\n\n    @staticmethod\n    def get_supported_head_sizes() -> list[int]:\n        # TODO(will-refactor): check this\n        return [32, 64, 96, 128, 160, 192, 224, 256]\n\n    @staticmethod\n    def get_enum() -> AttentionBackendEnum:\n        return AttentionBackendEnum.SLIDING_TILE_ATTN\n\n    @staticmethod\n    def get_impl_cls() -> type[\"SlidingTileAttentionImpl\"]:\n        return SlidingTileAttentionImpl\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py#L29-L65","documentation":"A dict subclass mapping supported sequence lengths (exact keys or (low, high) range tuples) to STA tile configs raises KeyError from __getitem__ when the requested length matches no entry. Only lengths with a precomputed sliding-tile mask strategy are supported.","triggerScenarios":"Indexing the STA config mapping with a seq_len outside every registered (low, high) range and equal to no exact key.","commonSituations":"Generating video/images at a resolution whose token count isn't covered by the shipped mask configs; multi-resolution batches mixing supported and unsupported lengths.","solutions":["Use a sequence length/resolution listed in the mapping keys (print them to see supported ranges)","Pad/round the sequence length up to the nearest supported value","Fall back to a dense/other attention backend for unsupported lengths"],"exampleFix":"# before\ncfg = sta_config[seq_len]  # KeyError: seq_len 8123 not supported for STA\n# after\nif not any((isinstance(k, tuple) and k[0] <= seq_len <= k[1]) or k == seq_len for k in sta_config):\n    seq_len = nearest_supported_length(seq_len)\ncfg = sta_config[seq_len]","handlingStrategy":"validation","validationCode":"if not any((isinstance(k, tuple) and k[0] <= seq_len <= k[1]) or k == seq_len for k in sta_cfg):\n    raise SystemExit(f\"unsupported STA seq_len {seq_len}; supported: {list(sta_cfg.keys())}\")","typeGuard":"def sta_len_supported(cfg, n: int) -> bool:\n    return any((isinstance(k, tuple) and k[0] <= n <= k[1]) or k == n for k in cfg.keys())","tryCatchPattern":"try:\n    tile_cfg = sta_cfg[seq_len]\nexcept KeyError:\n    tile_cfg = sta_cfg[nearest_supported_length(seq_len)]","preventionTips":["Restrict resolutions/seq lens to those with shipped STA mask configs","Validate seq_len against the mapping before forward"],"tags":["sliding-tile-attention","seq-len","unsupported-value","key-error"],"backgroundTag":"unsupported-value-lookup","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}