sgl-project/sglang · error · ValueError
f"Invalid prefix for SparseVideoGen2AttentionImpl: {prefix}"
Error message
f"Invalid prefix for SparseVideoGen2AttentionImpl: {prefix}" What it means
SparseVideoGen2AttentionImpl derives its layer index from the prefix string by taking the third-from-last dot-separated component (parts[-3]) and parsing it as an int. If the prefix has fewer than 3 parts (e.g. 'layers.5' or 'blocks'), it raises this ValueError.
Source
Thrown at python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py:210
**extra_impl_args,
) -> None:
if causal:
raise ValueError(
"Sparse Video Gen 2 attention does not support causal attention"
)
if not svg2_available:
raise ImportError(
"Sparse Video Gen 2 attention backend requires svg package to be installed"
"Please install it by following the instructions at "
"https://github.com/svg-project/Sparse-VideoGen"
)
self.prefix = prefix
self.layer_idx = self._get_layer_idx(prefix)
def _get_layer_idx(self, prefix: str) -> int:
parts = prefix.split(".")
if len(parts) < 3:
raise ValueError(
f"Invalid prefix for SparseVideoGen2AttentionImpl: {prefix}"
)
return int(parts[-3])
def kmeans_init(
self,
query: torch.Tensor,
key: torch.Tensor,
attn_metadata: SparseVideoGen2AttentionMetadata,
):
cfg, num_heads, seq_len, dim = query.size()
qlabels, qcentroids, qcluster_sizes, qiter = batch_kmeans_Euclid(
query.reshape(cfg * num_heads, seq_len, dim),
n_clusters=attn_metadata.num_q_centroids,
max_iters=attn_metadata.kmeans_iter_init,
)
klabels, kcentroids, kcluster_sizes, kiter = batch_kmeans_Euclid(
key.reshape(cfg * num_heads, seq_len, dim),View on GitHub (pinned to 0132848349)
Solutions
- Pass the full hierarchical prefix containing at least 3 dot-separated components where parts[-3] is the numeric layer index, e.g. 'backbone.layers.12.attn'.
- If you renamed modules, keep a numeric layer component third from the end, or subclass and override _get_layer_idx for custom mapping.
- Regenerate prefixes from the model's named_modules() rather than hand-writing them.
Example fix
# before impl = SparseVideoGen2AttentionImpl(prefix="attn", ...) # too shallow -> ValueError # after impl = SparseVideoGen2AttentionImpl(prefix="model.layers.12.attn", ...) # parts[-3] == '12'
Defensive patterns
Strategy: validation
Validate before calling
def is_valid_svg2_prefix(prefix: str) -> bool:
parts = prefix.split(".")
return len(parts) >= 3 and parts[-3].isdigit()
assert is_valid_svg2_prefix(prefix), f"bad prefix: {prefix}" Type guard
def is_valid_svg2_prefix(prefix: str) -> bool:
parts = prefix.split(".")
return len(parts) >= 3 and parts[-3].isdigit() Prevention
- Generate prefixes from model.named_modules() rather than hand-writing strings.
- Keep a numeric layer-index component third-from-last in module paths (e.g. model.layers.12.attn).
- Add a startup sanity check over all prefixes when wiring custom backends.
When it happens
Trigger: Constructing the impl with a shallow prefix like 'blocks.3.q_proj', 'model.layers', or a custom name without the expected '...{layer_idx}.{module}.{child}' depth, so len(prefix.split('.')) < 3.
Common situations: Loading per-layer weights under renamed/remapped module paths (e.g. after checkpoint conversion or prefix stripping), or passing a user-defined prefix when manually instantiating the impl instead of letting the model builder generate hierarchical prefixes like 'transformer.blocks.12.attn'.
Related errors
- v_cache must be provided
- q can only be None when only_qv=True
- q must be provided unless qv is provided with only_qv=True
- `dt_bias` must have {HV * K} elements (got {dt_bias.numel()}
- The batch size is expected to be 1 rather than {q.shape[0]}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/24c90e3d6767f007.
Report an issue: GitHub.