Repository navigation
install.sh: install XPU PyTorch on Linux when an Intel Arc / Data Center GPU is the only GPU - #13193
Conversation
…U is the only GPU
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8663ae4fc3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return | ||
| # Unpinned: install.sh's Intel GPU route (UNSLOTH_TORCH_BACKEND=xpu), or, on a standalone | ||
| # update, the XPU flavor that install recorded. Any other stated backend or pin wins. | ||
| if _explicit_torch_index_family() is not None or (_TORCH_BACKEND or _RECORDED_TORCH_TAG) != "xpu": |
There was a problem hiding this comment.
Do not let a recorded XPU flavor override a newly detected GPU
On a standalone studio update after the Intel GPU has been replaced or augmented with an NVIDIA GPU, _TORCH_BACKEND is empty and the old automatically recorded xpu value activates this branch without checking current hardware. _ensure_cuda_torch() runs first and converts the XPU build to CUDA for the detected NVIDIA GPU, but this subsequent repair immediately force-reinstalls XPU torch; the same sequence can occur again during the final repair pass, leaving the installation unable to use the GPU that a fresh install would select. Gate the recorded-flavor fallback on the absence of a currently usable competing GPU, or resolve one desired backend before running the repair helpers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 87deee2: the recorded XPU flavor now yields when an NVIDIA or AMD GPU is present (_has_usable_nvidia_gpu / _has_rocm_gpu), so a standalone update after adding a card no longer reinstalls XPU torch over the CUDA or ROCm repair. install.sh's own xpu backend still acts. Tests cover both vendors.
| # Unpinned: install.sh's Intel GPU route (UNSLOTH_TORCH_BACKEND=xpu), or, on a standalone | ||
| # update, the XPU flavor that install recorded. Any other stated backend or pin wins. | ||
| if _explicit_torch_index_family() is not None or (_TORCH_BACKEND or _RECORDED_TORCH_TAG) != "xpu": |
There was a problem hiding this comment.
Force the setup fast path to run recorded XPU repair
When an automatically configured XPU installation has subsequently acquired a CPU torch wheel and unsloth is already at the latest version, studio/setup.sh takes its dependency fast path and never calls this new recorded-flavor repair. Its escape checks only an explicit XPU index pin plus stale AMD/CUDA builds; it does not inspect the recorded XPU flavor, so _ensure_xpu_torch() is unreachable in exactly the unpinned standalone-update case this branch is intended to heal. Add a stale-XPU fast-path check analogous to the AMD/CUDA checks so the dependency pass is forced when the manifest records XPU but the resident wheel does not match.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 87deee2: setup.sh now has a stale-XPU fast-path escape mirroring the CUDA one. It runs install_python_stack.py --xpu-torch-needs-dependency-pass, which answers from _ensure_xpu_torch(probe_only=True), so a current package with a CPU wheel under a recorded XPU flavor forces the dependency pass. Offline it is left for the next online update, as the CUDA check does.
| pin = _pytorch_whl_leaf_url("xpu") | ||
| if pin is None: | ||
| return |
There was a problem hiding this comment.
Report an unexpressible XPU repair instead of silently skipping it
When the unpinned XPU signal comes from _TORCH_BACKEND or the recorded flavor and UNSLOTH_PYTORCH_MIRROR contains a query or fragment, _pytorch_whl_leaf_url("xpu") returns None; this new early return then reports success without even checking whether the resident torch is still XPU. A standalone update can therefore leave a CPU or CUDA wheel in place while recording the dependency pass as successful, contrary to this function's documented False result when a required repair cannot be expressed. Continue with the runtime check and return False if a repair is actually needed but no usable XPU URL can be constructed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 87deee2: an unpinned XPU signal no longer returns early when _pytorch_whl_leaf_url("xpu") is None. The runtime check runs, and _ensure_xpu_torch returns False only when a repair is needed (a supported +xpu wheel still returns None). Tests cover the install.sh route and the recorded flavor.
…ss on a stale XPU wheel, honour an emptied ZE_AFFINITY_MASK, report an unexpressible repair
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87deee2de9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # An emptied ZE_AFFINITY_MASK hides every Intel device, as Studio reads it. | ||
| if [ -n "${ZE_AFFINITY_MASK+x}" ]; then | ||
| case "$(printf '%s' "$ZE_AFFINITY_MASK" | tr -d '[:space:]')" in ''|-1) return 1 ;; esac |
There was a problem hiding this comment.
Validate the Intel device selected by the affinity mask
On a host containing both an ordinary Intel iGPU and a supported Arc/Data Center GPU, a nonempty ZE_AFFINITY_MASK can select only the ordinary iGPU while hiding the supported card. This check accepts every nonempty mask, and _intel_xpu_gpu_id() subsequently scans the unfiltered physical PCI inventory and finds the hidden Arc, so the installer auto-selects XPU even though the visible device set contains no allowlisted GPU. Resolve the mask to a supported visible device, or decline automatic routing when that cannot be established.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2878650: the auto route in install.sh and the Python revalidation both decline whenever ZE_AFFINITY_MASK is set, empty or not, since Level Zero indices need not follow PCI order. install.sh logs one info line saying to set UNSLOTH_TORCH_INDEX_FAMILY=xpu; an explicit pin still installs XPU PyTorch. ZE_AFFINITY_MASK=0 with an Arc card now resolves to cpu, with a new cell for the info line.
…tel GPU before replaying a recorded XPU flavor
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28786507c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| [ "${UNSLOTH_DISABLE_XPU_AUTO:-0}" = 1 ] && return 1 | ||
| [ -n "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && return 1 | ||
| # Level Zero mask indices need not follow PCI order, so any mask leaves the choice to a pin. | ||
| if [ -n "${ZE_AFFINITY_MASK+x}" ]; then |
There was a problem hiding this comment.
Honor SYCL device filters before auto-selecting XPU
On an Arc host with ONEAPI_DEVICE_SELECTOR=opencl:cpu or SYCL_DEVICE_FILTER=cpu, the SYCL runtime exposes no GPU, but this gate checks only ZE_AFFINITY_MASK and still installs XPU torch from the physical PCI inventory. Intel documents that these selectors restrict the devices visible to SYCL applications and that selecting a filtered-out GPU fails (Intel oneAPI device selection). The same omission in studio/install_python_stack.py:4633 also makes updates keep repairing back to XPU; decline the unpinned auto-route when either selector is set, as this code already does for an ambiguous Level Zero mask.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ce2cf16: the unpinned auto route now also declines when ONEAPI_DEVICE_SELECTOR or SYCL_DEVICE_FILTER is set, in both the install.sh gate and _intel_xpu_auto_route_holds. install.sh prints the same info line as for ZE_AFFINITY_MASK, naming the variable and the UNSLOTH_TORCH_INDEX_FAMILY=xpu pin. Explicit pins still win. New shell and pytest cells cover both variables and a selector plus pin.
| esac | ||
| _ix_n=$(printf '%d' "$_ix_d" 2>/dev/null) || continue | ||
| if { [ "$_ix_n" -ge 22160 ] && [ "$_ix_n" -le 22210 ]; } || # 0x5690-0x56C2 | ||
| { [ "$_ix_n" -ge 2921 ] && [ "$_ix_n" -le 3045 ]; } || # 0x0B69-0x0BE5 |
There was a problem hiding this comment.
Use exact PVC IDs instead of the whole interval
On an Intel Cedar Trail system with device ID 0x0be0 through 0x0be5, this interval classifies the legacy PowerVR GMA 3600/3650 display controller as a Data Center GPU and auto-installs XPU torch. The upstream Linux PCI table identifies those IDs as Cedar Trail (Linux gma500 PCI table), while Intel's XPU runtime lists only the sparse PVC IDs 0x0bd0, 0x0bd4–0x0bdb, 0x0b69, and 0x0b6e (Intel compute-runtime device table). Replace this range with the exact supported IDs in this detector and the copied Python allowlist so old Intel-only machines remain on CPU torch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ce2cf16: the 0x0B69-0x0BE5 range is gone. PVC is now matched by the exact ids Intel compute-runtime lists (0x0BD0, 0x0BD4-0x0BDB, 0x0B69, 0x0B6E) in install.sh, install_python_stack.py and Studio's hardware.py, which the parity checks keep equal. 0x0BE0 and 0x0BE5 (Cedar Trail, gma500) are negative cells in the installer shell test, the update pytest and test_gpu_probe_robustness.py.
| return 1 | ||
| fi | ||
| _amd_hardware_corroborated && return 1 | ||
| _intel_xpu_gpu_id |
There was a problem hiding this comment.
Detect Intel XPU devices on WSL before falling back to CPU
On WSL2 with an Intel Arc GPU, this PCI-only fallback always returns no device because WSL exposes the GPU through /dev/dxg rather than a PCI display entry—the existing _amd_hardware_corroborated helper explicitly documents that WSL enumerates no PCI display device. Consequently an unpinned install still chooses CPU, and the Python revalidation likewise refuses to replay a recorded XPU route, even though PyTorch documents WSL2 Ubuntu as a supported XPU platform (PyTorch Intel GPU prerequisites). Add a WSL-aware Intel runtime/vendor probe instead of relying exclusively on _intel_xpu_gpu_id.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this one as is. WSL exposes no PCI display device for the GPU, so the sysfs scan cannot see an Intel card there, and detecting it through /dev/dxg would need a runtime probe at install time. The unpinned route stays CPU on WSL, exactly as before this PR, and UNSLOTH_TORCH_INDEX_FAMILY=xpu selects XPU PyTorch there.
… id (not Cedar Trail), Windows-safe fake PCI names
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…"default" ZE_AFFINITY_MASK as unset Mesa (iris_pci_ids.h) names 0xB084-0xB087 Arc Pro B390/B370, the kernel binds them under xe, and compute-runtime lists them (unnamed). Level Zero skips the mask when it is empty or "default" (compute-runtime isAffinityMaskSet), so every Intel GPU stays visible there.
|
The That is a trap body that bash cannot parse, and it is installed in the torch phase this PR changes. No other PR in the last 30 shows it, so it looks like an issue in this PR's install.sh. The Backend and Repo test reds are from the stale base e7cf10f; #13173 and #13022 already fixed them on main, so a rebase should clear them. |
…E_ALLOWLIST, record the opt-out as a deliberate CPU choice
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Follow-up on the This PR does not touch any trap in install.sh, and the line the kill lands on ( |
…selectors are set
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The problem
On Linux, a host whose only GPU is an Intel Arc or Data Center card gets CPU PyTorch unless the user pins
UNSLOTH_TORCH_INDEX_FAMILY=xpu.get_torch_index_urlfalls straight from "no NVIDIA, no AMD ROCm" to$_base/cpu, and the XPU torch floor in install.sh is commented "Reached only through an explicit pin".Windows already does this automatically: install.ps1 matches
Intel.*(Arc|Data Center GPU)and reroutes to the xpu index. Two PRs meant to bring the same to Linux, #9084 and #5274, are marked merged, but both merge commits (617b0d4, 26db015) are empty, so nothing landed.unsloth studio updatehas the same gap:_ensure_xpu_torchonly acts on an explicit xpu pin, and install.sh never exportsUNSLOTH_TORCH_BACKENDfor an xpu index, so the install does not record the XPU flavor either.The change
install.sh:_intel_xpu_gpu_id. It walks/sys/bus/pci/devicesfor a vendor 0x8086 display device (class 0x03*) whose id is in the same allowlist Studio uses for XPU-capable parts:_INTEL_XPU_PCI_ID_RANGES/_INTEL_XPU_PCI_IDSinstudio/backend/utils/hardware/hardware.py. That covers Arc A / B, Data Center GPU Max and Flex, and the Arc-branded Core Ultra iGPUs, including the Panther Lake Arc Pro B390/B370 ids 0xB084-0xB087 (named in Mesa's iris_pci_ids.h, listed unnamed by compute-runtime). Data Center GPU Max (PVC) is now matched by the exact ids Intel compute-runtime lists (0x0BD0, 0x0BD4-0x0BDB, 0x0B69, 0x0B6E) in all three places, hardware.py included: the old 0x0B69-0x0BE5 range also took Cedar Trail (0x0BE0-0x0BE5, a gma500 legacy GPU).get_torch_index_urlreturns the xpu index only when it would otherwise return CPU, i.e. no NVIDIA GPU, no AMD ROCm GPU, and on x86_64.UNSLOTH_DISABLE_XPU_AUTO=1(the opt-out), whenONEAPI_DEVICE_SELECTOR,SYCL_DEVICE_FILTERorSYCL_DEVICE_ALLOWLISTis set at all, whenZE_AFFINITY_MASKis set to anything other than "" or "default" (Level Zero treats those two as no mask: compute-runtimeisAffinityMaskSet), whenUNSLOTH_ROCM_GFX_ARCHis set, or when AMD silicon is present, since the runtime-less AMD reroute owns a*/cpuindex there.0can expose only an ordinary iGPU while an Arc card sits on the bus. An info line names the variable and says to pinUNSLOTH_TORCH_INDEX_FAMILY=xpuinstead.UNSLOTH_TORCH_INDEX_URL/_FAMILYpins return earlier and are unchanged.UNSLOTH_TORCH_BACKEND=xpu.resolved, so the manifest records a deliberate CPU choice and Studio does not offer an XPU repair.Intel GPU (<id>, XPU)instead of "none (CPU-only)".studio/install_python_stack.py:_ensure_xpu_torchalso acts, unpinned, when the resolved backend is xpu, or on a standalone update when the recorded flavor is xpu.UNSLOTH_TORCH_BACKEND=xpu(not markedresolved) is a preference and is honoured as is. Otherwise it first re-asks the install.sh route through_intel_xpu_auto_route_holds: no opt-out, no effectiveZE_AFFINITY_MASK/ONEAPI_DEVICE_SELECTOR/SYCL_DEVICE_FILTER/SYCL_DEVICE_ALLOWLIST, no AMD display device, and an allowlisted Intel display device in/sys/bus/pci/devices. So an update does not reinstall XPU PyTorch after the Arc card is removed, masked or opted out. The allowlist is a copy of the hardware.py tables.probe_onlymode backs a new--xpu-torch-needs-dependency-passflag.studio/setup.sh: a stale-XPU fast-path escape, mirroring the CUDA one, forces the dependency pass when the package is current but the wheel is not the XPU build this install chose.The existing xpu path (2.6 floor, flavor repair, XPU bitsandbytes) is reused as is.
Tests
tests/sh/test_install_intel_xpu_auto_route.shruns the realget_torch_index_urlagainst a fake PCI tree:ZE_AFFINITY_MASK"" or "default"FAMILY=cpu, Arc + opt-out, Arc +UNSLOTH_ROCM_GFX_ARCH, Arc +ZE_AFFINITY_MASK"-1" or "0", Arc +ONEAPI_DEVICE_SELECTOR, Arc +SYCL_DEVICE_FILTER, Arc +SYCL_DEVICE_ALLOWLIST, Arc + mask or selector + xpu pin (xpu), Arc on aarch64resolved)resolvedThe same file checks that the install_python_stack.py tables equal the hardware.py tables (AST-read) and that the shell accepts exactly those ids (32 probes including the range edges).
tests/studio/install/test_xpu_auto_route_update.py(52 cases):/whl/xpufor the install.sh route and for a recorded xpu flavor.+xpuwheel, or a recorded xpu flavor beside an NVIDIA or AMD GPU.ZE_AFFINITY_MASK"0",ONEAPI_DEVICE_SELECTOR,SYCL_DEVICE_FILTER,SYCL_DEVICE_ALLOWLIST, opt-out), nothing is touched; a stated (unmarked) xpu backend still repairs; PVC and Panther Lake Arc Pro ids still route; aZE_AFFINITY_MASKof "" or "default" keeps the route; an explicit xpu pin still repairs with a mask or selector set.On main 21 of 52 fail. The fake PCI directories avoid
:so the file also runs on Windows.studio/backend/tests/test_gpu_probe_robustness.pyadds PVC 0x0bd0 / 0x0b69 / 0x0b6e (xpu) and 0x0bdc, Cedar Trail 0x0be0 / 0x0be5 (not xpu); the last three fail on main.All 89 existing
tests/shsuites give the same exit codes on main and this branch, all 0. The install-related pytest files (test_rocm_support.py,test_install_python_stack.py,test_cuda_repair.py,test_windows_torch_flavor_invariant.py,test_torch_probe_memoization.py,test_amd_fastpath_probe.pyand others) show only the same 4 pre-existingTestProgressStepCountMatchesTotalfailures on both. One source-text test intest_xpu_triton_swap.pykeyed on the old_ensure_xpu_torch()signature now finds the function by name.No Intel Arc was available, so this is shown on a fake sysfs tree and stubbed torch probes, not on hardware. The
ZE_AFFINITY_MASKhandling was checked against Intel's own driver (compute-runtime 26.35 and 25.35 with fake devices, stocktorch 2.14.1+xpu): "" and "default" expose every device, while "-1" or an out-of-range id selects none.Related: #8556, #12836, #8931.