{"record":{"id":"488c973dbeb6bf1a","repo":"sgl-project/sglang","slug":"unsupported-native-sd-cross-attention-arguments","errorCode":null,"errorMessage":"Unsupported native SD cross-attention arguments: {sorted(unsupported)}","messagePattern":"Unsupported native SD cross-attention arguments: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py","lineNumber":256,"sourceCode":"        self.norm2 = nn.LayerNorm(dim, eps=1e-5)\n        self.attn2 = StableDiffusionAttention(\n            dim, num_heads, head_dim, cross_attention_dim\n        )\n        self.norm3 = nn.LayerNorm(dim, eps=1e-5)\n        self.ff = FeedForward(dim)\n\n    def forward(\n        self,\n        hidden_states: torch.Tensor,\n        encoder_hidden_states: torch.Tensor,\n        attention_mask: torch.Tensor | None = None,\n        encoder_attention_mask: torch.Tensor | None = None,\n        cross_attention_kwargs: dict[str, Any] | None = None,\n    ) -> torch.Tensor:\n        if cross_attention_kwargs is not None and cross_attention_kwargs:\n            unsupported = set(cross_attention_kwargs) - {\"scale\"}\n            if unsupported:\n                raise ValueError(\n                    \"Unsupported native SD2 cross-attention arguments: \"\n                    f\"{sorted(unsupported)}\"\n                )\n        hidden_states = hidden_states + self.attn1(\n            self.norm1(hidden_states), attention_mask=attention_mask\n        )\n        hidden_states = hidden_states + self.attn2(\n            self.norm2(hidden_states),\n            encoder_hidden_states=encoder_hidden_states,\n            attention_mask=encoder_attention_mask,\n        )\n        return hidden_states + self.ff(self.norm3(hidden_states))\n\n\nclass Transformer2DModel(nn.Module):\n    def __init__(\n        self,\n        channels: int,","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py#L238-L274","documentation":"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.","triggerScenarios":"Calling forward with cross_attention_kwargs={'scale': 1.0, 'ip_adapter_image_embeds': ...} — any key besides 'scale' triggers the error.","commonSituations":"Copying a diffusers pipeline invocation into the native runtime; IP-Adapter or T2I-Adjusment kwargs passed through unchanged.","solutions":["Strip all keys except 'scale' from cross_attention_kwargs before calling forward","Drop cross_attention_kwargs entirely if you only need the default scale"],"exampleFix":"# before\ncross_attention_kwargs = {\"scale\": 1.0, \"ip_adapter_image_embeds\": emb}\n# after\ncross_attention_kwargs = {\"scale\": 1.0}  # or None","handlingStrategy":"validation","validationCode":"kwargs = {k: v for k, v in (cross_attention_kwargs or {}).items() if k == \"scale\"} or None","typeGuard":"def is_supported_cross_attn_kwargs(d: dict | None) -> bool:\n    return d is None or set(d) <= {\"scale\"}","tryCatchPattern":null,"preventionTips":["Whitelist instead of passing diffusers kwargs through verbatim"],"tags":["cross-attention","unsupported-argument","stable-diffusion"],"backgroundTag":"unsupported-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}