Skip to content

test: fix collection errors and gate CUDA-only kernels on ROCm - #3772

Merged
Qubitium merged 3 commits into
mainfrom
fix/mimo-writer-out-of-model-test
Nov 11, 2026
Merged

Qubitium merged 3 commits into
mainfrom
fix/mimo-writer-out-of-model-test

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes three test-only defects found while running the full suite on the current main tree.

1. Mimo writer test used a removed symbol

tests/test_mimo_mixed_source.py imported _merge_prefix_tensors_into_state_dict, which was removed in #3602, so pytest --collect-only failed with:

ImportError: cannot import name '_merge_prefix_tensors_into_state_dict' from 'gptqmodel.models.writer'

The same test unpacked _normalize_out_of_model_tensors_entries as two lists, while the current API returns four selector lists (files, prefixes, suffixes, tensor_names).

Fix: use the current successor _merge_selected_tensors_into_state_dict, unpack all four selector lists, and keep the test intent unchanged: absent MTP auxiliary tensors remain optional and leave the state dict empty.

2. Optional server dependencies were not gated

tests/test_openai_server.py and tests/test_openai_server_contract.py imported openai / fastapi at module scope, so collection failed when those optional packages were absent:

  • ModuleNotFoundError: No module named 'openai'
  • ModuleNotFoundError: No module named 'fastapi'

Fix: pytest.importorskip(...) at module scope. The modules now report as skipped instead of aborting collection.

3. CUDA-only kernels were not gated by device family on ROCm

tests/kernels/test_gptq.py::_maybe_skip_backend only special-cased BitBLAS / Machete / Swordfish / ExLlamaV2. TRITON and MARLIN therefore ran on ROCm, where the kernels correctly refuse:

  • TritonV2Linear is CUDA-only and does not run on ROCm (SUPPORTS_DEVICES = [DEVICE.CUDA])
  • Marlin kernel is not supported on ROCm.

The same pattern broke tests/kernels/test_qlinear_hierarchy.py::test_grouped_nonpacked_kernels_do_not_store_packed_runtime_state: its dummy BitBLAS install stubbed the operator but not cached_validate_once(), so construction raised NotImplementedError: BitBLAS ... is CUDA-only on ROCm.

Fix: ask the kernel instead of torch.cuda.is_available() (HIP reuses torch's cuda namespace, so that check is also true on ROCm). _maybe_skip_backend now checks every backend's SUPPORTS_DEVICES family declaration, validate_device() rules and validate_once() availability, so a kernel added later is gated without editing the test. The dummy BitBLAS install now also stubs cached_validate_once(), matching the dummy operator it already installs.

Verification

On the rebased tree:

  • pytest --collect-only -q: 14999 tests collected, 0 errors (previously 2 collection errors).
  • CUDA host, tests/kernels/test_gptq.py: 17 passed, 8 skipped, 0 failed.
  • ROCm host, tests/kernels/test_gptq.py -k "triton or marlin": 8 skipped, 0 failed (these were the 8 failures).
  • ROCm host, tests/kernels/test_qlinear_hierarchy.py: 9 passed (previously 1 failed).
  • ruff check on all four changed files: pass.

No open PR fixes these collection or ROCm test-gating failures. The earlier fix/rocm-test-gates branch targets an older tree and is not merged; this change rewrites only the parts still needed on current main.

Notes

No production kernel behavior changes: the kernels already rejected unsupported devices correctly; only the tests were wrong.

_merge_prefix_tensors_into_state_dict was removed in #3602, and
_normalize_out_of_model_tensors_entries now returns four selector
lists. Update the MTP absent-auxiliary test to the current
_merge_selected_tensors_into_state_dict API so collection no longer
fails.
Optional server dependencies and CUDA-only kernels must not break collection or fail on ROCm:

- Skip test_openai_server.py and test_openai_server_contract.py at module
  scope when openai / fastapi are not installed, instead of raising during
  collection.
- Gate every backend in test_gptq.py through the kernel's own
  SUPPORTS_DEVICES family declaration, validate_device() rules and
  validate_once() availability. TRITON, MARLIN, MACHETE, SWORDFISH and
  EXLLAMA_V2 now skip on ROCm instead of failing while loading.
- Stub cached_validate_once() alongside the dummy BitBLAS operator in
  test_qlinear_hierarchy.py so the runtime-state assertions do not require
  a CUDA BitBLAS install.
@ZX-ModelCloud
ZX-ModelCloud force-pushed the fix/mimo-writer-out-of-model-test branch from 9e3844e to 5572929 Compare November 11, 2026 12:04
@ZX-ModelCloud ZX-ModelCloud changed the title test(mimo): use current writer out-of-model selector API test: fix collection errors and gate CUDA-only kernels on ROCm Nov 11, 2026
test_openai_server_contract.py imported httpx at module scope, so a server
environment without the optional httpx package still failed collection after
fastapi and starlette were gated. Skip the module when httpx is absent.

_kernel_skip_reason() assumed validate_once() always returns (ok, error).
TritonV2Linear raises ImportError when its optional runtime is missing, which
turned the new gate into a test error instead of a skip. Treat a raising probe
as an unavailable kernel, and cover the family mismatch, device rejection,
unavailable and raising paths with a host-independent unit test.
@ZX-ModelCloud
ZX-ModelCloud marked this pull request as ready for review November 11, 2026 12:28

@ZX-ModelCloud ZX-ModelCloud left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed the branch on both accelerator families and fixed two remaining blockers in 403e662ce:

  • tests/test_openai_server_contract.py still imported httpx at module scope, so the module failed collection whenever the optional httpx package was absent — the same failure this PR set out to remove. It is now gated with pytest.importorskip.
  • _kernel_skip_reason() assumed validate_once() always returns (ok, error), but TritonV2Linear.validate_once() raises when Triton is missing, turning the new gate into a test error instead of a skip. A raising probe now counts as an unavailable kernel, and the helper has a host-independent unit test for the family-mismatch, device-rejection, unavailable and raising paths.

Verified after the fixes, with the branch merged onto current main:

  • CUDA: tests/kernels/test_gptq.py 18 passed / 8 skipped / 0 failed; test_qlinear_hierarchy.py, test_mimo_mixed_source.py and the server modules 60 passed / 2 skipped; --collect-only 15032 tests, 0 errors.
  • ROCm: tests/kernels/test_gptq.py + test_qlinear_hierarchy.py 15 passed / 20 skipped / 0 failed; --collect-only 14983 tests, with only unrelated einops / peft modules still erroring.
  • ruff check on the changed files: pass.

The kernel-declaration approach (SUPPORTS_DEVICES + validate_device() + validate_once()) is the right replacement for torch.cuda.is_available().

@Qubitium
Qubitium merged commit 042531e into main Nov 11, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/mimo-writer-out-of-model-test branch November 11, 2026 14:29
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.

2 participants