sgl-project/sglang · error · KeyError
f"seq_len {item} not supported for STA"
Error message
f"seq_len {item} not supported for STA" What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py:47
st_attn_backend_available = True
except Exception:
st_attn_backend_available = False
logger = init_logger(__name__)
class RangeDict(dict):
def __getitem__(self, item: int) -> str:
for key in self.keys():
if isinstance(key, tuple):
low, high = key
if low <= item <= high:
return str(super().__getitem__(key))
elif key == item:
return str(super().__getitem__(key))
raise KeyError(f"seq_len {item} not supported for STA")
class SlidingTileAttentionBackend(AttentionBackend):
accept_output_buffer: bool = True
@staticmethod
def get_supported_head_sizes() -> list[int]:
# TODO(will-refactor): check this
return [32, 64, 96, 128, 160, 192, 224, 256]
@staticmethod
def get_enum() -> AttentionBackendEnum:
return AttentionBackendEnum.SLIDING_TILE_ATTN
@staticmethod
def get_impl_cls() -> type["SlidingTileAttentionImpl"]:
return SlidingTileAttentionImpl
View on GitHub (pinned to 0132848349)
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
Example fix
# before
cfg = sta_config[seq_len] # KeyError: seq_len 8123 not supported for STA
# after
if not any((isinstance(k, tuple) and k[0] <= seq_len <= k[1]) or k == seq_len for k in sta_config):
seq_len = nearest_supported_length(seq_len)
cfg = sta_config[seq_len] Defensive patterns
Strategy: validation
Validate before calling
if not any((isinstance(k, tuple) and k[0] <= seq_len <= k[1]) or k == seq_len for k in sta_cfg):
raise SystemExit(f"unsupported STA seq_len {seq_len}; supported: {list(sta_cfg.keys())}") Type guard
def sta_len_supported(cfg, n: int) -> bool:
return any((isinstance(k, tuple) and k[0] <= n <= k[1]) or k == n for k in cfg.keys()) Try / catch
try:
tile_cfg = sta_cfg[seq_len]
except KeyError:
tile_cfg = sta_cfg[nearest_supported_length(seq_len)] Prevention
- Restrict resolutions/seq lens to those with shipped STA mask configs
- Validate seq_len against the mapping before forward
When it happens
Trigger: Indexing the STA config mapping with a seq_len outside every registered (low, high) range and equal to no exact key.
Common situations: 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.
Related errors
- st attn not supported
- SGLANG_DIFFUSION_ATTENTION_CONFIG is not set
- mask_strategy cannot be None for SlidingTileAttention
- mask_strategy[0] cannot be None for SlidingTileAttention
- forward_batch cannot be None
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5fe6b615ebe7b931.
Report an issue: GitHub.