{"record":{"id":"ae7f3595c42233b5","repo":"sgl-project/sglang","slug":"number-of-inference-steps-must-be-positive-but-go","errorCode":null,"errorMessage":"Number of inference steps must be positive, but got {batch.num_inference_steps}","messagePattern":"Number of inference steps must be positive, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/input_validation.py","lineNumber":340,"sourceCode":"            and batch.prompt is None\n            and batch.prompt_embeds is None\n        ):\n            raise ValueError(\"Either `prompt` or `prompt_embeds` must be provided\")\n\n        # Ensure negative prompt is properly formatted if using classifier-free guidance\n        if (\n            batch.do_classifier_free_guidance\n            and batch.negative_prompt is None\n            and batch.negative_prompt_embeds is None\n        ):\n            raise ValueError(\n                \"For classifier-free guidance, either `negative_prompt` or \"\n                \"`negative_prompt_embeds` must be provided\"\n            )\n\n        # Validate number of inference steps\n        if batch.num_inference_steps <= 0:\n            raise ValueError(\n                f\"Number of inference steps must be positive, but got {batch.num_inference_steps}\"\n            )\n\n        # Validate guidance scale if using classifier-free guidance\n        if batch.do_classifier_free_guidance and batch.guidance_scale < 0:\n            raise ValueError(\n                f\"Guidance scale must be positive, but got {batch.guidance_scale}\"\n            )\n\n        # Reject requests that do not enable CFG on a server launched with\n        # --enable-cfg-parallel. CFG-parallel splits cond/uncond across ranks,\n        # so rank 1 has no work and returns None for noise_pred, which crashes\n        # scheduler.step() ~30 minutes later under a gloo broadcast timeout.\n        # Earlier, field-specific checks above (negative_prompt missing,\n        # guidance_scale < 0) fire first and produce better messages for those\n        # cases; this is the catch-all for any combination that still leaves\n        # do_classifier_free_guidance=False under cfg-parallel.\n        if server_args.enable_cfg_parallel and not batch.do_classifier_free_guidance:","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/input_validation.py#L322-L358","documentation":"num_inference_steps must be a positive integer (>= 1). The validation stage rejects requests with 0 or negative steps because the denoising loop would never execute or is meaningless.","triggerScenarios":"Passing num_inference_steps=0, a negative value, or a config/env default that resolves to 0 (e.g. unset strength/distillation settings collapsing steps to 0).","commonSituations":"Distilled-model configs where steps is computed from guidance/distillation parameters and underflows to 0; clients sending num_inference_steps from an unset optional field defaulting to 0; arithmetic like int(steps * strength) with tiny strength.","solutions":["Set num_inference_steps to at least 1 (typically 20-50 for standard, 4-8 for distilled models)","Check any computed step counts (e.g. steps*strength roundings) and clamp with max(1, ...)","Verify request serialization is not turning a missing field into 0"],"exampleFix":"// before\nout = pipe(prompt=\"a cat\", num_inference_steps=0)\n\n// after\nout = pipe(prompt=\"a cat\", num_inference_steps=max(1, num_inference_steps))","handlingStrategy":"validation","validationCode":"batch.num_inference_steps = max(1, int(batch.num_inference_steps))\nassert batch.num_inference_steps > 0","typeGuard":"def valid_step_count(n) -> bool:\n    return isinstance(n, int) and n >= 1","tryCatchPattern":null,"preventionTips":["Clamp computed step counts with max(1, ...)","Treat missing/0 values in configs as errors early"],"tags":["inference-steps","input-validation","range-check"],"backgroundTag":"out-of-range-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}