Skip to content

Give the ROCm bf16 chain test every name _gpu_init imports from device_type - #11688

Merged
danielhanchen merged 2 commits into
mainfrom
fix/rocm-bf16-chain-namespace
Sep 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/rocm-bf16-chain-namespace

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

tests/python/test_rocm_bf16_capability.py fails on main (e776f1c80) in Repo tests (CPU, studio). For example, #11679's staging run:

FAILED tests/python/test_rocm_bf16_capability.py::test_patched_probe_accepts_every_call_form[...] - NameError: name 'arch_lacks_buffer_ops' is not defined

Locally on main this gives 18 failed and 26 passed, all 18 with that NameError.

Cause

The test execs the block of unsloth/_gpu_init.py from if DEVICE_TYPE == "cuda" and not torch.cuda.is_available(): up to # For Gradio HF Spaces?, in a namespace it builds by hand. #11615 added its RDNA1 workaround inside that block:

if DEVICE_TYPE == "hip" and any(arch_lacks_buffer_ops(arch) for arch in hip_visible_archs()):
    apply_gfx101x_triton_workaround()

The hand-built namespace had arch_lacks_bf16 and hip_visible_archs but not the two names #11615 imports. The product is right and the test's namespace was out of date.

Change

  • Namespace: the test now fills it from _gpu_init.py's own from .device_type import (...), read with ast. A name the block starts using reaches the test without a hand edit.
  • Workaround stubbed: apply_gfx101x_triton_workaround is recorded, not run. The real one writes AMDGCN_USE_BUFFER_OPS, TRITON_CACHE_DIR and TORCHINDUCTOR_CACHE_DIR into os.environ, which would leak into the rest of the worker.
  • New test for AMD RDNA1: turn Triton's buffer ops off on gfx101x before Triton loads #11615's gate: test_the_chain_turns_triton_buffer_ops_off_only_for_a_visible_gfx101x. It applies the workaround on gfx1010, and on a mixed host with gfx1012:xnack-. It does not apply it on gfx1030 (RDNA2), on gfx1100, or off hip.

Verification

…e_type

#11615 added the RDNA1 buffer-op workaround inside the _gpu_init.py block
this test execs, and it calls arch_lacks_buffer_ops, which the test's
hand-built namespace did not have: every hip case failed with a NameError
on main. The namespace is now read from _gpu_init's own
`from .device_type import (...)`, so the next name arrives by itself.

apply_gfx101x_triton_workaround is recorded rather than run, since the real
one writes Triton and Inductor settings into os.environ, and a new test
covers #11615's gate: gfx101x only, RDNA2 excluded, off hip nothing.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 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-09-23T15:09:10.592191Z 97ba83b 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 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: 0663135001

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

def _namespace(fake_torch, device_type, workarounds):
import unsloth.device_type as dt

namespace = {name: getattr(dt, name) for name in _device_type_imports()}

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 Support the fallback device-type stub

When tests/conftest.py cannot preload the real unsloth.device_type, its documented fallback installs a stub exposing arch_lacks_bf16 and hip_visible_archs, but not arch_lacks_buffer_ops or apply_gfx101x_triton_workaround. This comprehension calls getattr for both missing names before the workaround can be replaced, so every _run_chain case raises AttributeError in that supported CPU-test path. Extend the fallback stub or provide these overrides before performing the lookup.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 97ba83b, at both ends. The conftest stub now carries arch_lacks_buffer_ops (gfx101x only), apply_gfx101x_triton_workaround and gfx101x_triton_workaround_applied, and the namespace applies its overrides first, so it only looks up the names it does not replace. A new test reads _install_device_type_stub with ast and fails if it lacks any name _gpu_init.py imports from .device_type; dropping arch_lacks_buffer_ops from the stub fails it. (Separately, import unsloth under that stub already stops earlier, on get_device_stats, which predates this PR.)

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 97ba83b766

ℹ️ 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 ebf2f2a into main Sep 23, 2026
0 of 21 checks passed
@danielhanchen
danielhanchen deleted the fix/rocm-bf16-chain-namespace branch September 23, 2026 15:12
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…e_type (unslothai#11688)

* Give the ROCm bf16 chain test every name _gpu_init imports from device_type

unslothai#11615 added the RDNA1 buffer-op workaround inside the _gpu_init.py block
this test execs, and it calls arch_lacks_buffer_ops, which the test's
hand-built namespace did not have: every hip case failed with a NameError
on main. The namespace is now read from _gpu_init's own
`from .device_type import (...)`, so the next name arrives by itself.

apply_gfx101x_triton_workaround is recorded rather than run, since the real
one writes Triton and Inductor settings into os.environ, and a new test
covers unslothai#11615's gate: gfx101x only, RDNA2 excluded, off hip nothing.

* Give the conftest device_type stub unslothai#11615's names, and pin it to _gpu_init's imports
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