{"record":{"id":"49a70ba82429be3d","repo":"unslothai/unsloth","slug":"gpu-selection-is-unavailable-on-this-host-exc","errorCode":null,"errorMessage":"GPU selection is unavailable on this host: {exc}","messagePattern":"GPU selection is unavailable on this host: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/diffusion_device.py","lineNumber":188,"sourceCode":"\n    Raises ValueError for a selection this host cannot honour, so the load is refused with a\n    reason rather than quietly running somewhere the user did not choose.\n\n    ``allow_ranking = False`` drops only the free-VRAM probe, for a caller that must not open a\n    CUDA context (the plan routes while a trainer holds the cards). Validation and translation\n    still run -- they read the mask and nvidia-smi -- so the single card the UI sends resolves and\n    only a multi-card pick comes back None.\n    \"\"\"\n    wanted = sorted({int(gpu_id) for gpu_id in gpu_ids or ()})\n    if not wanted:\n        return None\n    try:\n        from utils.hardware.hardware import (\n            get_parent_visible_gpu_ids,\n            resolve_requested_gpu_ids,\n        )\n    except Exception as exc:  # noqa: BLE001 -- without the hardware layer the mask is unknowable\n        raise ValueError(f\"GPU selection is unavailable on this host: {exc}\") from exc\n    allowed = resolve_requested_gpu_ids(wanted)\n    visible = get_parent_visible_gpu_ids()\n    # Torch enumerates the parent-visible list in order, so its ordinal for a physical id is that\n    # id's position in the mask. Unmasked, the layer reports range(physical count) and this is\n    # the identity mapping.\n    ordinals = [visible.index(gpu_id) for gpu_id in allowed if gpu_id in visible]\n    if not ordinals:\n        raise ValueError(\n            f\"Requested GPU {wanted} but none of them are visible to this process \"\n            f\"(visible: {visible}). Clear the GPU selection to use the default device.\"\n        )\n    if len(ordinals) == 1:\n        return ordinals[0]\n    if not allow_ranking:\n        return None\n\n    def _free_vram(ordinal: int) -> int:\n        try:","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_device.py#L170-L206","documentation":"Translating requested physical GPU ids into torch ordinals requires utils.hardware.hardware (get_parent_visible_gpu_ids / resolve_requested_gpu_ids), and importing it raised. Without the hardware layer the CUDA_VISIBLE_DEVICES mask is unknowable, so the load is refused with a reason instead of guessing a device.","triggerScenarios":"Calling the GPU-selection resolve with non-empty gpu_ids on a host where importing utils.hardware.hardware raises — missing module, missing dependency of that module, broken install, or a sys.path/CWD that does not include the utils package.","commonSituations":"Running the backend from a different working directory or as a packaged binary that omits the utils package; a broken venv after a partial upgrade; utils.hardware itself raising on import due to a missing helper dependency (e.g. nvidia-smi wrapper deps) on an unusual host.","solutions":["Run the backend from the repository root (or otherwise ensure utils.hardware.hardware is importable) and repair the install","python -c 'from utils.hardware.hardware import get_parent_visible_gpu_ids' to reproduce and see the underlying error","As a workaround, clear the GPU selection (empty gpu_ids) so the default device resolution runs without the hardware layer"],"exampleFix":"# before\nordinal = resolve_gpu_ordinal(gpu_ids=[0])  # utils.hardware not importable\n\n# after\n# fix the environment first:\n#   cd <repo root> && python -c \"from utils.hardware.hardware import get_parent_visible_gpu_ids\"\nordinal = resolve_gpu_ordinal(gpu_ids=[0])\n# or bypass selection:\nordinal = resolve_gpu_ordinal(gpu_ids=None)","handlingStrategy":"try-catch","validationCode":"def gpu_selection_available() -> bool:\n    try:\n        from utils.hardware.hardware import get_parent_visible_gpu_ids  # noqa: F401\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    ordinal = resolve_gpu_ordinal(gpu_ids, allow_ranking=True)\nexcept ValueError as e:\n    if \"unavailable on this host\" in str(e):\n        fix_environment_or_run_without_gpu_selection()  # or pass gpu_ids=None\n    raise","preventionTips":["Smoke-test the hardware layer import at backend startup, not at first GPU pick","Run the backend from the repo root with the full source tree deployed","Degrade gracefully: clear the GPU selection rather than failing the load when the layer is optional"],"tags":["gpu","environment","import-error","cuda"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}