sgl-project/sglang · error · ValueError
Guidance scale must be positive, but got {batch.guidance_sca
Error message
Guidance scale must be positive, but got {batch.guidance_scale} What it means
When CFG is active, guidance_scale must be non-negative (the check rejects values < 0). A negative guidance scale would push samples away from the prompt in an unsupported way, so validation fails before any denoising step runs.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/input_validation.py:346
if (
batch.do_classifier_free_guidance
and batch.negative_prompt is None
and batch.negative_prompt_embeds is None
):
raise ValueError(
"For classifier-free guidance, either `negative_prompt` or "
"`negative_prompt_embeds` must be provided"
)
# Validate number of inference steps
if batch.num_inference_steps <= 0:
raise ValueError(
f"Number of inference steps must be positive, but got {batch.num_inference_steps}"
)
# Validate guidance scale if using classifier-free guidance
if batch.do_classifier_free_guidance and batch.guidance_scale < 0:
raise ValueError(
f"Guidance scale must be positive, but got {batch.guidance_scale}"
)
# Reject requests that do not enable CFG on a server launched with
# --enable-cfg-parallel. CFG-parallel splits cond/uncond across ranks,
# so rank 1 has no work and returns None for noise_pred, which crashes
# scheduler.step() ~30 minutes later under a gloo broadcast timeout.
# Earlier, field-specific checks above (negative_prompt missing,
# guidance_scale < 0) fire first and produce better messages for those
# cases; this is the catch-all for any combination that still leaves
# do_classifier_free_guidance=False under cfg-parallel.
if server_args.enable_cfg_parallel and not batch.do_classifier_free_guidance:
neg_prompt_state = (
"not set"
if batch.negative_prompt is None
else "empty" if batch.negative_prompt == "" else "set"
)
raise ValueError(View on GitHub (pinned to 0132848349)
Solutions
- Use a non-negative guidance_scale (0 to ~15; 7.5 is a common default)
- If you intended to disable CFG, set guidance_scale=0 or turn off do_classifier_free_guidance rather than negating it
- Sanity-check parsed config values before submitting
Example fix
// before out = pipe(prompt="a cat", guidance_scale=-7.5) // after out = pipe(prompt="a cat", guidance_scale=7.5)
Defensive patterns
Strategy: validation
Validate before calling
if batch.do_classifier_free_guidance:
batch.guidance_scale = abs(float(batch.guidance_scale))
assert batch.guidance_scale >= 0 Type guard
def valid_guidance_scale(scale, cfg: bool) -> bool:
return not cfg or scale >= 0 Prevention
- Validate guidance_scale range (0-15) client-side
- Avoid sign manipulations of guidance values; use CFG toggles instead
When it happens
Trigger: Passing a negative guidance_scale (e.g. -7.5) together with do_classifier_free_guidance=True, or a request builder that negates/mis-parses the scale field.
Common situations: Typos/sign errors in client configs; JSON configs where guidance_scale is read as a negative number; experiments with 'negative guidance' not supported by this pipeline; note the check allows 0 (which effectively disables CFG weighting) but not below.
Related errors
- For classifier-free guidance, either `negative_prompt` or `n
- Number of inference steps must be positive, but got {batch.n
- unsupported input for causal Conv3D cat/pad CUDA
- unsupported input for usp_merge_heads CUDA
- unsupported input for modulate_scale_shift CUDA
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/3c1f85b48b0b9782.
Report an issue: GitHub.