Skip to content

Studio Windows XPU Triton: verify the swap and torch's XPU triton payload, repair a broken triton, skip pip backups - #16250

Merged
danielhanchen merged 11 commits into
mainfrom
studio-windows-xpu-triton-hardening
Nov 2, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
studio-windows-xpu-triton-hardening

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #16074. The review of that PR found problems in the Intel XPU Triton handling of the Windows installer. They date from before #16074, so it left them alone. #16074 added helpers that already solve the same problems on the AMD ROCm path, and this PR reuses them. It changes only the Windows installer (studio/setup.ps1); the Python stack's copy of the swap is listed under "Not covered".

On Intel XPU, setup replaces triton-windows with torch's own XPU triton, because both own the triton package.

studio/setup.ps1

  • The swap ignored inherited resolver settings. The XPU wheel install and the triton-windows fallback ran with whatever UV_OVERRIDE, UV_EXCLUDE, UV_CONSTRAINT and PIP_CONSTRAINT the shell had. With UV_EXCLUDE set, the install can exit 0 without installing the wheel after triton-windows was already removed. Setup then restored the install manifest over a venv with no triton.
    • Fetch, uninstall, install and fallback now run with those inputs cleared and require-hashes relaxed, as the ROCm pairing does.
    • The values are restored afterwards, and unset ones stay unset.
  • Exit 0 was taken as success. The XPU install now counts only when a fresh probe shows four things: the XPU dist is recorded at a version torch accepts, the imported triton reports that version, no triton-windows is left, and triton imports (Get-TritonRuntimeState). Anything less falls back to triton-windows:
    • the XPU dist is uninstalled first, so its record does not stay over the triton-windows files;
    • the fallback counts only once triton-windows is recorded and triton imports;
    • under installer-managed setup, falling back over a triton that was not triton-windows fails setup, so the installer keeps its rollback copy.
  • Get-XpuTritonState checks torch's XPU triton itself:
    • Version: the installed XPU dist must satisfy torch's requirement. The parser is packaging, else pip's vendored copy, else an exact == match on the versions without their local labels. A missing or versionless record fails, and so does a parser that is found but does not import: it falls through to the next one instead of failing the whole probe.
    • Payload: the imported triton's __version__ must match the dist, so generic triton files at another version under the XPU dist's record are not accepted. This runs as its own probe, so a triton that crashes on import still leaves the metadata readable. A metadata probe that fails part way still returns the fields it read (torch's requirement, triton-windows), so the repair can still run; the state stays unverified.
    • Effect: a missing XPU dist, a wrong version, or a generic payload sends the fast path into the dependency pass and the swap into a reinstall. A uv config override that installs another version no longer passes.
  • pip backups were counted as installed. The fast-path check and the post-stack probe matched dists on the metadata Name field. That also matches the ~riton_windows-* and ~itsandbytes-* backup folders an interrupted pip replacement leaves behind. Both lookups now use importlib.metadata.distributions(name=...), as Get-RocmTritonPairing does.
  • A broken triton with no triton-windows record was never repaired. Once only a backup is left, nothing named triton-windows triggers the dependency pass or the swap. A payload removed along with the record stayed broken. Two checks now also ask whether triton imports:
    • the fast-path check, which runs the dependency pass when it does not;
    • the swap entry, which reinstalls the XPU wheel. There is nothing to uninstall in that case.
  • A failed uninstall restored the manifest unconditionally. An uninstall can fail after removing some files. The manifest now goes back only while triton still imports.
  • Offline runs keep the verified tree. With UV_OFFLINE set (or on the verified offline fast path), the triton triggers do not start the dependency pass: not an active triton-windows, not a missing or wrong XPU triton. A stale or missing bitsandbytes still runs it, as on main. The swap fetches nothing either. Both say the repair is left for the next online update, as the ROCm pairing does.
  • A failed fetch for a triton already known not to import removes the install manifest, so the next update retries. A working triton keeps it.
  • When triton ends up broken, the outcome depends on whether triton imported before the swap (as in the ROCm repair). This applies after a failed uninstall and after a failed fallback.
    • If it imported before, the swap broke it: setup fails with the repair command, and the manifest is not restored.
    • If it was already broken: setup warns and withholds the manifest, so the next update tries again.
  • Under install.ps1 (installer-managed setup) setup fails whenever torch wants an XPU triton and triton does not import. That includes a triton already broken before the swap, an offline run that left the repair for later, and a metadata probe that could not read torch's requirement. The installer then restores its rollback copy instead of committing this venv.

New helpers sit next to the ROCm pairing helpers:

  • Enter-TritonInstallEnv / Exit-TritonInstallEnv, now also used by the ROCm repair, whose behaviour is unchanged;
  • Get-XpuTritonState.

CI

tests/studio/test_xpu_triton_windows_swap.ps1 now runs in cross-platform-parity-ci.yml, under pwsh and under Windows PowerShell 5.1, next to the ROCm pairing test. It is also added to both path filters.

Not changed

  • The ROCm repair's handling of a triton that was already broken. If the ROCm pairing cannot be repaired and triton did not import before, setup still warns and continues, including under install.ps1. Its test asserts that a missing triton that cannot be installed only warns, since on ROCm that leaves flex attention decode unfused rather than breaking anything that worked.

  • The triton-windows 3.9 to 3.8 churn on Windows ROCm torch 2.11 / 2.12. A fresh install still resolves triton-windows 3.9 first, and the Studio Windows AMD: pair triton-windows with torch after the dependency stack #16074 repair then replaces it with 3.8. Pinning it in studio/install_python_stack.py is not a small change:

    • The pin must be dynamic. It applies only to a Windows ROCm torch, which an environment marker cannot express, so it cannot go into the static single-env/constraints.txt that every install receives as -c.
    • A separate constraint would split the bookkeeping. The step-skip gate and the manifest's constraint check both digest and read only that file, so they would not see it.
    • It needs a torch probe per install. Detecting the ROCm torch takes a subprocess probe, and its cached result is dropped after every install.

    The repair is already verified, so this is left as is.

Tests

  • tests/studio/test_xpu_triton_windows_swap.ps1, 68 checks, ASCII only. It cuts the helpers, the fast-path check and the swap out of setup.ps1.
    • Stub cases:
      • verification: a verified install; exit 0 with nothing installed; an XPU dist that does not import; triton-windows still recorded after the install; an unreadable post-install probe; an install that leaves a version torch does not accept; an importable generic triton under the XPU dist's record;
      • failures: a failed install, a fallback that exits 0 without a working triton, a fallback that exits 0 with no triton-windows recorded, and a failed fallback;
      • the fallback uninstalls the XPU dist first; under installer-managed setup it fails over a triton that was not triton-windows;
      • a metadata probe that fails part way, and one that cannot read torch's requirement under installer-managed setup;
      • environment isolation and restore;
      • uninstall: a failed uninstall with triton still working, one that broke triton, and one where triton was broken before;
      • repair: a broken triton with no record, repaired and not repaired; an importable triton with no XPU dist; an XPU dist at another version;
      • fetch: a failed fetch for a broken and for a working triton;
      • installer-managed setup:
        • these fail setup: a failed uninstall, a failed repair and fallback, a failed fetch for a triton already broken, and a broken triton left for the next online update;
        • these do not: a verified swap, a failed uninstall that left triton importing, and an offline run with a triton-windows that imports;
      • offline: nothing is fetched for a broken triton or for triton-windows;
      • the cases where the swap does not apply.
    • Real Python against hand-made dist-info folders and a fixture triton package:
      • a ~riton_windows backup alone, with the files present and with them gone (the fast path, also offline, and the swap);
      • an active triton-windows (also offline); a record without Version; a ~itsandbytes backup (also offline and alone, where the dependency pass still runs);
      • the XPU dist missing, at 3.4.0 under a torch that requires 3.5.0, and without Version: none is XpuOk, and the fast path runs the dependency pass for the first two;
      • triton files reporting 3.4.0 under a 3.5.0 XPU record: not XpuOk; a triton/backends/intel directory does not decide;
      • ==3.5.0+git... against an installed 3.5.0+git... with no version parser importable: XpuOk;
      • a packaging that does not import: the next parser decides.
    • Previous revision: against it, 7 of the new checks fail; all 68 pass with this change.
  • All 26 PowerShell test files under tests/studio that read setup.ps1: they pass. On main, the 25 that exist there pass too.
  • Pester tests/studio_setup_ps1: 245 passed, 0 failed, 7 skipped, the same as main.
  • The 80 Python test files that read setup.ps1: 10111 passed and 26 failed, the same failing test IDs as the previous revision (Linux host failures, unrelated).
  • The real Linux pytorch-triton-xpu==3.5.0 wheel, installed alone into a venv, reports __version__ 3.5.0 and the backends amd, intel, nvidia, which the probe accepts.

Not covered

  • The Python stack's copy of the swap (_ensure_xpu_triton in studio/install_python_stack.py, used on Linux and by direct runs). It has the same kind of gaps: inherited resolver inputs, exit 0 taken as success, backups counted, no repair of a missing payload, and the setup.sh fast path checking only for a generic dist-info. It needs its own probe and tests, so it is left for a follow-up. The latest review's findings on install_python_stack.py and setup.sh (resolver inputs and verification around the XPU install, the early return with no generic record, the setup.sh fast path) are part of that follow-up, not this PR.
  • No Intel XPU hardware. The swap is covered by stubs and by the probe code run with real Python on Linux.
  • The Windows pytorch-triton-xpu wheel was not tried.
  • Windows PowerShell 5.1 itself: the tests ran under pwsh 7 on Linux. The CI step runs them under 5.1.

The XPU swap that replaces triton-windows with torch's XPU triton now runs
with inherited UV_OVERRIDE / UV_EXCLUDE / UV_CONSTRAINT / PIP_CONSTRAINT
cleared and require-hashes relaxed, as the ROCm pairing does, and counts an
install only once a fresh probe shows the XPU dist recorded, no
triton-windows left and triton importing. The triton-windows fallback is
verified the same way; one that exits 0 without a working triton fails
setup instead of certifying the venv.

The fast-path check and the swap probe look dists up by name, so a
~riton_windows-* or ~itsandbytes-* backup left by an interrupted pip is no
longer read as installed. Follow-up to #16074.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T13:32:49.620255Z 16cc0b8 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

setup.ps1
- The dependency fast path and the post-stack swap also ask whether triton
  imports. Once only a ~riton_windows backup is left there is no
  triton-windows record to trigger a repair, so a payload removed with it
  stayed broken. A broken triton with no record is now reinstalled from the
  XPU wheel, with nothing to uninstall.
- A failed triton-windows uninstall puts the install manifest back only
  while triton still imports. One that removed files part way and left
  triton unimportable fails setup when triton worked before the swap. A
  triton that was already broken warns and withholds the manifest, so the
  next update retries; the fallback failure path follows the same rule.

install_python_stack.py (_ensure_xpu_triton)
- Download, uninstall and install run with UV_OVERRIDE, UV_EXCLUDE,
  UV_CONSTRAINT and PIP_CONSTRAINT cleared and require-hashes off, restored
  afterwards, as setup.ps1 does.
- After the install a fresh interpreter must find the XPU dist, no generic
  triton and a working triton.language; otherwise setup fails with a
  repair command instead of certifying a venv with no triton.
- The generic triton probe looks dists up by name, so a ~riton-* backup is
  not a triton to swap out.

CI: run test_xpu_triton_windows_swap.ps1 under pwsh and Windows
PowerShell 5.1 in the cross-platform parity workflow.

[skip ci]
@danielhanchen danielhanchen changed the title Studio Windows: verify the Intel XPU Triton swap and skip pip backups Studio XPU Triton: verify the swap, repair a broken triton, skip pip backups Oct 31, 2026
…on probe, defer offline, keep the rollback

[skip ci]
@danielhanchen danielhanchen changed the title Studio XPU Triton: verify the swap, repair a broken triton, skip pip backups Studio XPU Triton: verify the swap and torch's XPU triton version, repair a broken triton, skip pip backups Oct 31, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 31, 2026
@danielhanchen danielhanchen changed the title Studio XPU Triton: verify the swap and torch's XPU triton version, repair a broken triton, skip pip backups Studio Windows XPU Triton: verify the swap and torch's XPU triton payload, repair a broken triton, skip pip backups Oct 31, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 31, 2026
…back under the installer, drop the Intel directory check

[skip ci]
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 31, 2026
danielhanchen added a commit that referenced this pull request Oct 31, 2026
## Summary

Every `Core zoo` cell in `consolidated-tests-ci.yml` is now being
cancelled at its 35 minute job cap, on unrelated PRs, with the
unsloth_zoo suite at 99%. It is the same failure #14240 fixed at 25
minutes: the suite has grown past the cap.

A passing cell from today, for scale: the zoo `pytest -n 4` step
reported `14494 passed, 2462 skipped ... in 1770.53s (0:29:30)`, and the
whole job ran 34m57s, three seconds under the cap.

## Change

- `Core zoo` job: `timeout-minutes: 35` -> `50`, comment updated with
the current numbers.
- Unchanged: the 5 minute `PYTEST_TIMEOUT` per test, which is what names
and stack-dumps a genuine hang. The job cap only bounds the total.

## Evidence

Staging Core runs since 2026-10-30 21:28 UTC, Core zoo cells by combo:

| PR | HF=4.57.6 | HF=default | HF=latest |
|---|---|---|---|
| #16041 | failure | cancelled | cancelled |
| #16249 | cancelled | cancelled | cancelled |
| #16250 | cancelled | cancelled | cancelled |
| #16257 | cancelled | cancelled | cancelled |
| #16255 (run 1) | cancelled | success (34m57s) | success (28m46s) |
| #16255 (run 2) | success | cancelled | cancelled |

The cancelled cells end with `##[error]The operation was canceled.`
while the suite is printing its last progress lines (98-99%).

## Tests

`tests/studio/test_zoo_suite_parallel_isolation.py`,
`test_workflow_guards_run_unfiltered.py` and every test that reads
`consolidated-tests-ci.yml`: 267 passed.

## Not proven

- This PR's own CI run is the first measurement at the new cap; whether
50 minutes leaves enough headroom as the suite keeps growing is not
known.
@danielhanchen danielhanchen self-assigned this Nov 2, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a8f125bd18

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 16cc0b8343

ℹ️ 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".

@danielhanchen
danielhanchen merged commit c72742f into main Nov 2, 2026
@danielhanchen
danielhanchen deleted the studio-windows-xpu-triton-hardening branch November 2, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant