{"record":{"id":"7f8cb9d0224a0486","repo":"sgl-project/sglang","slug":"the-native-sd2-unet-currently-supports-only-the-hu","errorCode":null,"errorMessage":"The native SD2 UNet currently supports only the Hunyuan3D four-level SD2.1 block layout.","messagePattern":"The native SD2 UNet currently supports only the Hunyuan3D four-level SD2\\.1 block layout\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py","lineNumber":88,"sourceCode":"        )\n        parsed.validate()\n        return parsed\n\n    def validate(self) -> None:\n        expected_down = (\n            \"CrossAttnDownBlock2D\",\n            \"CrossAttnDownBlock2D\",\n            \"CrossAttnDownBlock2D\",\n            \"DownBlock2D\",\n        )\n        expected_up = (\n            \"UpBlock2D\",\n            \"CrossAttnUpBlock2D\",\n            \"CrossAttnUpBlock2D\",\n            \"CrossAttnUpBlock2D\",\n        )\n        if self.down_block_types != expected_down or self.up_block_types != expected_up:\n            raise ValueError(\n                \"The native SD2 UNet currently supports only the Hunyuan3D \"\n                \"four-level SD2.1 block layout.\"\n            )\n        if len(self.block_out_channels) != 4 or len(self.attention_head_dim) != 4:\n            raise ValueError(\"Hunyuan3D SD2.1 UNet requires four channel stages.\")\n        if self.layers_per_block != 2 or self.transformer_layers_per_block != 1:\n            raise ValueError(\n                \"Hunyuan3D SD2.1 UNet requires two ResNet layers and one \"\n                \"transformer layer per block.\"\n            )\n        if not self.use_linear_projection:\n            raise ValueError(\"Hunyuan3D SD2.1 checkpoints require linear projection.\")\n\n\n@dataclass\nclass StableDiffusionUNetOutput:\n    sample: torch.Tensor\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py#L70-L106","documentation":"The native SD2 UNet implementation only supports the exact Hunyuan3D-style SD2.1 architecture: a fixed four-level down/up block layout (DownBlock2D + 3 CrossAttnDownBlock2D; UpBlock2D + 3 CrossAttnUpBlock2D). Any other block layout fails config validation.","triggerScenarios":"Loading a UNet config (e.g. via from_dict) whose down_block_types/up_block_types deviate from the Hunyuan3D SD2.1 layout — different depth, mid-block-only variants, or vanilla SD configs with reordered blocks.","commonSituations":"Pointing the loader at a vanilla Stable Diffusion 2 config or a community fine-tune with modified block types; version drift where config JSON keys were renamed and defaults fell back to a mismatched layout.","solutions":["Use the Hunyuan3D SD2.1 UNet config: down_block_types=(DownBlock2D, CrossAttnDownBlock2D x3), up_block_types=(UpBlock2D, CrossAttnUpBlock2D x3)","For non-Hunyuan3D SD2 checkpoints, use diffusers' UNet2DConditionModel instead of this native path","Verify block_out_channels and attention_head_dim both have 4 entries and layers_per_block=2"],"exampleFix":"# before\ncfg.down_block_types = [\"CrossAttnDownBlock2D\"] * 4\n# after\ncfg.down_block_types = [\"DownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\"]\ncfg.up_block_types = [\"UpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\"]","handlingStrategy":"validation","validationCode":"EXPECTED_DOWN = (\"DownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\")\nEXPECTED_UP = (\"UpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\")\nassert tuple(cfg.down_block_types) == EXPECTED_DOWN and tuple(cfg.up_block_types) == EXPECTED_UP","typeGuard":"def is_hunyuan3d_sd2_layout(cfg) -> bool:\n    return (tuple(cfg.down_block_types) == (\"DownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\", \"CrossAttnDownBlock2D\")\n            and tuple(cfg.up_block_types) == (\"UpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\", \"CrossAttnUpBlock2D\"))","tryCatchPattern":null,"preventionTips":["Only feed Hunyuan3D SD2.1 checkpoints to the native path; use diffusers for other SD2 variants"],"tags":["stable-diffusion","unet","config-validation","hunyuan3d"],"backgroundTag":"model-config-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}