sgl-project/sglang · error · ValueError
Invalid attention metadata values.Sparsity should be in [0,
Error message
Invalid attention metadata values.Sparsity should be in [0, 1), skip_first_steps should be non-negative.Got sparsity={sparsity}, skip_first_steps={skip_first_steps} What it means
RainFusionAttentionMetadata.build validates that sparsity is in [0, 1) and skip_first_steps is non-negative before constructing metadata; bad values would produce an invalid sparse attention pattern, so it fails immediately.
Source
Thrown at python/sglang/multimodal_gen/runtime/layers/attention/backends/rain_fusion_attn.py:74
class RainFusionAttentionMetadataBuilder(AttentionMetadataBuilder):
def __init__(self) -> None:
pass
def prepare(self) -> None:
pass
def build(
self,
current_timestep: int,
skip_first_steps: int,
sparsity: float,
raw_latent_shape: list[int],
patch_size: tuple[int, int, int],
**kwargs: dict[str, Any],
) -> RainFusionAttentionMetadata:
if not (skip_first_steps >= 0 and 0.0 <= sparsity < 1.0):
raise ValueError(
(
"Invalid attention metadata values."
f"Sparsity should be in [0, 1), skip_first_steps should be non-negative."
f"Got sparsity={sparsity}, skip_first_steps={skip_first_steps}"
)
)
if sparsity == 0.0:
logger.warning(
(
"Sparsity is set to 0.0, which means no tokens will be dropped."
"For better performance use Laser Attention or increase sparsity."
)
)
latent_shape = raw_latent_shape[-3:]
latent_shape = [latent_shape[i] // patch_size[i] for i in range(3)]
View on GitHub (pinned to 0132848349)
Solutions
- Correct the values: 0.0 <= sparsity < 1.0 and skip_first_steps >= 0
- Convert density to sparsity with sparsity = 1 - density if the config uses density
- Validate both values at config-parse time before build() is called
Example fix
# before meta = RainFusionAttentionMetadata.build(sparsity=1.2, skip_first_steps=0, ...) # after meta = RainFusionAttentionMetadata.build(sparsity=0.2, skip_first_steps=0, ...)
Defensive patterns
Strategy: validation
Validate before calling
assert 0.0 <= sparsity < 1.0 and skip_first_steps >= 0, "invalid RainFusion sparsity args"
Prevention
- Validate sparse-attn config ranges where YAML is parsed
- Convert density to sparsity explicitly
When it happens
Trigger: Calling RainFusionAttentionMetadata.build with sparsity >= 1.0, negative sparsity, or negative skip_first_steps.
Common situations: RainFusion (video/diffusion sparse attention) configs specifying density where sparsity is expected; negative skip_first_steps meant as 'no skip'; hand-tuned YAML with typos.
Related errors
- Invalid attention metadata values.Sparsity should be in [0,
- Missing required argument for SparseVideoGen2Attention: {nam
- n_q/n_k must be one of {VALID_N}, got n_q={n_q}, n_k={n_k}
- v_cache must be provided
- q can only be None when only_qv=True
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/d4350d45d8b56bf4.
Report an issue: GitHub.