Skip to content

Tests: run the MXFP4 operand device guard check on CPU-only torch too - #16088

Merged
danielhanchen merged 1 commit into
mainfrom
tests-mxfp4-guard-needs-cuda-build
Oct 30, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
tests-mxfp4-guard-needs-cuda-build

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU, rest-2) is red on main since #16062 (MXFP4 torch decode fallback: run ldexp on the operands' GPU). It fails on unrelated PRs such as #16085 and #16074:

tests/test_mxfp4_compressed_linear.py::test_torch_fallback_runs_ldexp_on_the_operands_gpu[dtype0..2]
unsloth/models/mxfp4_compressed_linear.py:99: in _dequantize_torch_impl
    out[..., 0::2] = lut[(blocks & 0x0F).long()]
RuntimeError: PyTorch is not linked with support for cuda devices

The test builds its operands on cuda:1 inside FakeTensorMode. That works on any CUDA-linked torch, with or without a GPU, but a CPU-only build cannot dispatch a fake CUDA tensor. The CPU shards install CPU-only torch. I checked the same few lines on both builds: 2.13.0+cu130 with no visible GPU runs them, and 2.10.0+cpu raises the error above. The product's device guard is fine; the test assumed a CUDA build.

Changes

  • test_torch_fallback_runs_ldexp_on_the_operands_gpu now skips when torch.backends.cuda.is_built() is false. It still runs on CUDA builds, GPU or not.
  • New test_the_torch_decode_runs_inside_its_operands_device_guard runs on any build, so the CPU shards keep covering the guard. It checks three things: _dequantize_torch decodes with the operand's device current, puts the previous device back, and leaves the current device alone for a CPU operand or an index-less cuda operand.
  • The fake torch.cuda.device guard is shared by both tests.

Verification

  • CPU-only torch 2.10: the file has 20 passed and 38 skipped, and the fake-tensor test skips with the reason above. On main it had 3 failures.
  • CUDA torch 2.13 with no visible GPU: the three fake-tensor cases and the new test pass (4 passed).
  • Sabotage: dropping _operand_device_guard from _dequantize_torch fails the new test on CPU-only torch.

#16062's fake-tensor test places tensors on cuda:1 under FakeTensorMode, which a CPU-only
torch build refuses (PyTorch is not linked with support for cuda devices), so the CPU rest-2
shard is red. Skip it there, and add a test of the guard itself that runs on any build.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-10-30T08:54:27.616656Z 1bc539b 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 1bc539bb31

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

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