Skip to content

Stop the torchao ROCm test from depending on the host's GPU - #10099

Merged
danielhanchen merged 2 commits into
mainfrom
fix-torchao-test
Sep 1, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-torchao-test

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

test_skips_torchao_on_windows_rocm is failing on main. It fails on CI and passes on a CUDA workstation, on identical code.

Why

The fixture describes a machine that cannot exist: a Windows host with ROCm torch installed and a usable NVIDIA GPU.

monkeypatch.setattr(mod, "_rocm_windows_torch_installed", True)   # a ROCm box
monkeypatch.setattr(mod, "_has_usable_nvidia_gpu", lambda: True)  # ... with an NVIDIA GPU

That second flag is exactly the input _expected_torch_flavor_tag uses to decide whether a CUDA expectation exists at all:

if _explicit_torch_index_url() is None and not _has_usable_nvidia_gpu():
    return ""
return _torch_index_leaf(_detect_cuda_torch_index_url())

So the test asked for a cu* build on a box it had just called ROCm.

That was inert until #9857 added the Windows torch flavor invariant (step 13w), the first step in install_python_stack that reads the real installed torch. Combined with the CPU-only torch studio-backend-ci.yml installs, the invariant correctly refused the install and returned 1, so a test about torchao selection failed on an assertion about the whole installer:

FAILED tests/test_torchao_select.py::test_skips_torchao_on_windows_rocm[True-False]
  AssertionError: assert 1 == 0

Reproduced by pinning the probe to the CPU torch CI installs: with the NVIDIA flag True the installer emits "PyTorch is CPU-only but a cu126 GPU build was expected for this machine" and returns 1; with it False it returns 0 and the torchao assertions hold.

#9857 is correct and is unchanged

On a real Windows ROCm host _has_usable_nvidia_gpu() is False, so the expected tag is empty and the invariant returns early. No ROCm user is affected, and a Windows box that expected a GPU build but holds CPU-only torch should fail the install rather than report success. The fixture was wrong, not the code.

What changed

  • The host is coherent again: no usable NVIDIA GPU on a ROCm box.
  • The installed torch is pinned through _probe_torch_runtime and _RECORDED_TORCH_TAG, so the verdict no longer depends on whichever torch the developer happens to have. This is what made it green locally and red on CI.
  • A precondition assertion on _expected_torch_flavor_tag() == "" runs before the install, so the next time a later step reaches back into real hardware the failure names its cause instead of surfacing as assert 1 == 0.
  • Adds the (True, True) case. Both signals agreeing is the ordinary Windows ROCm state and the parametrization only covered the two mixed ones.

No coverage is lost: #9857's invariant keeps its own tests in tests/studio/install/test_windows_torch_flavor_invariant.py.

Verification

  • studio/backend/tests/test_torchao_select.py: 30 passed (29 before, plus the new case).
  • Passes both on a CUDA host and under CUDA_VISIBLE_DEVICES="", where it used to be host-dependent.
  • tests/studio/install/ + tests/python/test_install_python_stack.py: 3460 passed, 3 skipped.
  • Mutation check: restoring _has_usable_nvidia_gpu -> True reproduces the original CI failure, and the new precondition reports it with the reason.

test_skips_torchao_on_windows_rocm described a machine that cannot exist: a
Windows host with ROCm torch installed AND a usable NVIDIA GPU. The NVIDIA
claim is the input _expected_torch_flavor_tag uses to decide whether a CUDA
expectation exists at all, so the test asked for a cu* build on a box it had
just called ROCm.

That was inert until #9857 added the Windows torch flavor invariant, which is
the first step in install_python_stack to read the real installed torch. With
a CUDA expectation manufactured by the test and the CPU-only torch that
studio-backend-ci.yml installs, the invariant correctly refused the install
and returned 1, so a test about torchao selection failed on an assertion about
the whole installer. It passed on a CUDA workstation and failed on CI, on the
same code.

The invariant is right and stays as it is: on a real Windows ROCm host
_has_usable_nvidia_gpu is False, the expected tag is empty, and the step
returns early, so no ROCm user is affected. It is the fixture that was wrong.

The host is now coherent (no NVIDIA GPU), and the installed torch is pinned
through _probe_torch_runtime and _RECORDED_TORCH_TAG so the verdict no longer
depends on whatever torch the developer happens to have. #9857's invariant
keeps its own coverage in tests/studio/install/test_windows_torch_flavor_invariant.py.

Also adds the (True, True) case. Both signals agreeing is the ordinary Windows
ROCm state and the parametrization only covered the two mixed ones.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 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-08-31T23:53:26.325932Z ccdd0a9 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2c79361b9

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

# Checked BEFORE the install so a regression names its cause here rather than as
# an opaque `assert 1 == 0` on the line below, which is how this surfaced: the run
# returned 1 on a CPU-only runner and 0 on a CUDA workstation, on identical code.
assert mod._expected_torch_flavor_tag() == "", (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear ambient torch-selection variables before asserting

When the suite is run with a supported torch selection variable already exported, this assertion remains environment-dependent: _expected_torch_flavor_tag() checks UNSLOTH_EXPECTED_TORCH_TAG, UNSLOTH_TORCH_INDEX_URL, and UNSLOTH_TORCH_INDEX_FAMILY before the newly patched GPU/manifest inputs. In particular, setup.ps1 exports UNSLOTH_EXPECTED_TORCH_TAG=rocm for its normal Windows ROCm handoff, while a developer may run tests with an explicit family such as cu128; either makes this assertion fail despite identical code. Delete or explicitly set these variables in the fixture (or model the ROCm handoff) so the test is actually isolated from its host environment.

Useful? React with 👍 / 👎.

fastmcp 4.0.0 released today and dropped FastMCP._call_tool_mcp, so this
test started failing with AttributeError on every CI run that resolved
the dependency fresh. The pin is an open fastmcp>=3.0.2, so nothing held
CI on 3.x.

Nothing in the product is affected: every fastmcp import the backend
actually makes still resolves on 4.0.0, and the whole backend suite is
green there apart from this one test. So the pin is fine and only the
test needs to change.

Switch to get_tool/call_tool, which are public and carry the same
signatures on 3.0.2 (the floor) and on 4.0.0, and drop the
server._mask_error_details assertion. That flag was a stand-in for "the
409 detail reaches the caller", which the two message assertions below it
already prove directly, so the check cost a private attribute and bought
nothing. Verified against real installs of both 3.0.2 and 4.0.0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ccdd0a9258

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

Comment on lines +153 to +156
monkeypatch.setattr(mod, "_RECORDED_TORCH_TAG", "")
monkeypatch.setattr(
mod, "_probe_torch_runtime", lambda *args, **kwargs: (True, True, "2.9.1+cpu", "", "")
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stub the final core-payload gate in this installer test

On a clean backend test runner where the unsloth distribution is not installed, these new stubs still do not isolate the test from ambient package state. Since SKIP_STUDIO_BASE=1 prevents the core package from being installed, the final install_python_stack() call reaches _repair_damaged_core_payload(..., require_present=True), returns false for the absent distribution, and still produces the failing assert 1 == 0. Stub _repair_damaged_core_payload to return true here, as with the other unrelated installer side effects.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 9954357 into main Sep 1, 2026
33 of 36 checks passed
@danielhanchen
danielhanchen deleted the fix-torchao-test branch September 1, 2026 01:28
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