{"record":{"id":"506b3e4a1dc914f4","repo":"sgl-project/sglang","slug":"number-of-gpus-must-be-positive","errorCode":null,"errorMessage":"Number of gpus must be positive","messagePattern":"Number of gpus must be positive","errorType":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/cli/generate.py","lineNumber":234,"sourceCode":"        self.generation_arg_names = self._get_generation_arg_names()\n\n    def _get_init_arg_names(self) -> list[str]:\n        \"\"\"Get names of arguments for DiffGenerator initialization\"\"\"\n        return [\"num_gpus\", \"tp_size\", \"sp_size\", \"model_path\"]\n\n    def _get_generation_arg_names(self) -> list[str]:\n        \"\"\"Get names of arguments for generate_video method\"\"\"\n        return [field.name for field in dataclasses.fields(SamplingParams)]\n\n    def cmd(\n        self, args: argparse.Namespace, unknown_args: list[str] | None = None\n    ) -> None:\n        generate_cmd(args, unknown_args)\n\n    def validate(self, args: argparse.Namespace) -> None:\n        \"\"\"Validate the arguments for this command\"\"\"\n        if args.num_gpus is not None and args.num_gpus <= 0:\n            raise ValueError(\"Number of gpus must be positive\")\n\n        if args.config and not os.path.exists(args.config):\n            raise ValueError(f\"Config file not found: {args.config}\")\n\n    def subparser_init(\n        self, subparsers: argparse._SubParsersAction\n    ) -> FlexibleArgumentParser:\n        generate_parser = subparsers.add_parser(\n            \"generate\",\n            help=\"Run inference on a model\",\n            usage=\"sglang generate (--model-path MODEL_PATH_OR_ID --prompt PROMPT) | --config CONFIG_FILE [OPTIONS]\",\n        )\n\n        generate_parser = add_multimodal_gen_generate_args(generate_parser)\n\n        return cast(FlexibleArgumentParser, generate_parser)\n","sourceCodeStart":216,"sourceCodeEnd":251,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/cli/generate.py#L216-L251","documentation":"Raised by the validate() method of the `generate` CLI command when --num-gpus (args.num_gpus) is provided and is <= 0. The value must be a positive integer because it drives distributed launch of the generation workers.","triggerScenarios":"Running `sglang generate --num-gpus 0` or a negative value (possibly via a config/computed variable that evaluated to 0).","commonSituations":"Shell scripts computing GPU count from nvidia-smi or CUDA_VISIBLE_DEVICES when no GPUs are visible (count=0), typos, CI runners without GPUs.","solutions":["Check GPU availability: run nvidia-smi; if empty, fix CUDA_VISIBLE_DEVICES or run on a GPU host","Pass an explicit positive value, e.g. --num-gpus 1","If the count is computed in a script, add a guard that fails early with a clear message when the detected count is 0"],"exampleFix":"# before\nNUM_GPUS=$(nvidia-smi --list-gpus | wc -l)\nsglang generate --num-gpus $NUM_GPUS ...\n\n# after\nNUM_GPUS=$(nvidia-smi --list-gpus | wc -l)\n[ \"$NUM_GPUS\" -gt 0 ] || { echo 'no GPUs detected'; exit 1; }\nsglang generate --num-gpus $NUM_GPUS ...","handlingStrategy":"validation","validationCode":"if args.num_gpus is not None:\n    assert args.num_gpus > 0, \"--num-gpus must be positive\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Detect GPUs explicitly (nvidia-smi) and fail with a clear message when count is 0","Default --num-gpus to 1 in wrapper scripts","Validate computed values before passing them to the CLI"],"tags":["cli","gpu","argument-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}