{"record":{"id":"214fdd98201c400c","repo":"sgl-project/sglang","slug":"num-inference-steps-must-be-positive-got-steps","errorCode":null,"errorMessage":"num_inference_steps must be positive, got {steps}","messagePattern":"num_inference_steps must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py","lineNumber":262,"sourceCode":"    # two logical encoders sharing the same underlying `text_encoder` module.\n    text_encoder_configs: tuple[EncoderConfig, ...] = field(\n        default_factory=lambda: (Gemma3Config(),)\n    )\n    text_encoder_precisions: tuple[str, ...] = field(default_factory=lambda: (\"bf16\",))\n    text_encoder_extra_args: list[dict] = field(default_factory=lambda: [{}])\n\n    preprocess_text_funcs: tuple[Callable[[str], str] | None, ...] = field(\n        default_factory=lambda: (None,)\n    )\n    postprocess_text_funcs: tuple[\n        Callable[[BaseEncoderOutput, dict], torch.Tensor], ...\n    ] = field(default_factory=lambda: (_gemma_postprocess_func,))\n\n    def prepare_sigmas(self, sigmas, num_inference_steps):\n        if sigmas is None:\n            steps = int(num_inference_steps)\n            if steps <= 0:\n                raise ValueError(f\"num_inference_steps must be positive, got {steps}\")\n            return [1.0 - i / steps for i in range(steps)]\n        return sigmas\n\n    def tokenize_prompt(self, prompt: list[str], tokenizer, tok_kwargs) -> dict:\n        # Adapted from diffusers_pipeline.py _get_gemma_prompt_embeds\n        # But we only need tokenization here, the embedding happens in TextEncodingStage\n        # Official LTX Gemma tokenizer trims surrounding whitespace before\n        # tokenization.\n        prompt = [text.strip() for text in prompt]\n\n        # Gemma expects left padding for chat-style prompts\n        tokenizer.padding_side = \"left\"\n        if tokenizer.pad_token is None:\n            tokenizer.pad_token = tokenizer.eos_token\n\n        max_sequence_length = tok_kwargs.get(\n            \"max_length\", 1024\n        )  # Default from diffusers pipeline","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py#L244-L280","documentation":"LTX-2's prepare_sigmas builds the sigma schedule [1 - i/steps] when no explicit sigmas are passed; a non-positive num_inference_steps (0 or negative) would produce an empty/invalid schedule, so it is rejected up front.","triggerScenarios":"Calling generation with sigmas=None and num_inference_steps <= 0 — e.g. 0, -1, or a value that int() truncates to 0 (like 0.5).","commonSituations":"num_inference_steps read from a config/CLI where the default was never set (0), computed as steps = strength * total and rounding to 0 at low strength, or a typo/negative value in request parameters.","solutions":["Set num_inference_steps to a positive integer (typically 20-50 for LTX-2)","If computing steps from strength, clamp: max(1, int(strength * total_steps))","Pass an explicit sigmas list if you want to bypass step-count schedule generation","Validate request params before submission"],"exampleFix":"# before\nsteps = int(strength * num_inference_steps)  # 0 when strength small\nout = pipe(prompt, num_inference_steps=steps)\n\n# after\nsteps = max(1, int(strength * num_inference_steps))\nout = pipe(prompt, num_inference_steps=steps)","handlingStrategy":"validation","validationCode":"num_inference_steps = max(1, int(num_inference_steps))\nassert num_inference_steps > 0","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if \"num_inference_steps must be positive\" in str(e):\n        pipe(prompt, num_inference_steps=30)  # sane default retry","preventionTips":["Clamp strength-derived step counts with max(1, ...)","Validate request schema client-side","Default num_inference_steps in config, never 0"],"tags":["sglang","ltx-2","num-inference-steps","sigma-schedule","diffusion","invalid-argument"],"backgroundTag":"invalid-parameter-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}