{"record":{"id":"23a889640465e153","repo":"unslothai/unsloth","slug":"invalid-gpu-ids-requested-ids-gpu-ids-must-be-n","errorCode":null,"errorMessage":"Invalid gpu_ids {requested_ids}: GPU IDs must be non-negative. Rejected IDs: {negative_ids}.","messagePattern":"Invalid gpu_ids (.+?): GPU IDs must be non-negative\\. Rejected IDs: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/utils/hardware/hardware.py","lineNumber":2765,"sourceCode":"    physical_gpu_count = get_physical_gpu_count()\n\n    if gpu_ids is None:\n        return [] if is_vulkan else parent_visible_ids\n\n    requested_ids = list(gpu_ids)\n    if len(requested_ids) == 0:\n        return [] if is_vulkan else parent_visible_ids\n\n    if is_vulkan:\n        # A Vulkan build selects by ggml Vulkan ordinal (--device VulkanN), a separate\n        # index space from CUDA/ROCm ids that may be empty under CPU-only torch. The\n        # CUDA parent-visible / physical-count checks below do not apply; only reject\n        # malformed ordinals (issue #7239).\n        if len(set(requested_ids)) != len(requested_ids):\n            raise ValueError(f\"Invalid gpu_ids {requested_ids}: duplicate GPU IDs are not allowed.\")\n        negative_ids = [gpu_id for gpu_id in requested_ids if gpu_id < 0]\n        if negative_ids:\n            raise ValueError(\n                f\"Invalid gpu_ids {requested_ids}: GPU IDs must be non-negative. \"\n                f\"Rejected IDs: {negative_ids}.\"\n            )\n        return requested_ids\n\n    if not parent_visible_spec[\"supports_explicit_gpu_ids\"]:\n        env_var_name = (\n            \"ZE_AFFINITY_MASK\" if get_device() == DeviceType.XPU else \"CUDA_VISIBLE_DEVICES\"\n        )\n        raise ValueError(\n            f\"Invalid gpu_ids {requested_ids}: explicit physical GPU IDs are \"\n            f\"unsupported when {env_var_name} uses non-numeric or subdevice \"\n            f\"entries ({parent_visible_spec['raw']!r}). Omit gpu_ids to use \"\n            \"the parent-visible devices.\"\n        )\n\n    if len(set(requested_ids)) != len(requested_ids):\n        raise ValueError(","sourceCodeStart":2747,"sourceCodeEnd":2783,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/hardware/hardware.py#L2747-L2783","documentation":"Raised on the Vulkan validation path when any requested GPU ordinal is negative. The error lists every rejected negative id. Like the duplicate check, this is a pure well-formedness guard because Vulkan ordinals have no parent-visible set to validate against (issue #7239 regression guard).","triggerScenarios":"Calling resolve_requested_gpu_ids([-1]) or any list containing a negative id under the Vulkan backend, e.g. someone using CUDA-style '-1 means all' semantics.","commonSituations":"Porting CUDA conventions (-1 = all GPUs) to a Vulkan build; off-by-one index math producing -1; parsing a config where an unset value defaulted to -1.","solutions":["Remove negative ids; use [] or None for 'auto/all' selection instead of -1.","Fix the caller computing ids so it clamps to >= 0.","Check the config file for a -1 placeholder and replace it with an empty list."],"exampleFix":"# before\ngpu_ids = [-1]  # CUDA-style 'all' convention -> ValueError on Vulkan\n\n# after\ngpu_ids = []  # auto-select on Vulkan","handlingStrategy":"validation","validationCode":"def valid_vulkan_ids(ids):\n    return all(isinstance(i, int) and i >= 0 for i in ids) and len(set(ids)) == len(ids)","typeGuard":"def are_valid_vulkan_ordinals(ids) -> bool:\n    return (\n        isinstance(ids, (list, tuple))\n        and len(ids) > 0\n        and all(isinstance(i, int) and i >= 0 for i in ids)\n        and len(set(ids)) == len(ids)\n    )","tryCatchPattern":null,"preventionTips":["Never use -1 to mean 'all GPUs' on Vulkan — use auto-select (None/[]).","Clamp computed GPU indices to >= 0.","Treat unset config values as empty lists, not -1 sentinels."],"tags":["gpu","vulkan","hardware","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}