Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

fix: warm up Triton CUDA driver before mocking device capability (#2253)

Sun, Xuehaoa97b91a24ffc
diff --git a/test/conftest.py b/test/conftest.py
index 34aa6d90a..006079a3b 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -71,6 +71,44 @@ def pytest_unconfigure(config):
os.environ.update(config.stash[backup_env])
[email protected](scope="session", autouse=True)
+def _warmup_triton_cuda_driver():
+ """Force Triton's CUDA driver singleton to snapshot the *real* device capability.
+
+ Triton's ``GPUDriver.__init__`` (triton/backends/driver.py) does::
+
+ self.get_device_capability = torch.cuda.get_device_capability
+
+ This copies the function object once, when the process-wide
+ ``triton.runtime.driver.active`` singleton is first constructed. If that
+ first construction happens to occur while some test has patched
+ ``torch.cuda.get_device_capability`` (e.g. ``mock_fp8_capable_device``
+ faking an FP8-capable device), the mocked return value gets baked in
+ *permanently* for the rest of the process -- unaffected by the patch
+ being un-applied later. Every subsequent Triton kernel is then compiled
+ for that fake architecture, causing
+ ``RuntimeError: Triton Error [CUDA]: no kernel image is available for
+ execution on the device`` on the *real* hardware regardless of its actual
+ compute capability (reproduced on both sm80 and sm120).
+ See https://github.com/intel/auto-round/issues/2048.
+
+ Triggering the singleton construction here -- as an autouse, session
+ scoped fixture that pytest always instantiates before any function scoped
+ fixture -- guarantees it captures the real capability before any test
+ gets a chance to mock it.
+ """
+ try:
+ import torch
+
+ if not torch.cuda.is_available():
+ return
+ import triton
+
+ triton.runtime.driver.active.get_current_target()
+ except Exception:
+ pass
+
+
@pytest.fixture(autouse=True)
def disable_torch_compile_by_default(request, monkeypatch):
"""Use a no-op torch.compile by default to reduce test overhead and flakiness.
diff --git a/test/unit/test_cuda/models/test_fp8_model.py b/test/unit/test_cuda/models/test_fp8_model.py
index a21b51b36..8829f77ad 100644
--- a/test/unit/test_cuda/models/test_fp8_model.py
+++ b/test/unit/test_cuda/models/test_fp8_model.py
@@ -72,7 +72,6 @@ class TestAutoRound:
model = convert_module_to_hp_if_necessary(model)
assert type(model.model.layers[0].mlp.up_proj) is torch.nn.Linear, "FP8Linear layer was not converted to Linear"
- @pytest.mark.skip_ci(reason="triton issue") # https://github.com/intel/auto-round/issues/2048
def test_small_model_rtn_generation(self, mock_fp8_capable_device, tiny_fp8_qwen_model_path):
ar = AutoRound(tiny_fp8_qwen_model_path, iters=0, disable_opt_rtn=True)
_, quantized_model_path = ar.quantize_and_save(output_dir=self.save_dir)