Skip to content

Commit f3704ee

Browse files
committed
fix(tests): keep extension failures out of hardware skips
1 parent 4838083 commit f3704ee

2 files changed

Lines changed: 110 additions & 19 deletions

File tree

‎tests/kernels/test_asymmetric_real_models.py‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from gptqmodel.nn_modules.qlinear.marlin_awq import AwqMarlinLinear
1818
from gptqmodel.nn_modules.qlinear.torch import TorchLinear
1919
from gptqmodel.nn_modules.qlinear.torch_awq import AwqTorchLinear
20-
from gptqmodel.utils.machete import machete_runtime_error
21-
from gptqmodel.utils.marlin import marlin_runtime_error
2220
from tests.models.model_test import ModelTest
2321

2422

@@ -106,29 +104,20 @@ class _RealModelCase:
106104
)
107105

108106

109-
_CANDIDATE_BACKEND_GATES = {
110-
# Machete is Hopper-only (SM90, >=204800 bytes opt-in shared memory), so an
111-
# Ada (SM89) or Blackwell host has CUDA but cannot run it. Marlin is
112-
# CUDA-only, and ROCm reports `torch.cuda.is_available()` as True.
113-
BACKEND.MACHETE: lambda: machete_runtime_error(_DEVICE),
114-
BACKEND.MARLIN: lambda: marlin_runtime_error(_DTYPE),
115-
}
116-
117-
118107
def _require_candidate_backend(case: _RealModelCase) -> None:
119-
"""Skip candidates whose own runtime gate rejects this host.
108+
"""Skip unsupported hardware without hiding extension build failures.
120109
121110
``torch.cuda.is_available()`` is not sufficient: it is true on ROCm, and
122111
true on CUDA hosts whose compute capability the kernel does not target.
123-
Ask the kernel's own gate instead of re-deriving those checks here.
112+
Use the candidate's device-only validation for the exact target GPU. Runtime
113+
availability checks also compile/load extensions; their failures must reach
114+
the test through model loading instead of being converted to skips.
124115
"""
125116

126-
gate = _CANDIDATE_BACKEND_GATES.get(case.candidate_backend)
127-
if gate is None:
128-
return
129-
error = gate()
130-
if error:
131-
pytest.skip(error)
117+
try:
118+
case.candidate_cls.validate_device(_DEVICE)
119+
except NotImplementedError as exc:
120+
pytest.skip(str(exc))
132121

133122

134123
def _module_device(module: torch.nn.Module) -> torch.device:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SPDX-FileCopyrightText: 2026 ModelCloud.ai
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from importlib import import_module
5+
from types import SimpleNamespace
6+
7+
import pytest
8+
import torch
9+
10+
from gptqmodel import extension
11+
from tests.kernels import test_asymmetric_real_models as real_models
12+
13+
14+
_CASES = real_models._AWQ_REAL_CASES + real_models._GPTQ_REAL_CASES
15+
16+
17+
def _mock_device(monkeypatch, capability=(9, 0), shared_memory=227328, rocm=False):
18+
def get_capability(device=None):
19+
assert device == real_models._DEVICE
20+
return capability
21+
22+
monkeypatch.setattr(torch.cuda, "is_available", lambda: True)
23+
monkeypatch.setattr(torch.cuda, "get_device_capability", get_capability)
24+
monkeypatch.setattr(
25+
torch.cuda,
26+
"get_device_properties",
27+
lambda device=None: SimpleNamespace(
28+
name="test GPU",
29+
shared_memory_per_block=49152,
30+
shared_memory_per_block_optin=shared_memory,
31+
),
32+
)
33+
for module_name in (
34+
"gptqmodel.utils.machete",
35+
"gptqmodel.utils.marlin",
36+
*{case.candidate_cls.__module__ for case in _CASES},
37+
):
38+
monkeypatch.setattr(import_module(module_name), "IS_ROCM", rocm)
39+
40+
41+
@pytest.mark.parametrize("case", _CASES, ids=lambda case: case.name)
42+
@pytest.mark.parametrize(
43+
"capability,shared_memory,rocm,supported",
44+
[
45+
((9, 0), 227328, False, {case.name for case in _CASES}),
46+
((8, 9), 102400, False, {"awq_marlin"}),
47+
((10, 0), 227328, False, {"awq_marlin"}),
48+
((7, 5), 65536, False, set()),
49+
((9, 0), 102400, False, {"awq_marlin"}),
50+
((9, 0), 227328, True, set()),
51+
],
52+
ids=["hopper", "ada", "blackwell", "turing", "low_shared_memory", "rocm"],
53+
)
54+
def test_gate_checks_hardware_without_loading_extensions(
55+
monkeypatch,
56+
case,
57+
capability,
58+
shared_memory,
59+
rocm,
60+
supported,
61+
):
62+
_mock_device(monkeypatch, capability, shared_memory, rocm)
63+
64+
def unexpected_load(*args, **kwargs):
65+
pytest.fail("Hardware gating must not load or compile an extension")
66+
67+
monkeypatch.setattr(extension, "_load_one", unexpected_load)
68+
if case.name in supported:
69+
real_models._require_candidate_backend(case)
70+
else:
71+
with pytest.raises(pytest.skip.Exception):
72+
real_models._require_candidate_backend(case)
73+
74+
75+
@pytest.mark.parametrize("case", _CASES, ids=lambda case: case.name)
76+
def test_generation_propagates_extension_build_failure(monkeypatch, case):
77+
_mock_device(monkeypatch)
78+
message = "CUDA source compilation regression"
79+
80+
def failed_load(*args, **kwargs):
81+
raise RuntimeError(message)
82+
83+
monkeypatch.setattr(extension, "_load_one", failed_load)
84+
monkeypatch.setattr(extension, "error", lambda name: message)
85+
86+
def load_model(model_id, backend):
87+
if backend == case.baseline_backend:
88+
return object()
89+
extension_name = "marlin_fp16" if case.name == "awq_marlin" else "machete"
90+
return extension.op(extension_name, "unused")
91+
92+
monkeypatch.setattr(real_models, "_load_model", load_model)
93+
monkeypatch.setattr(real_models, "_generate_completion", lambda model: "baseline")
94+
monkeypatch.setattr(real_models, "_release_model", lambda model: None)
95+
96+
# Exercise the actual test entry point: a supported host must reach model
97+
# loading and report the build error, rather than skip before loading.
98+
with pytest.raises(RuntimeError, match=message):
99+
try:
100+
real_models.test_asymmetric_real_generation_matches_torch_and_is_sane(case)
101+
except pytest.skip.Exception as exc:
102+
pytest.fail(f"Build failure was hidden by a skip: {exc}")

0 commit comments

Comments
 (0)