Repository navigation
Studio: give Intel XPU Triton a working C++ toolchain on Windows - #14814
danielhanchen merged 10 commits into
Conversation
Intel's XPU Triton builds its SYCL helpers with icpx, else cl from PATH, else $CXX. Studio is not started from a Developer Command Prompt, so cl is not on PATH and every chat on an Intel GPU failed with "Failed to find C++ compiler". Setting CXX did not help either: Triton picks MSVC flags only when the path contains the literal "cl.EXE", so "cl.exe" got GNU flags (D8021 on /Wno-psabi), and clang++ got the MSVC /LIBPATH: flags Triton always adds on Windows. When XPU Triton is installed on Windows, load the Visual Studio C++ environment through vswhere and vcvars64.bat if it is missing, and set CXX to cl spelled the way Triton recognises. A GNU driver in CXX is left as the user set it, with a warning that explains why it cannot work. Refs unslothai#14807
|
@codex review |
|
@codex security 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d699054bb
ℹ️ 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".
| root = os.environ.get("LEVEL_ZERO_V1_SDK_PATH") or os.environ.get("ZE_PATH") | ||
| dirs = [os.path.join(root, "include")] if root else [] | ||
| dirs += os.environ.get("INCLUDE", "").split(os.pathsep) | ||
| return any(d and os.path.isfile(os.path.join(d, "level_zero", "ze_api.h")) for d in dirs) |
There was a problem hiding this comment.
Require the Level Zero loader library before reporting the SDK
On a Windows XPU host where ze_api.h is present but ze_loader.lib is absent—for example, a header-only SDK or a Level Zero include added to INCLUDE without its library added to LIB—_level_zero_sdk_found() returns true here. _prepare() then omits the only Level Zero warning even though the helper link described immediately above still fails, leaving chat/compile with an unexplained linker error; verify the import library in the SDK/library search paths as well as the header.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the official level-zero-win-sdk zip ships include/level_zero/ze_api.h and lib/ze_loader.lib together, and Triton derives both paths from the same LEVEL_ZERO_V1_SDK_PATH root, so a header-only state is not a real install. This check only decides whether a log hint is printed.
|
@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: 5d699054bb
ℹ️ 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".
| if not _msvc_environment_loaded() and _load_msvc_environment(): | ||
| log.info("Loaded the Visual Studio C++ environment for Intel XPU Triton") | ||
| cl = shutil.which(cxx or "cl") |
There was a problem hiding this comment.
Require a complete MSVC environment before accepting cl
When cl is already on PATH (or CXX points to it) but INCLUDE/LIB are not initialized, a failed or partial _load_msvc_environment() falls through here and line 159 still finds the executable; line 167 then advertises it to Triton even though this module's own _msvc_environment_loaded() predicate is still false. MSVC cannot compile and link the XPU helper without those CRT headers and libraries, so this changes the startup failure into a later JIT error; only accept cl after rechecking the loaded environment, and otherwise emit the Build Tools warning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: reaching this line with cl found but no INCLUDE/LIB needs cl on PATH or in CXX while vswhere finds no Visual Studio with the C++ tools, which a Build Tools install does not produce. That state fails on main too (D8021 there), so the only difference would be one extra log line.
|
@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: 1bdfe6437d
ℹ️ 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".
| import urllib.request # noqa: PLC0415 | ||
| import zipfile # noqa: PLC0415 | ||
|
|
||
| with urllib.request.urlopen(_L0_URL, timeout = 30) as response: |
There was a problem hiding this comment.
Honor offline mode before fetching the SDK
When a Windows XPU worker has cl but no cached Level Zero SDK and the operator has set UV_OFFLINE=1 (or a user-set HF_HUB_OFFLINE/TRANSFORMERS_OFFLINE), this unconditional call still reaches GitHub and can wait for the 30-second timeout. studio/backend/utils/utils.py:43-56 defines those switches as forbidding on-demand installs, so this path should return the existing manual-install warning without networking while still accepting a complete cached SDK.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5628ac3: the fetch now follows package_installs_offline(), so UV_OFFLINE or an operator-set HF offline only uses a cached SDK and otherwise prints the manual-install hint.
| target.write_bytes(archive.read(member)) | ||
| # Another worker may have won the race; its copy is the same pinned archive. | ||
| try: | ||
| os.replace(staging, dest) |
There was a problem hiding this comment.
Replace an incomplete SDK cache before installing
When the versioned cache directory already exists but is incomplete—for example, antivirus or cache cleanup removed lib/ze_loader.lib—_provide_level_zero_sdk() calls this fetch, but on Windows os.replace(staging, dest) cannot replace the remaining non-empty directory. The exception path re-raises because that destination is still incomplete, so every later worker repeats the failure and XPU remains unusable until the user discovers and deletes the internal cache directory; quarantine or remove an incomplete destination before atomically installing the staging tree.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the SDK is unpacked into a fresh staging directory and moved into place in one rename, so Studio never leaves a partial cache directory. A partial one needs a third party deleting files out of Studio's cache, which this does not try to repair.
|
@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: 5628ac328f
ℹ️ 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".
| if not os.path.isfile(vswhere): | ||
| return None | ||
| try: | ||
| done = subprocess.run( |
There was a problem hiding this comment.
Hide the toolchain discovery subprocesses
When Studio starts an XPU inference, training, or export worker from the Windows desktop shell without an attached console, both new subprocess.run calls launch console-subsystem executables without the repository's windows_hidden_subprocess_kwargs; vswhere.exe and especially the cmd.exe/vcvars64.bat call can therefore create visible console windows on every worker start. Pass the helper's kwargs to both probes so toolchain discovery remains invisible in desktop mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8a9b537: both vswhere and the vcvars cmd now run with windows_hidden_subprocess_kwargs(), so a Desktop worker start opens no console window.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Four checks fail on `main` (fd924a5), so every open PR inherits them. Each was reproduced on a clean `main` worktree and attributed. A fifth, `test_every_resolver_probe_forwards_the_trust_decision`, was fixed on `main` by #14990 in the meantime, so this PR takes that version. | Check | Introduced by | Wrong side | Fix | |---|---|---|---| | `studio/backend/tests/test_text_io_encoding.py::test_text_io_names_its_encoding[_xpu_triton_toolchain.py]` | #14814 | Product | The `vswhere` call used `text=True` with no encoding, so it decoded with the locale code page. A Visual Studio install path with non-ASCII characters would garble. It now passes `-utf8` to vswhere and decodes as UTF-8 (`errors="replace"`). | | `tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe` | 0947723 | Test | `test_packed_fp32_cuda_parity` skipped on `torch.cuda.is_available()`, which the CPU CI spoof answers True. It is now gated on `has_real_cuda()`, same as the sibling attention tests. | | `tests/studio/test_usage_examples_model_source_contract.py::test_examples_never_print_a_hardcoded_model_id` | #14914 | Test | #14914 deliberately renders the example with a `YOUR_MODEL` placeholder when nothing is servable, instead of hiding it. The test still asserted the old "no snippet" shape. | | `tests/test_fp8_pre_sm89_byte_dequant.py::test_kill_switch_env_is_read_at_import` | #14936 | Test | The subprocess imports `unsloth` in a fresh interpreter that has no conftest spoof, so on CPU CI the import raised "cannot find any torch accelerator" before the switch was read. With no GPU, the subprocess now applies `tests/_zoo_aggressive_cuda_spoof.py`, the same pattern `test_qat_phone_deployment.py` uses. It now checks both `0` and `1`. | For the third check, the invariant is unchanged: no hardcoded `unsloth/...` id and no `MODEL_FALLBACK`. The test now also pins the new contract: - the placeholder constant - the `model ?? MODEL_PLACEHOLDER` call as the only `buildSnippets` call site - the no-model note rendering exactly when the placeholder is shown ## Verification - On `main` before #14990: 4 failed in `tests/` and 1 failed in `studio/backend/tests`. - On this branch: `test_accelerator_skip_guards.py`, `test_usage_examples_model_source_contract.py` and `test_attention_packed_fp32_routing.py` give 48 passed, 1 skipped. With the two new files and `test_audio_load_routing.py` added, the run gives 94 passed, 133 skipped. `test_text_io_encoding.py` and `test_xpu_triton_toolchain_14807.py` give 904 passed. - Sabotage check: hardcoding `_HIP_FP8_BYTES_DEQUANT = True` fails the kill-switch test. - Sabotage check: both edits below make the updated contract test fail. - Changing the placeholder to `"unsloth/Qwen3-4B"`. - Dropping the `model ? null :` gate on the note.
Fixes #14807
Before: on Windows with an Intel GPU, chat with a local model through the Transformers path (for example a LoRA adapter) failed with "An internal error occurred." Intel's XPU Triton builds small SYCL helpers on first use with
icpx, elseclfrom PATH, else$CXX. Studio is not started from a Developer Command Prompt, soclis not on PATH and the build stopped at "Failed to find C++ compiler". SettingCXXdid not help: Triton picks MSVC flags only when the path contains the literalcl.EXE, socl.exereceived GNU flags (D8021on/Wno-psabi), andclang++received the MSVC/LIBPATH:flags Triton always adds on Windows. Past the compiler, the helpers also includelevel_zero/ze_api.hand linkze_loader.lib, which neither the Intel GPU driver nor the pip wheels ship.After: when XPU Triton is installed on Windows, Studio
vswhere, thenvcvars64.bat) if it is not already loaded, and setsCXXtoclspelled the way Triton recognises;LEVEL_ZERO_V1_SDK_PATH,ZE_PATH, orINCLUDE), fetches the officiallevel-zero-win-sdk-1.34.0.zip(317 KB, MIT) once into Studio's cache, checks its SHA-256, and pointsLEVEL_ZERO_V1_SDK_PATHat it. UnderUV_OFFLINEor an operator-set HF offline mode it uses only a cached copy and otherwise logs how to install the SDK by hand.It leaves things alone when
icpxis available orCXXalready namesicpx, does nothing for triton-windows (NVIDIA / AMD) or off Windows, and never raises. ACXXnaming a GNU driver such asclang++is left as set, with a warning. No Visual Studio found logs how to install the Build Tools. The discovery subprocesses run without a console window, andvcvarsoutput is read as UTF-16 so non-ASCII PATH entries survive.How:
core/_xpu_triton_toolchain.py, called fromgate_torch_compile_on_windows, which the inference, training and export workers already run on Windows. OnlyPATH,INCLUDE,LIBandLIBPATHare taken from vcvars. Telling Intel's Triton from triton-windows is a directory check on the already-imported package (backends/intel), so other Windows users pay no package scan.Evidence (windows-latest, torch 2.10.0+xpu, triton-xpu 3.6.0, building Triton's real
arch_utilsandspirv_utilshelpers; the runner has no Intel GPU, so Triton'sis_xpu()is forced on, which is the only branch a real Arc machine takes):Failed to find C++ compilerCXX=cl.exeD8021 invalid numeric argument '/Wno-psabi'CXX=clang++no such file or directory: '/LIBPATH:...'spirv_utilscannot be loaded on the runner becauseze_loader.dllcomes with the Intel GPU driver; it compiles and links.Tests:
studio/backend/tests/test_xpu_triton_toolchain_14807.py(discovery stubbed, runs on Linux CI) covers loading the environment and pointing Triton atcl, re-spellingcl.exe, leavingclang++andicpxalone, the Intel backend check, vcvars UTF-16 parsing, SDK detection and provisioning, archive unpacking with backslash member names, a bad hash or unsafe member leaving nothing behind, offline mode, hidden console windows, and the Windows gate calling the new step.tests/test_msvc_env_7595.pystill passes. Staging CI is green on Linux, macOS and Windows. Not covered: a real Intel Arc GPU running a kernel end to end.