sgl-project/sglang · error · ValueError

Unsupported native SD cross-attention arguments: {sorted(uns

Error message

Unsupported native SD cross-attention arguments: {sorted(unsupported)}

What it means

Raised by the SD2 transformer block forward when cross_attention_kwargs contains keys other than 'scale'. The native implementation only honors the attention scale argument and rejects diffusers-style extras like ip_adapter_image or cross_attention_kwargs carried over from a diffusers pipeline call.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py:256

        self.norm2 = nn.LayerNorm(dim, eps=1e-5)
        self.attn2 = StableDiffusionAttention(
            dim, num_heads, head_dim, cross_attention_dim
        )
        self.norm3 = nn.LayerNorm(dim, eps=1e-5)
        self.ff = FeedForward(dim)

    def forward(
        self,
        hidden_states: torch.Tensor,
        encoder_hidden_states: torch.Tensor,
        attention_mask: torch.Tensor | None = None,
        encoder_attention_mask: torch.Tensor | None = None,
        cross_attention_kwargs: dict[str, Any] | None = None,
    ) -> torch.Tensor:
        if cross_attention_kwargs is not None and cross_attention_kwargs:
            unsupported = set(cross_attention_kwargs) - {"scale"}
            if unsupported:
                raise ValueError(
                    "Unsupported native SD2 cross-attention arguments: "
                    f"{sorted(unsupported)}"
                )
        hidden_states = hidden_states + self.attn1(
            self.norm1(hidden_states), attention_mask=attention_mask
        )
        hidden_states = hidden_states + self.attn2(
            self.norm2(hidden_states),
            encoder_hidden_states=encoder_hidden_states,
            attention_mask=encoder_attention_mask,
        )
        return hidden_states + self.ff(self.norm3(hidden_states))


class Transformer2DModel(nn.Module):
    def __init__(
        self,
        channels: int,

View on GitHub (pinned to 0132848349)

Solutions

  1. Strip all keys except 'scale' from cross_attention_kwargs before calling forward
  2. Drop cross_attention_kwargs entirely if you only need the default scale

Example fix

# before
cross_attention_kwargs = {"scale": 1.0, "ip_adapter_image_embeds": emb}
# after
cross_attention_kwargs = {"scale": 1.0}  # or None
Defensive patterns

Strategy: validation

Validate before calling

kwargs = {k: v for k, v in (cross_attention_kwargs or {}).items() if k == "scale"} or None

Type guard

def is_supported_cross_attn_kwargs(d: dict | None) -> bool:
    return d is None or set(d) <= {"scale"}

Prevention

When it happens

Trigger: Calling forward with cross_attention_kwargs={'scale': 1.0, 'ip_adapter_image_embeds': ...} — any key besides 'scale' triggers the error.

Common situations: Copying a diffusers pipeline invocation into the native runtime; IP-Adapter or T2I-Adjusment kwargs passed through unchanged.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/488c973dbeb6bf1a. Report an issue: GitHub.