{"record":{"id":"b03cefcda35a396b","repo":"sgl-project/sglang","slug":"pairs-length-must-be-greater-than-0","errorCode":null,"errorMessage":"pairs length must be greater than 0","messagePattern":"pairs length must be greater than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/schedulers/flow_match_pair.py","lineNumber":371,"sourceCode":"                kwargs.get(\"visual_denoising_strength\", 1.0)\n            )\n            audio_denoising_strength = float(\n                kwargs.get(\"audio_denoising_strength\", 1.0)\n            )\n            visual_mu = kwargs.get(\n                \"visual_exponential_shift_mu\", self.exponential_shift_mu\n            )\n            audio_mu = kwargs.get(\n                \"audio_exponential_shift_mu\", self.exponential_shift_mu\n            )\n\n            def _dual_sigma_shift(pairs: torch.Tensor, *, source: str):\n                if not isinstance(pairs, torch.Tensor):\n                    raise TypeError(\"pairs must be a torch.Tensor\")\n                if pairs.ndim != 2 or pairs.shape[1] != 2:\n                    raise ValueError(\"pairs must be a torch.Tensor of shape [N, 2]\")\n                if pairs.shape[0] == 0:\n                    raise ValueError(\"pairs length must be greater than 0\")\n                if source not in (\"timesteps\", \"sigmas\"):\n                    raise ValueError(\"source must be 'timesteps' or 'sigmas'\")\n\n                num_steps = pairs.shape[0]\n                device = pairs.device\n                dtype = pairs.dtype\n\n                def _build_column(\n                    shift_value: float, denoising_strength: float, mu_override\n                ):\n                    if shift_value <= 0:\n                        raise ValueError(\"shift must be positive\")\n                    if denoising_strength <= 0:\n                        raise ValueError(\"denoising_strength must be positive\")\n\n                    sigma_start = (\n                        self.sigma_min\n                        + (self.sigma_max - self.sigma_min) * denoising_strength","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/schedulers/flow_match_pair.py#L353-L389","documentation":"_dual_sigma_shift requires at least one pair row: pairs.shape[0] == 0 raises ValueError because num_steps = 0 would produce empty/degenerate linspace columns and divide-by-zero in the sigma transform. The check runs after the type/shape validations.","triggerScenarios":"set_pair_postprocess_by_name('dual_sigma_shift') then calling with an empty [0, 2] tensor — e.g. num_inference_steps=0 passed to set_timesteps, or an upstream filter/slice that removed all steps.","commonSituations":"num_inference_steps read from request config as 0 (missing field, bad default); slicing pairs with a boolean mask that selected nothing; edge case in batched serving where a request has zero scheduled steps.","solutions":["Guard num_inference_steps >= 1 before calling set_timesteps / the scheduler","Check pairs.shape[0] > 0 in your loop and skip/return early for empty requests","Fix the config default that yields 0 steps (e.g. missing YAML key defaulting to 0)","Log the offending shape at the request boundary to catch upstream slicing bugs"],"exampleFix":"# before\nsteps = int(req.get(\"num_steps\", 0))\nscheduler.set_timesteps(steps)\n\n# after\nsteps = int(req.get(\"num_steps\", 50))\nif steps < 1:\n    raise ValueError(\"num_steps must be >= 1\")\nscheduler.set_timesteps(steps)","handlingStrategy":"validation","validationCode":"if not isinstance(pairs, torch.Tensor) or pairs.shape[0] == 0:\n    raise ValueError(\"num_inference_steps must produce at least one pair\")\n# or: skip the request\nif pairs.shape[0] == 0:\n    return early_response(request)","typeGuard":null,"tryCatchPattern":"try:\n    scheduler.set_timesteps(n)\nexcept ValueError as e:\n    if 'length must be greater than 0' in str(e):\n        n = max(1, n)  # or reject the request\n    else:\n        raise","preventionTips":["Clamp num_inference_steps to >= 1 at request parsing","Validate step counts against masks/filters that could empty the schedule"],"tags":["pytorch","empty-tensor","scheduler","sigma-shift","validation"],"backgroundTag":"empty-input-array","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}