{"record":{"id":"4f9db9328d139ad7","repo":"sgl-project/sglang","slug":"class-labels-are-required-by-this-unet","errorCode":null,"errorMessage":"class_labels are required by this UNet.","messagePattern":"class_labels are required by this UNet\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py","lineNumber":847,"sourceCode":"            raise ValueError(\"T2I adapter residuals are not supported by Hunyuan3D.\")\n        if (down_block_additional_residuals is None) != (\n            mid_block_additional_residual is None\n        ):\n            raise ValueError(\n                \"ControlNet down and mid residuals must be provided together.\"\n            )\n\n        attention_mask = self._attention_bias(attention_mask, sample.dtype)\n        encoder_attention_mask = self._attention_bias(\n            encoder_attention_mask, sample.dtype\n        )\n        if self.config.center_input_sample:\n            sample = 2 * sample - 1.0\n\n        time_embedding = self._time_embedding(sample, timestep)\n        if self.class_embedding is not None:\n            if class_labels is None:\n                raise ValueError(\"class_labels are required by this UNet.\")\n            time_embedding = time_embedding + self.class_embedding(class_labels).to(\n                sample.dtype\n            )\n\n        forward_upsample_size = any(\n            dimension % 8 != 0 for dimension in sample.shape[-2:]\n        )\n        sample = self.conv_in(sample)\n        down_residuals = (sample,)\n        for block in self.down_blocks:\n            if isinstance(block, CrossAttnDownBlock2D):\n                sample, residuals = block(\n                    sample,\n                    time_embedding,\n                    encoder_hidden_states,\n                    attention_mask,\n                    encoder_attention_mask,\n                    cross_attention_kwargs,","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/stable_diffusion.py#L829-L865","documentation":"Raised by the Hunyuan3D SD2.1 UNet forward when the config created a class_embedding but the caller passed class_labels=None. Classifier-free guidance setups on class-conditional checkpoints still need dummy labels when the embedding exists.","triggerScenarios":"Instantiating the UNet with num_class_embeds > 0 (creating class_embedding) then calling forward without class_labels.","commonSituations":"Loading a class-conditional SD2 checkpoint and running plain CFG sampling with no class labels provided.","solutions":["Pass class_labels of shape [B] (or [B, embedding_dim]) to forward","If class conditioning is unwanted, load the config with num_class_embeds unset/0 so class_embedding is None","Use zero/dummy labels matching batch size for unconditional pass"],"exampleFix":"# before\nout = unet(x, t, encoder_hidden_states=ctx)\n# after\nlabels = torch.zeros(x.shape[0], dtype=torch.long, device=x.device)\nout = unet(x, t, encoder_hidden_states=ctx, class_labels=labels)","handlingStrategy":"validation","validationCode":"if unet.class_embedding is not None and class_labels is None:\n    class_labels = torch.zeros(sample.shape[0], dtype=torch.long, device=sample.device)","typeGuard":"def needs_class_labels(unet) -> bool:\n    return unet.class_embedding is not None","tryCatchPattern":null,"preventionTips":["Check unet.class_embedding is not None before every forward"],"tags":["unet","class-conditional","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}