{"record":{"id":"490c3a63bcf1b819","repo":"sgl-project/sglang","slug":"sana-wm-cfg-requires-negative-prompt-embeds","errorCode":null,"errorMessage":"SANA-WM CFG requires negative prompt embeds.","messagePattern":"SANA-WM CFG requires negative prompt embeds\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py","lineNumber":876,"sourceCode":"            _first_tensor(batch.prompt_attention_mask), device=device\n        )\n        if pos_embeds is None:\n            raise ValueError(\"SANA-WM denoising requires positive prompt embeds.\")\n\n        do_cfg = bool(batch.do_classifier_free_guidance)\n        neg_embeds = None\n        neg_mask = None\n        if do_cfg:\n            neg_embeds = _to_device_dtype(\n                _first_tensor(server_args.pipeline_config.get_neg_prompt_embeds(batch)),\n                device=device,\n                dtype=target_dtype,\n            )\n            neg_mask = _to_device_dtype(\n                _first_tensor(batch.negative_attention_mask), device=device\n            )\n            if neg_embeds is None:\n                raise ValueError(\"SANA-WM CFG requires negative prompt embeds.\")\n\n            pos_embeds, neg_embeds, pos_mask, neg_mask = (\n                _align_sana_wm_cfg_text_conditions(\n                    pos_embeds, neg_embeds, pos_mask, neg_mask\n                )\n            )\n\n        extra = batch.extra or {}\n        diffusers_kwargs = extra.get(\"diffusers_kwargs\", {})\n        if not isinstance(diffusers_kwargs, dict):\n            diffusers_kwargs = {}\n        chunk_kwargs = {}\n        for key in (\"chunk_index\", \"chunk_size\", \"chunk_split_strategy\"):\n            value = extra.get(key, diffusers_kwargs.get(key))\n            if value is not None:\n                chunk_kwargs[key] = value\n        camera_conditions = _to_device_dtype(\n            extra.get(\"camera_conditions\"), device=device, dtype=target_dtype","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py#L858-L894","documentation":"Raised by the SANA-WM denoising forward when classifier-free guidance is enabled (batch.do_classifier_free_guidance) but negative prompt embeds are None. CFG needs both positive and negative text conditions.","triggerScenarios":"Enabling CFG on a request that has no negative prompt, or where the negative prompt embeds were not computed/attached by the text stage.","commonSituations":"do_classifier_free_guidance defaults true while negative_prompt is empty; negative-prompt encoding branch skipped; field name mismatch for negative embeds.","solutions":["Provide a negative prompt (even a plain '' encoded through the text encoder) so embeds exist","Or disable CFG: set do_classifier_free_guidance=False on the request","Ensure the text stage encodes both positive and negative prompts when CFG is on"],"exampleFix":"# before\nrequest.do_classifier_free_guidance = True  # no negative prompt set\n# after\nrequest.negative_prompt = request.negative_prompt or ''\nrequest.do_classifier_free_guidance = bool(request.negative_prompt)","handlingStrategy":"validation","validationCode":"if batch.do_classifier_free_guidance:\n    assert _first_tensor(batch.negative_prompt_embeds) is not None","typeGuard":"def cfg_ready(batch) -> bool:\n    return not batch.do_classifier_free_guidance or getattr(batch, 'negative_prompt_embeds', None) is not None","tryCatchPattern":null,"preventionTips":["Auto-disable CFG when no negative prompt is supplied","Always encode an empty-string negative prompt when CFG is on"],"tags":["cfg","negative-prompt","sana-wm"],"backgroundTag":"missing-prerequisite-state","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}