Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Run the whole test suite without a GPU; clearer qualify errors (#131)

Idriss091792a5dd80acc
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 581ab26..dbdba88 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -32,6 +32,10 @@ pip install pytest
for t in tests/test_ablit_runtime_cpu.py tests/test_uncensor_bundled_cpu.py tools/glm/test_serve.py tools/mimo/test_serve.py tools/mimo/test_toolcalls.py; do PYTHONPATH=. pytest -q $t; done
```
+The whole `tests/` directory also runs without a GPU: `PYTHONPATH=. pytest tests`. Tests that need a GPU, the built extension (`import exllamav3` loads it) or Triton are skipped with the reason (`-rs` lists them); the needs are checked in `tests/hardware.py`. A new test that needs one of them takes `@pytest.mark.gpu`, `@pytest.mark.ext` or `@pytest.mark.triton`, or, when its file cannot even be imported without it, calls `require("ext")` from `hardware` before that import.
+
+On the GPU machine, run the suite with `EXL3_TESTS_STRICT=1`: nothing is skipped for missing hardware, so a broken build fails instead of skipping.
+
If a test or the first import hangs, look for a stale lock file at `~/.cache/torch_extensions/*/exllamav3_ext/lock` and remove it. GPU tests under `tests/` need a built extension and a free GPU; say in the pull request whether you ran them.
## Pull requests
diff --git a/tests/conftest.py b/tests/conftest.py
index 4f98a30..1d6468f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,6 +1,25 @@
+import os
+import sys
+
import pytest
import torch
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # tests/hardware.py, whatever the --import-mode
+import hardware # noqa: E402
+
+
+def pytest_configure(config):
+ for need, reason in hardware.REASONS.items():
+ config.addinivalue_line("markers", f"{need}: {reason}; skipped without it (tests/hardware.py, EXL3_TESTS_STRICT=1 runs it anyway)")
+
+
+def pytest_collection_modifyitems(config, items):
+ for need, reason in hardware.REASONS.items():
+ if hardware.missing(need):
+ for item in items:
+ if item.get_closest_marker(need):
+ item.add_marker(pytest.mark.skip(reason = reason))
+
@pytest.fixture(autouse = True)
def _restore_current_cuda_device():
diff --git a/tests/dsv41/test_dsv41_ablit.py b/tests/dsv41/test_dsv41_ablit.py
index c32b23a..a41133c 100644
--- a/tests/dsv41/test_dsv41_ablit.py
+++ b/tests/dsv41/test_dsv41_ablit.py
@@ -25,6 +25,8 @@ ROOT = os.path.dirname(os.path.dirname(HERE))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(ROOT, "tools", "ablit"))
sys.path.insert(0, os.path.join(ROOT, "tools", "ds41"))
+from hardware import require # noqa: E402
+require("ext")
from test_dsv41_serving import make_world, build_ref, build_serving, ids_of # noqa: E402
from exllamav3.modules import ablit_runtime # noqa: E402
import arch as A # noqa: E402
diff --git a/tests/dsv41/test_dsv41_calib.py b/tests/dsv41/test_dsv41_calib.py
index 5f41b2c..9c57376 100644
--- a/tests/dsv41/test_dsv41_calib.py
+++ b/tests/dsv41/test_dsv41_calib.py
@@ -11,6 +11,8 @@ import os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from harness import *
from test_dsv41_e2e import setup, build_mine
from exllamav3.dsv41 import ops, quant
diff --git a/tests/dsv41/test_dsv41_e2e.py b/tests/dsv41/test_dsv41_e2e.py
index 5eab93f..e761b17 100644
--- a/tests/dsv41/test_dsv41_e2e.py
+++ b/tests/dsv41/test_dsv41_e2e.py
@@ -10,6 +10,8 @@ import os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from harness import *
from exllamav3.dsv41.engram import build_compressed_token_map, EngramLayout, MemoryEngramStore
from exllamav3.dsv41.weights import DictWeightSource
diff --git a/tests/dsv41/test_dsv41_engram_io.py b/tests/dsv41/test_dsv41_engram_io.py
index c0694be..4b77c9c 100644
--- a/tests/dsv41/test_dsv41_engram_io.py
+++ b/tests/dsv41/test_dsv41_engram_io.py
@@ -4,6 +4,8 @@ import numpy as np
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.dsv41.engram import DirectRowReader
from exllamav3.modules.dsv41_fn.engram_io import ParallelRowReader, NativeRowReader
diff --git a/tests/dsv41/test_dsv41_engram_prefetch.py b/tests/dsv41/test_dsv41_engram_prefetch.py
index 1c3ddc7..b689bd2 100644
--- a/tests/dsv41/test_dsv41_engram_prefetch.py
+++ b/tests/dsv41/test_dsv41_engram_prefetch.py
@@ -4,6 +4,8 @@ import numpy as np
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.dsv41.engram import EngramLayout, NgramHasher, compute_multipliers, EngramRowStore
from exllamav3.modules.dsv41_fn.engram_prefetch import HostEngramHash, EngramPrefetcher
diff --git a/tests/dsv41/test_dsv41_engram_wkv_fp8.py b/tests/dsv41/test_dsv41_engram_wkv_fp8.py
index fd93739..9fecc3f 100644
--- a/tests/dsv41/test_dsv41_engram_wkv_fp8.py
+++ b/tests/dsv41/test_dsv41_engram_wkv_fp8.py
@@ -6,6 +6,8 @@ import torch
from safetensors.torch import save_file
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from hardware import require
+require("ext")
from exllamav3.loader import SafetensorsCollection
from exllamav3.modules import Linear
diff --git a/tests/dsv41/test_dsv41_framework.py b/tests/dsv41/test_dsv41_framework.py
index 9d48cf1..54753d6 100644
--- a/tests/dsv41/test_dsv41_framework.py
+++ b/tests/dsv41/test_dsv41_framework.py
@@ -12,6 +12,8 @@ import json, os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from tiny_ckpt import write_tiny, fw_config
from harness import *
from exllamav3.dsv41 import ops
diff --git a/tests/dsv41/test_dsv41_hip.py b/tests/dsv41/test_dsv41_hip.py
index 8f40f79..bc536de 100644
--- a/tests/dsv41/test_dsv41_hip.py
+++ b/tests/dsv41/test_dsv41_hip.py
@@ -16,6 +16,8 @@ import numpy as np
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from harness import *
from test_dsv41_e2e import setup, build_mine
from exllamav3.dsv41 import ops, quant
diff --git a/tests/dsv41/test_dsv41_hipk.py b/tests/dsv41/test_dsv41_hipk.py
index a32e76f..7ec73bb 100644
--- a/tests/dsv41/test_dsv41_hipk.py
+++ b/tests/dsv41/test_dsv41_hipk.py
@@ -18,6 +18,8 @@ import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from exllamav3.dsv41 import ops, quant
from exllamav3.dsv41.engram import (EngramLayout, NgramHasher, MemoryEngramStore, dequant_rows, engram_inject)
diff --git a/tests/dsv41/test_dsv41_idx_score.py b/tests/dsv41/test_dsv41_idx_score.py
index fa07310..4ad4575 100644
--- a/tests/dsv41/test_dsv41_idx_score.py
+++ b/tests/dsv41/test_dsv41_idx_score.py
@@ -1,5 +1,7 @@
"""GPU check of the indexer scoring kernels against the torch reference (dense scan and candidate slots)."""
import pytest, torch
+from hardware import require
+require("ext")
from exllamav3.dsv41 import quant
pytestmark = pytest.mark.skipif(not torch.cuda.is_available(), reason="needs a GPU")
diff --git a/tests/dsv41/test_dsv41_loaders.py b/tests/dsv41/test_dsv41_loaders.py
index 879d4b9..2a51368 100644
--- a/tests/dsv41/test_dsv41_loaders.py
+++ b/tests/dsv41/test_dsv41_loaders.py
@@ -10,6 +10,8 @@ import numpy as np
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from harness import *
from gguf_writer import *
from test_dsv41_e2e import setup, build_mine, install_hooks, cmp_taps, TOL
diff --git a/tests/dsv41/test_dsv41_num.py b/tests/dsv41/test_dsv41_num.py
index 256de95..2dab513 100644
--- a/tests/dsv41/test_dsv41_num.py
+++ b/tests/dsv41/test_dsv41_num.py
@@ -8,6 +8,8 @@ import numpy as np
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.dsv41 import quant
from exllamav3.dsv41.engram import (EngramLayout, NgramHasher, compute_multipliers, dequant_rows)
diff --git a/tests/dsv41/test_dsv41_ops.py b/tests/dsv41/test_dsv41_ops.py
index c797b1a..ac00684 100644
--- a/tests/dsv41/test_dsv41_ops.py
+++ b/tests/dsv41/test_dsv41_ops.py
@@ -6,6 +6,8 @@ import numpy as np
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from harness import *
from harness import _fp8_block_quant, _fp4_row_quant
from exllamav3.dsv41 import ops, quant
diff --git a/tests/dsv41/test_dsv41_packwire.py b/tests/dsv41/test_dsv41_packwire.py
index aadcff0..4356664 100644
--- a/tests/dsv41/test_dsv41_packwire.py
+++ b/tests/dsv41/test_dsv41_packwire.py
@@ -23,6 +23,8 @@ ROOT = os.path.dirname(os.path.dirname(HERE))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(ROOT, "tools", "ds41"))
+from hardware import require # noqa: E402
+require("ext")
import tiny_ckpt # noqa: E402
from exllamav3.dsv41 import packspec as PS # noqa: E402
from exllamav3.dsv41.engram import MemoryEngramStore # noqa: E402
diff --git a/tests/dsv41/test_dsv41_real_headers.py b/tests/dsv41/test_dsv41_real_headers.py
index bf782ed..2fa86b6 100644
--- a/tests/dsv41/test_dsv41_real_headers.py
+++ b/tests/dsv41/test_dsv41_real_headers.py
@@ -7,6 +7,8 @@ import glob, json, os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from hardware import require
+require("ext")
from exllamav3.dsv41.config import DSV41Config
from exllamav3.dsv41.weights import WeightSource
from exllamav3.dsv41.linear import DenseLin
diff --git a/tests/dsv41/test_dsv41_real_slices.py b/tests/dsv41/test_dsv41_real_slices.py
index c9ef930..d26d3d1 100644
--- a/tests/dsv41/test_dsv41_real_slices.py
+++ b/tests/dsv41/test_dsv41_real_slices.py
@@ -8,6 +8,8 @@ import json, os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from hardware import require
+require("ext")
from exllamav3.dsv41 import quant, gguf as G
R = os.environ.get("DSV41_REAL_DIR", "./ds41_work/ds41port/scratch/real")
diff --git a/tests/dsv41/test_dsv41_serving.py b/tests/dsv41/test_dsv41_serving.py
index b181938..5fcf4f1 100644
--- a/tests/dsv41/test_dsv41_serving.py
+++ b/tests/dsv41/test_dsv41_serving.py
@@ -19,6 +19,8 @@ import torch
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(HERE)), "tools", "ds41"))
+from hardware import require
+require("ext")
import harness
from harness import FakeTok, make_state_dict, make_engram_tables, tiny_config
from exllamav3.dsv41.config import DSV41Config
diff --git a/tests/dsv41/test_dsv41_serving_spec.py b/tests/dsv41/test_dsv41_serving_spec.py
index 3515fe8..b507645 100644
--- a/tests/dsv41/test_dsv41_serving_spec.py
+++ b/tests/dsv41/test_dsv41_serving_spec.py
@@ -16,6 +16,8 @@ import torch
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(HERE)), "tools", "ds41"))
+from hardware import require
+require("ext")
import test_dsv41_serving as S
import test_dsv41_spec as T
import dspark as ctl
diff --git a/tests/dsv41/test_dsv41_spec.py b/tests/dsv41/test_dsv41_spec.py
index 31123bf..b992ce4 100644
--- a/tests/dsv41/test_dsv41_spec.py
+++ b/tests/dsv41/test_dsv41_spec.py
@@ -19,6 +19,8 @@ import torch
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(HERE)), "tools", "ds41"))
+from hardware import require
+require("ext")
import harness
from harness import FakeTok, make_state_dict, make_engram_tables, tiny_config
from test_dsv41_e2e import build_mine
diff --git a/tests/dsv41/test_dsv41_spec_real.py b/tests/dsv41/test_dsv41_spec_real.py
index de20f9d..7063480 100644
--- a/tests/dsv41/test_dsv41_spec_real.py
+++ b/tests/dsv41/test_dsv41_spec_real.py
@@ -15,6 +15,8 @@ import torch
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(HERE)), "tools", "ds41"))
+from hardware import require
+require("ext")
from exllamav3.dsv41.config import DSV41Config
from exllamav3.dsv41.safetensors_io import SafetensorsWeightSource
from exllamav3.dsv41.experts import SourceExpertProvider
diff --git a/tests/dsv41/test_dsv41_stream.py b/tests/dsv41/test_dsv41_stream.py
index 479b477..d7593f6 100644
--- a/tests/dsv41/test_dsv41_stream.py
+++ b/tests/dsv41/test_dsv41_stream.py
@@ -7,6 +7,8 @@ import os, sys
import pytest
import torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+from hardware import require
+require("ext")
from tiny_ckpt import write_tiny
from harness import *
from exllamav3.dsv41.weights import DictWeightSource
diff --git a/tests/dsv41/test_dsv41_vision_model.py b/tests/dsv41/test_dsv41_vision_model.py
index 9087fc4..a7e2860 100644
--- a/tests/dsv41/test_dsv41_vision_model.py
+++ b/tests/dsv41/test_dsv41_vision_model.py
@@ -18,6 +18,8 @@ from PIL import Image
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
from pathlib import Path
+from hardware import require
+require("ext")
import harness
from harness import FakeTok, build_reference, make_engram_tables, make_state_dict, tiny_config
from exllamav3.dsv41 import vision as V
diff --git a/tests/hardware.py b/tests/hardware.py
new file mode 100644
index 0000000..6c723e1
--- /dev/null
+++ b/tests/hardware.py
@@ -0,0 +1,62 @@
+"""What this machine can run the tests on, so that a test needing a GPU or the built extension skips instead of failing.
+
+Three needs:
+ gpu a CUDA or ROCm device (torch.cuda.is_available())
+ ext `import exllamav3` works: it loads the native extension at import time, so it needs the extension built by
+ ./build.sh (or a GPU to JIT-build it) and Triton
+ triton Triton alone (CPU tests that stub the extension but import modules that import Triton)
+
+Test functions take the marks (@pytest.mark.gpu, .ext, .triton; tests/conftest.py skips them). A file that cannot even be
+imported without them calls require("ext") or require("gpu", "ext") before the import that needs it.
+
+EXL3_TESTS_STRICT=1 turns every such skip off: on the GPU machine, a broken build or a hidden device then fails the tests
+instead of skipping them silently."""
+from __future__ import annotations
+
+import importlib.machinery
+import importlib.util
+import os
+import sys
+
+import torch
+
+STRICT = os.environ.get("EXL3_TESTS_STRICT") == "1"
+
+
+def has_gpu() -> bool:
+ return torch.cuda.is_available()
+
+
+def has_ext() -> bool:
+ """Never imports exllamav3.ext itself: without a prebuilt extension that starts a JIT build (and takes its lock).
+ Already in sys.modules (loaded, or a test's stub while it imports): the import goes through."""
+ if "exllamav3.ext" in sys.modules:
+ return True
+ spec = importlib.util.find_spec("exllamav3_ext")
+ prebuilt = bool(spec and spec.origin and spec.origin.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)))
+ return (prebuilt or has_gpu()) and has_triton()
+
+
+def has_triton() -> bool:
+ return importlib.util.find_spec("triton") is not None
+
+
+CHECKS = {"gpu": has_gpu, "ext": has_ext, "triton": has_triton}
+REASONS = {"gpu": "needs a GPU", "ext": "needs the built extension (./build.sh) and Triton", "triton": "needs Triton"}
+
+
+def missing(need: str) -> bool:
+ return not STRICT and not CHECKS[need]()
+
+
+def require(*needs: str) -> None:
+ """Skip the whole file when one of `needs` is missing. Call it before the import that needs it. Without pytest (a test
+ file run as a script in a venv that has none) it does nothing, and the import fails as it did before."""
+ try:
+ import pytest
+ except ImportError:
+ return
+ caller = os.path.basename(sys._getframe(1).f_code.co_filename) # -rs reports this file's line, not the caller's
+ for need in needs:
+ if missing(need):
+ pytest.skip(f"{caller}: {REASONS[need]}", allow_module_level = True)
diff --git a/tests/port/test_attn16.py b/tests/port/test_attn16.py
index 6038ebc..12253a6 100644
--- a/tests/port/test_attn16.py
+++ b/tests/port/test_attn16.py
@@ -19,6 +19,9 @@ except ImportError: # the CUDA venv has no pytest: __main__ runs the same grid
if pytest is not None:
pytestmark = pytest.mark.skipif(not torch.cuda.is_available() or bool(torch.version.hip), reason = "CUDA only")
+if pytest is not None and __name__ != "__main__": # collected by pytest (tests/hardware.py is on the path then)
+ from hardware import require
+ require("gpu", "ext")
from exllamav3.constants import PAGE_SIZE
from exllamav3.modules.attention_fn import triton_paged as tp
diff --git a/tests/test_attn_optimizer_targets.py b/tests/test_attn_optimizer_targets.py
index 4d9f6d0..4eb9e52 100644
--- a/tests/test_attn_optimizer_targets.py
+++ b/tests/test_attn_optimizer_targets.py
@@ -1,5 +1,7 @@
import os, sys, unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.modules.attn import Attention
class FakeLinear:
diff --git a/tests/test_bc_recurrent_graph_geometry_.py b/tests/test_bc_recurrent_graph_geometry_.py
index a0aa9f9..ff96885 100644
--- a/tests/test_bc_recurrent_graph_geometry_.py
+++ b/tests/test_bc_recurrent_graph_geometry_.py
@@ -11,6 +11,8 @@ qwen3.5-0.8b quant (GatedDeltaNet). For BC_Mamba2 point it at a NemotronH quant.
import sys, os, gc
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3 import Config, Model, Cache, Tokenizer, Generator, Job, ArgmaxSampler
from exllamav3.modules.block_sparse_mlp import BlockSparseMLP
diff --git a/tests/test_bc_shared_expert_graph_.py b/tests/test_bc_shared_expert_graph_.py
index bfed09d..fb7ea2d 100644
--- a/tests/test_bc_shared_expert_graph_.py
+++ b/tests/test_bc_shared_expert_graph_.py
@@ -11,6 +11,8 @@ keeps the default. Decode logits are checked against the plain forward, teacher-
import sys, os, gc
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3 import Config, Model, Cache, Tokenizer, Generator, Job, ArgmaxSampler
from exllamav3.modules.block_sparse_mlp import BlockSparseMLP
diff --git a/tests/test_block_ldl_threads.py b/tests/test_block_ldl_threads.py
index 3959b84..40d6f75 100644
--- a/tests/test_block_ldl_threads.py
+++ b/tests/test_block_ldl_threads.py
@@ -2,6 +2,8 @@
worker: no spurious Cholesky failure, no silently wrong factor. Needs a GPU (take gpu-lease on shared boxes).
Run: PYTHONPATH=$PWD python tests/test_block_ldl_threads.py"""
import threading, torch
+from hardware import require
+require("ext")
from exllamav3.modules.quant.exl3_lib import quantize as q
N, B = 1024, 16
diff --git a/tests/test_cache_rotate.py b/tests/test_cache_rotate.py
index 40203fc..33dcc24 100644
--- a/tests/test_cache_rotate.py
+++ b/tests/test_cache_rotate.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
from itertools import pairwise
diff --git a/tests/test_capture_h_batched.py b/tests/test_capture_h_batched.py
index 08bc6cd..1396e71 100644
--- a/tests/test_capture_h_batched.py
+++ b/tests/test_capture_h_batched.py
@@ -17,6 +17,8 @@ import numpy as np
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.modules import linear as lin
diff --git a/tests/test_cpu_cache.py b/tests/test_cpu_cache.py
index b3c7662..975e163 100644
--- a/tests/test_cpu_cache.py
+++ b/tests/test_cpu_cache.py
@@ -3,6 +3,8 @@ import torch
from collections import namedtuple
from types import SimpleNamespace
+from hardware import require
+require("ext")
from exllamav3.generator.cpu_cache import CPUPageCache
# The eviction policy is plain host-side bookkeeping over the slot table, so it can be driven directly with a
diff --git a/tests/test_cpu_cache_tp.py b/tests/test_cpu_cache_tp.py
index b488367..5ff33c9 100644
--- a/tests/test_cpu_cache_tp.py
+++ b/tests/test_cpu_cache_tp.py
@@ -3,6 +3,8 @@ import torch
from collections import namedtuple
from types import SimpleNamespace
+from hardware import require
+require("ext")
from exllamav3.generator.cpu_cache import CPUPageCache
from exllamav3.model.model_tp_fn import (
mp_cpu_cache_init,
diff --git a/tests/test_dec_router_ragged_e.py b/tests/test_dec_router_ragged_e.py
index 23783fd..dbd67dc 100644
--- a/tests/test_dec_router_ragged_e.py
+++ b/tests/test_dec_router_ragged_e.py
@@ -2,6 +2,8 @@
torch reference of routing_dots (fp16 logits, sigmoid, + fp32 bias, top-k, renormalize, scale)
and as the generic torch path (_routing_nogroup_torch) it replaces. Run: python tests/test_dec_router_ragged_e.py"""
import sys, torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext # noqa
from exllamav3.modules.quant.exl3 import dec_workspace
from exllamav3.modules.block_sparse_mlp_routing import _routing_nogroup_torch
diff --git a/tests/test_dense_tune_seed.py b/tests/test_dense_tune_seed.py
index 4918a6d..b2f28f1 100644
--- a/tests/test_dense_tune_seed.py
+++ b/tests/test_dense_tune_seed.py
@@ -1,5 +1,7 @@
import os, sys, tempfile, unittest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
+from hardware import require
+require("ext")
from exllamav3.model.dense_warmup import seed_dense_tune
diff --git a/tests/test_device_copy_.py b/tests/test_device_copy_.py
index e8768b7..afa2632 100644
--- a/tests/test_device_copy_.py
+++ b/tests/test_device_copy_.py
@@ -7,6 +7,8 @@ Needs two CUDA devices; the P2P failure is simulated by patching the probe.
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.util import device_copy as dc
from exllamav3.util.device_copy import to_device
diff --git a/tests/test_disk_store_cpu.py b/tests/test_disk_store_cpu.py
index 7bdee02..97c3501 100644
--- a/tests/test_disk_store_cpu.py
+++ b/tests/test_disk_store_cpu.py
@@ -4,6 +4,8 @@ import time
import torch
+from hardware import require
+require("ext")
from exllamav3.util import disk_store as ds
diff --git a/tests/test_draft_head_blocks_.py b/tests/test_draft_head_blocks_.py
index 1de1470..2dd7846 100644
--- a/tests/test_draft_head_blocks_.py
+++ b/tests/test_draft_head_blocks_.py
@@ -7,6 +7,8 @@ try:
except ImportError: # plain-python run (the serving venv ships no pytest)
pytest = None
import torch
+from hardware import require
+require("ext")
from exllamav3.architecture.qwen3_5_mtp import exl3_block_subhead
from exllamav3.modules.quant.exl3 import LinearEXL3
diff --git a/tests/test_ds41_k1_cpu.py b/tests/test_ds41_k1_cpu.py
index b2f4dff..df7f591 100644
--- a/tests/test_ds41_k1_cpu.py
+++ b/tests/test_ds41_k1_cpu.py
@@ -19,18 +19,41 @@ from unittest import mock
import pytest
import torch
-# CPU only: never JIT-build the native extension (it needs the build lock and a GPU toolchain)
-if os.environ.get("EXL3_REAL_EXT") != "1" and "exllamav3.ext" not in sys.modules:
+from hardware import require
+require("triton")
+
+# CPU only: never JIT-build the native extension (it needs the build lock and a GPU toolchain). The stub and every
+# exllamav3 module imported over it leave sys.modules after the imports, or the test files collected later would get
+# them, and come back while this file's tests run (_stubbed_exllamav3)
+_stubbed = os.environ.get("EXL3_REAL_EXT") != "1" and "exllamav3.ext" not in sys.modules
+_before = set(sys.modules)
+if _stubbed:
_stub = types.ModuleType("exllamav3.ext")
_stub.exllamav3_ext = mock.MagicMock()
_stub.__getattr__ = lambda name: mock.MagicMock()
sys.modules["exllamav3.ext"] = _stub
-
-from ref import frac_reconstruct as FR
-from exllamav3.modules.moe_mixedk import (MixedKStore, MixedKUnsupported, PrunedLinear, expert_ks, layer_is_mixed,
- pruned_experts, check_expert_bits)
-from exllamav3.modules.block_sparse_mlp import _scatter_expert_count
-from test_moe_mixedk_cpu import (Pack, KernelEmu, DEV, H, I, TOPK, LIMIT, routing, acts, buffers, outs, ws_fn, close)
+try:
+ from ref import frac_reconstruct as FR
+ from exllamav3.modules.moe_mixedk import (MixedKStore, MixedKUnsupported, PrunedLinear, expert_ks, layer_is_mixed,
+ pruned_experts, check_expert_bits)
+ from exllamav3.modules.block_sparse_mlp import _scatter_expert_count
+ from test_moe_mixedk_cpu import (Pack, KernelEmu, DEV, H, I, TOPK, LIMIT, routing, acts, buffers, outs, ws_fn, close)
+finally:
+ _stub_modules = {_n: sys.modules.pop(_n) for _n in set(sys.modules) - _before
+ if _stubbed and (_n == "exllamav3" or _n.startswith("exllamav3."))}
+
+
[email protected](autouse = True, scope = "module")
+def _stubbed_exllamav3():
+ """The tests (and the modules they call) import exllamav3 modules too: the stubbed ones, as during the imports above."""
+ saved = {n: sys.modules.get(n) for n in _stub_modules}
+ sys.modules.update(_stub_modules)
+ yield
+ for n, m in saved.items():
+ if m is None:
+ sys.modules.pop(n, None)
+ else:
+ sys.modules[n] = m
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
QD = os.path.join(ROOT, "exllamav3", "exllamav3_ext", "quant")
diff --git a/tests/test_dsa_kernels.py b/tests/test_dsa_kernels.py
index 4e9a97e..518a7b4 100644
--- a/tests/test_dsa_kernels.py
+++ b/tests/test_dsa_kernels.py
@@ -13,6 +13,8 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn.dsa_triton import dsa_attn, dsa_indexer_scores
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_dsv4_cached.py b/tests/test_dsv4_cached.py
index 045108d..8eb13d2 100644
--- a/tests/test_dsv4_cached.py
+++ b/tests/test_dsv4_cached.py
@@ -13,8 +13,12 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import pytest
import torch
-from compare_deepseek_v4_hf_ import make_checkpoint, TINY
+_cmp = pytest.importorskip("compare_deepseek_v4_hf_", reason = "needs compare_deepseek_v4_hf_, not in the repository")
+make_checkpoint, TINY = _cmp.make_checkpoint, _cmp.TINY
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.cache.cache import Cache
diff --git a/tests/test_dsv4_compress_kernel.py b/tests/test_dsv4_compress_kernel.py
index b6c9546..0b8c891 100644
--- a/tests/test_dsv4_compress_kernel.py
+++ b/tests/test_dsv4_compress_kernel.py
@@ -16,6 +16,8 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_dsv4_state.py b/tests/test_dsv4_state.py
index 31e0f2f..63976d5 100644
--- a/tests/test_dsv4_state.py
+++ b/tests/test_dsv4_state.py
@@ -13,8 +13,12 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import pytest
import torch
-from compare_deepseek_v4_hf_ import make_checkpoint, TINY
+_cmp = pytest.importorskip("compare_deepseek_v4_hf_", reason = "needs compare_deepseek_v4_hf_, not in the repository")
+make_checkpoint, TINY = _cmp.make_checkpoint, _cmp.TINY
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.modules.dsv4 import DSV4CompressorState
diff --git a/tests/test_embedding_mmap.py b/tests/test_embedding_mmap.py
index 06d4afb..bc8b957 100644
--- a/tests/test_embedding_mmap.py
+++ b/tests/test_embedding_mmap.py
@@ -1,5 +1,7 @@
import os, torch
from safetensors.torch import save_file
+from hardware import require
+require("ext")
from exllamav3.loader.safetensors import SafetensorsCollection
diff --git a/tests/test_expert_store_mixedk_cpu.py b/tests/test_expert_store_mixedk_cpu.py
index 1e12123..4af7a4b 100644
--- a/tests/test_expert_store_mixedk_cpu.py
+++ b/tests/test_expert_store_mixedk_cpu.py
@@ -17,6 +17,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import numpy as np
import torch
+from hardware import require
+require("ext")
import exllamav3.modules.quant.exl3 as exl3mod
from exllamav3.modules import expert_store as es
from exllamav3.modules.moe_mixedk import MixedKStore, expert_ks
diff --git a/tests/test_ext_norm_.py b/tests/test_ext_norm_.py
index ab4bab9..f3e1935 100644
--- a/tests/test_ext_norm_.py
+++ b/tests/test_ext_norm_.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
torch.set_printoptions(precision = 5, sci_mode = False, linewidth = 200)
diff --git a/tests/test_ext_routing_.py b/tests/test_ext_routing_.py
index 5241834..0d053f1 100644
--- a/tests/test_ext_routing_.py
+++ b/tests/test_ext_routing_.py
@@ -11,6 +11,8 @@ import pytest
import torch
import torch.nn.functional as F
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
# The routing kernels are excluded from non-CUDA builds; the module-level torch fallbacks in
diff --git a/tests/test_ext_sampling_edges_.py b/tests/test_ext_sampling_edges_.py
index 90ee7ca..d55990f 100644
--- a/tests/test_ext_sampling_edges_.py
+++ b/tests/test_ext_sampling_edges_.py
@@ -5,6 +5,8 @@ must handle an odd element count; argmax_sample's paired read must respect an od
import os, sys
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
device = "cuda:0"
diff --git a/tests/test_ext_strings_.py b/tests/test_ext_strings_.py
index 8a8049e..f7c1a1b 100644
--- a/tests/test_ext_strings_.py
+++ b/tests/test_ext_strings_.py
@@ -8,6 +8,8 @@ match at a smaller index was found, so an already-present stop string could be o
import os, sys
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.generator.job import _strings_to_utf32
diff --git a/tests/test_failure_containment.py b/tests/test_failure_containment.py
index 1b88324..d98e335 100644
--- a/tests/test_failure_containment.py
+++ b/tests/test_failure_containment.py
@@ -22,6 +22,8 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3 import ArgmaxSampler
from exllamav3.generator.generator import Generator
from exllamav3.generator.async_generator import AsyncGenerator
diff --git a/tests/test_gdn_rewind_batch_.py b/tests/test_gdn_rewind_batch_.py
index f01d2fb..e289465 100644
--- a/tests/test_gdn_rewind_batch_.py
+++ b/tests/test_gdn_rewind_batch_.py
@@ -7,6 +7,8 @@ import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from types import SimpleNamespace
import torch
+from hardware import require
+require("ext")
from exllamav3.modules import gated_delta_net as gdn
dev = torch.device("cuda:0")
diff --git a/tests/test_gemm_rows24.py b/tests/test_gemm_rows24.py
index 39b2ca8..bafc570 100644
--- a/tests/test_gemm_rows24.py
+++ b/tests/test_gemm_rows24.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
# Swapped-operand 24-row tile (kernel shape 6, CUDA): 17..24 rows against the 32-row tile (shape 5) and the 16-row tiles
diff --git a/tests/test_gemv_pair_.py b/tests/test_gemv_pair_.py
index b484aa7..96486e0 100644
--- a/tests/test_gemv_pair_.py
+++ b/tests/test_gemv_pair_.py
@@ -6,6 +6,8 @@ Needs a CUDA device and EXL3_INT8_GEMV on (default on CUDA).
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
mode = int(os.environ.get("EXL3_GEMV_PAIR", "1"))
diff --git a/tests/test_generator_max_new_tokens_.py b/tests/test_generator_max_new_tokens_.py
index 23e09b3..4609f67 100644
--- a/tests/test_generator_max_new_tokens_.py
+++ b/tests/test_generator_max_new_tokens_.py
@@ -6,6 +6,8 @@ Set EXL3_TEST_DRAFT=mtp to also test with an MTP draft (model must have an MTP h
"""
import os, sys, inspect
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3 import model_init, Generator, Job, ArgmaxSampler
DEFAULT_MODEL = "/mnt/str/models/qwen3.5-0.8b/exl3/2.00bpw/"
diff --git a/tests/test_glm_dec2.py b/tests/test_glm_dec2.py
index 483596a..92ca21d 100644
--- a/tests/test_glm_dec2.py
+++ b/tests/test_glm_dec2.py
@@ -27,6 +27,8 @@ import pytest
import torch
sys.path.insert(0, os.environ.get("EXL3_REPO", os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from hardware import require # noqa: E402
+require("ext")
from exllamav3.ext import exllamav3_ext as ext # noqa: E402
DEV = "cuda:0"
diff --git a/tests/test_hgemm_f16acc.py b/tests/test_hgemm_f16acc.py
index da75878..a15633a 100644
--- a/tests/test_hgemm_f16acc.py
+++ b/tests/test_hgemm_f16acc.py
@@ -2,6 +2,8 @@
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_hip_add_sigmoid_gate_proj.py b/tests/test_hip_add_sigmoid_gate_proj.py
index 4c3e247..f2dcab5 100644
--- a/tests/test_hip_add_sigmoid_gate_proj.py
+++ b/tests/test_hip_add_sigmoid_gate_proj.py
@@ -4,6 +4,8 @@ from __future__ import annotations
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_hip_block_graph.py b/tests/test_hip_block_graph.py
index 69a525e..119c238 100644
--- a/tests/test_hip_block_graph.py
+++ b/tests/test_hip_block_graph.py
@@ -8,6 +8,8 @@ from pathlib import Path
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizer
from exllamav3.modules import block_graph
from exllamav3.modules.block_graph import BlockGraphRunner, maybe_graph_forward
diff --git a/tests/test_hip_dec_glm_gates.py b/tests/test_hip_dec_glm_gates.py
index 6d13474..ee4d2cc 100644
--- a/tests/test_hip_dec_glm_gates.py
+++ b/tests/test_hip_dec_glm_gates.py
@@ -26,6 +26,8 @@ import pytest
import torch
sys.path.insert(0, os.environ.get("EXL3_REPO", os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from hardware import require # noqa: E402
+require("ext")
from exllamav3.ext import exllamav3_ext as ext # noqa: E402
HIDDEN = 512 # % 512 == 0 (exl3_dec_moe requirement)
diff --git a/tests/test_hip_gemv_decode.py b/tests/test_hip_gemv_decode.py
index e363641..c503c2e 100644
--- a/tests/test_hip_gemv_decode.py
+++ b/tests/test_hip_gemv_decode.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.modules.quant import exl3 as exl3_quant
diff --git a/tests/test_hip_gemv_k5_flash.py b/tests/test_hip_gemv_k5_flash.py
index fa01bfe..f2a585f 100644
--- a/tests/test_hip_gemv_k5_flash.py
+++ b/tests/test_hip_gemv_k5_flash.py
@@ -8,6 +8,8 @@ import pytest
import torch
from hip_flash_quant import exl3_expert_quant
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_hip_grouped_moe_flash_oracle.py b/tests/test_hip_grouped_moe_flash_oracle.py
index 03ba4d2..e7428c7 100644
--- a/tests/test_hip_grouped_moe_flash_oracle.py
+++ b/tests/test_hip_grouped_moe_flash_oracle.py
@@ -8,6 +8,8 @@ from pathlib import Path
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizer
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.modules.block_sparse_mlp import BlockSparseMLP
diff --git a/tests/test_hip_grouped_moe_k3.py b/tests/test_hip_grouped_moe_k3.py
index 598cd36..20efdd9 100644
--- a/tests/test_hip_grouped_moe_k3.py
+++ b/tests/test_hip_grouped_moe_k3.py
@@ -11,6 +11,8 @@ import torch
from safetensors.torch import save_file
from hip_flash_quant import exl3_expert_quant
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.model.lora import LoRA
diff --git a/tests/test_hip_hc_mix.py b/tests/test_hip_hc_mix.py
index d7b8ad3..cbfb8ed 100644
--- a/tests/test_hip_hc_mix.py
+++ b/tests/test_hip_hc_mix.py
@@ -7,6 +7,8 @@ import pytest
import torch
import torch.nn.functional as F
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.modules import hyperconnections as hc
diff --git a/tests/test_hip_prefill_rows_oracle.py b/tests/test_hip_prefill_rows_oracle.py
index 626e035..f48d524 100644
--- a/tests/test_hip_prefill_rows_oracle.py
+++ b/tests/test_hip_prefill_rows_oracle.py
@@ -13,6 +13,8 @@ from pathlib import Path
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizer
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.modules.block_sparse_mlp import BlockSparseMLP
diff --git a/tests/test_job_params.py b/tests/test_job_params.py
index a22e89b..213f3f4 100644
--- a/tests/test_job_params.py
+++ b/tests/test_job_params.py
@@ -1,6 +1,8 @@
import os, sys, unittest
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.generator.job import Job
diff --git a/tests/test_kernel_seed.py b/tests/test_kernel_seed.py
index 92ac5d0..2178d06 100644
--- a/tests/test_kernel_seed.py
+++ b/tests/test_kernel_seed.py
@@ -2,6 +2,8 @@
import json, os, subprocess, sys, tempfile
from pathlib import Path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+from hardware import require
+require("ext")
from exllamav3.util import kernel_seed
REPO = str(Path(__file__).resolve().parents[1])
diff --git a/tests/test_kv_quant.py b/tests/test_kv_quant.py
index 16f4f73..6e30a14 100644
--- a/tests/test_kv_quant.py
+++ b/tests/test_kv_quant.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
import random
diff --git a/tests/test_kvwin.py b/tests/test_kvwin.py
index 22120d6..1f4acd9 100644
--- a/tests/test_kvwin.py
+++ b/tests/test_kvwin.py
@@ -14,6 +14,8 @@ import pytest
pytestmark = pytest.mark.skipif(not CPU and not torch.cuda.is_available(), reason = "needs a GPU (or KVWIN_TEST_CPU=1)")
+from hardware import require
+require("ext")
from exllamav3.cache.quant import CacheLayer_quant
from exllamav3.cache import kvwin
from exllamav3.cache.kvwin import KVWinLayerState, KVWinCtx, KVWinCfg, ring_rows, ring_positions, ov_write_ref, parse_spec
diff --git a/tests/test_mla.py b/tests/test_mla.py
index 242ef2f..bc30d50 100644
--- a/tests/test_mla.py
+++ b/tests/test_mla.py
@@ -4,6 +4,8 @@ import math
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.modules import MLAttention
from exllamav3.cache import CacheLayer_MLA_fp16
from exllamav3.constants import PAGE_SIZE
diff --git a/tests/test_mla_dsa.py b/tests/test_mla_dsa.py
index 15c9a06..d8abec8 100644
--- a/tests/test_mla_dsa.py
+++ b/tests/test_mla_dsa.py
@@ -5,6 +5,8 @@ import pytest
import torch
import torch.nn.functional as F
+from hardware import require
+require("ext")
from exllamav3.modules import MLAttention
from exllamav3.cache import CacheLayer_MLA_fp16, CacheLayer_MLA_quant
from exllamav3.ext import exllamav3_ext as ext
diff --git a/tests/test_model_tp_signals.py b/tests/test_model_tp_signals.py
index 9940708..68bb938 100644
--- a/tests/test_model_tp_signals.py
+++ b/tests/test_model_tp_signals.py
@@ -5,6 +5,8 @@ from unittest.mock import patch
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
import exllamav3.model.model_tp_fn as model_tp_fn
diff --git a/tests/test_moe_coop.py b/tests/test_moe_coop.py
index dfbd9f7..02afe3f 100644
--- a/tests/test_moe_coop.py
+++ b/tests/test_moe_coop.py
@@ -10,6 +10,8 @@ reconstructed weights.
import os
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
pytestmark = pytest.mark.skipif(
@@ -18,6 +20,8 @@ pytestmark = pytest.mark.skipif(
)
DEV = torch.device(os.environ.get("EXL3_TEST_DEVICE", "cuda:0"))
+if DEV.type == "cuda":
+ pytestmark = [pytestmark, pytest.mark.gpu]
ACTS = {"silu": 0, "gelu": 1, "relu2": 2, "swiglu_oai": 3}
diff --git a/tests/test_moe_cpu_pool_.py b/tests/test_moe_cpu_pool_.py
index de10674..a727e79 100644
--- a/tests/test_moe_cpu_pool_.py
+++ b/tests/test_moe_cpu_pool_.py
@@ -8,6 +8,8 @@ alternates a small participant cap with the full pool, the configuration in whic
import os, sys
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
pytestmark = pytest.mark.skipif(
diff --git a/tests/test_moe_cpu_tiers_.py b/tests/test_moe_cpu_tiers_.py
index 3dbd5f8..57e51d9 100644
--- a/tests/test_moe_cpu_tiers_.py
+++ b/tests/test_moe_cpu_tiers_.py
@@ -19,6 +19,8 @@ import os, sys, subprocess, tempfile
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as _ext
pytestmark = pytest.mark.skipif(
not hasattr(_ext, "exl3_moe_cpu_has_avx2"),
diff --git a/tests/test_moe_foreign.py b/tests/test_moe_foreign.py
index 7bff120..66345eb 100644
--- a/tests/test_moe_foreign.py
+++ b/tests/test_moe_foreign.py
@@ -32,6 +32,8 @@ def _load_pkg(name, path):
iq2_xxs = _load_pkg("fq_iq2_ref", os.path.join(ENGINE, "exllamav3", "foreign_quant", "iq2_xxs.py"))
+from hardware import require # noqa: E402
+require("ext")
from exllamav3.modules.foreign_linear import ForeignLinear # noqa: E402
import exllamav3.modules.foreign_linear as fl_mod # noqa: E402
from exllamav3.modules.block_sparse_mlp import BlockSparseMLP # noqa: E402
diff --git a/tests/test_moe_mixedk_cpu.py b/tests/test_moe_mixedk_cpu.py
index 4028c92..23976d3 100644
--- a/tests/test_moe_mixedk_cpu.py
+++ b/tests/test_moe_mixedk_cpu.py
@@ -26,6 +26,8 @@ import pytest
import torch
import torch.nn.functional as F
+from hardware import require
+require("ext")
from exllamav3.modules.moe_mixedk import (
MixedKStore, MixedKUnsupported, expert_bits_from_plan, parse_expert_bits, check_expert_bits, EXPERT_BITS_KEY,
layer_is_mixed, expert_ks)
diff --git a/tests/test_moe_sync_free_count.py b/tests/test_moe_sync_free_count.py
index 7956d0b..a4167ec 100644
--- a/tests/test_moe_sync_free_count.py
+++ b/tests/test_moe_sync_free_count.py
@@ -1,5 +1,7 @@
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.modules.block_sparse_mlp import (
_HIP_PREFILL_MAX_EXPERT_ROWS,
_moe_sync_free_count,
diff --git a/tests/test_multimodal_rewind_prefill.py b/tests/test_multimodal_rewind_prefill.py
index 3b274ad..70b5b56 100644
--- a/tests/test_multimodal_rewind_prefill.py
+++ b/tests/test_multimodal_rewind_prefill.py
@@ -14,6 +14,8 @@ import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.constants import PAGE_SIZE
from exllamav3.generator.job import Job
from exllamav3.tokenizer import MMEmbedding
diff --git a/tests/test_ngram_prefetch_.py b/tests/test_ngram_prefetch_.py
index a8d64e5..c6e5b18 100644
--- a/tests/test_ngram_prefetch_.py
+++ b/tests/test_ngram_prefetch_.py
@@ -17,6 +17,8 @@ KEY = "model.language_model.layers.1.ple.ple_embedding.ngram_embedding"
EOS = 248044
DEV = torch.device("cuda:0")
+from hardware import require
+require("ext")
from exllamav3.loader.safetensors import SafetensorsCollection
from exllamav3.modules import NGramEmbedding
from exllamav3.modules import ngram_embedding as ne
diff --git a/tests/test_padded_vocab.py b/tests/test_padded_vocab.py
index 1f25f6c..9e04da4 100644
--- a/tests/test_padded_vocab.py
+++ b/tests/test_padded_vocab.py
@@ -6,6 +6,8 @@ CPU tests, no model; the sampler tests on the GPU run only where one is present.
import os, sys, unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.generator import spec_sample
from exllamav3.generator.generator import Generator
from exllamav3.generator.job import Job
diff --git a/tests/test_pf_split_plan.py b/tests/test_pf_split_plan.py
index dc95ac2..1ac2075 100644
--- a/tests/test_pf_split_plan.py
+++ b/tests/test_pf_split_plan.py
@@ -1,6 +1,8 @@
"""Job.split_plan / Job.exact_gate / Job._stash_exact: EXL3_PF_SPLIT exactness tags (CPU only)."""
import os, sys, types
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+from hardware import require
+require("ext")
from exllamav3.generator.job import Job
from exllamav3.generator.pagetable import PAGE_SIZE
diff --git a/tests/test_plain_rows_cpu.py b/tests/test_plain_rows_cpu.py
index 82d0f86..ee8e8ac 100644
--- a/tests/test_plain_rows_cpu.py
+++ b/tests/test_plain_rows_cpu.py
@@ -1,4 +1,6 @@
"""CPU gate: which decode steps take the R-row exact paths (params["dflash_verify"]) without drafting."""
+from hardware import require
+require("ext")
from exllamav3.generator.row_groups import PLAIN_ROWS, plain_rows_verify
from exllamav3.util.row_inv import ROW_INV, ROW_INV_MAX_ROWS
diff --git a/tests/test_ple_stash_clone.py b/tests/test_ple_stash_clone.py
index ee0e71b..881b859 100644
--- a/tests/test_ple_stash_clone.py
+++ b/tests/test_ple_stash_clone.py
@@ -7,6 +7,8 @@ import os, sys
from types import SimpleNamespace
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.modules.ple import PLELayerState
diff --git a/tests/test_prefill_block_table_cpu.py b/tests/test_prefill_block_table_cpu.py
index d9b93dc..3ad92f6 100644
--- a/tests/test_prefill_block_table_cpu.py
+++ b/tests/test_prefill_block_table_cpu.py
@@ -1,5 +1,7 @@
import torch
+from hardware import require
+require("ext")
from exllamav3.constants import PAGE_SIZE
from exllamav3.generator.generator import block_table_pages
from exllamav3.generator.pagetable import Sequence
diff --git a/tests/test_prefill_ck.py b/tests/test_prefill_ck.py
index 86939c9..ac6f882 100644
--- a/tests/test_prefill_ck.py
+++ b/tests/test_prefill_ck.py
@@ -4,6 +4,8 @@ import torch
pytestmark = pytest.mark.skipif(not torch.cuda.is_available() or torch.version.hip is None, reason = "ROCm only")
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
_SO = os.environ.get("EXL3_PF_CK_SO") or os.path.expanduser("~/.cache/kyojin/ck-fmha/libckpf.so")
diff --git a/tests/test_prefill_ck_fallback.py b/tests/test_prefill_ck_fallback.py
index b19d218..68ba034 100644
--- a/tests/test_prefill_ck_fallback.py
+++ b/tests/test_prefill_ck_fallback.py
@@ -1,6 +1,8 @@
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
diff --git a/tests/test_prefill_fa2_rows.py b/tests/test_prefill_fa2_rows.py
index 5fb5cf4..4b0e84e 100644
--- a/tests/test_prefill_fa2_rows.py
+++ b/tests/test_prefill_fa2_rows.py
@@ -3,6 +3,8 @@ import torch
pytestmark = pytest.mark.skipif(not torch.cuda.is_available() or torch.version.hip is not None, reason = "CUDA only")
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
diff --git a/tests/test_prefill_row_slice.py b/tests/test_prefill_row_slice.py
index eb1ce60..a7e347a 100644
--- a/tests/test_prefill_row_slice.py
+++ b/tests/test_prefill_row_slice.py
@@ -10,6 +10,8 @@ import torch
pytestmark = pytest.mark.skipif(not torch.cuda.is_available(), reason = "needs a GPU (Triton)")
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
PAGE = 256
diff --git a/tests/test_prefill_waves_per_eu.py b/tests/test_prefill_waves_per_eu.py
index 27558bc..7d293be 100644
--- a/tests/test_prefill_waves_per_eu.py
+++ b/tests/test_prefill_waves_per_eu.py
@@ -9,6 +9,8 @@ import torch
pytestmark = pytest.mark.skipif(not torch.cuda.is_available() or torch.version.hip is None, reason = "needs a ROCm GPU (Triton)")
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
PAGE = 256
diff --git a/tests/test_qdec_hip.py b/tests/test_qdec_hip.py
index 811aee4..30d55cd 100644
--- a/tests/test_qdec_hip.py
+++ b/tests/test_qdec_hip.py
@@ -4,6 +4,8 @@ import argparse, math, os, sys, time
os.environ.setdefault("EXL3_QDEC_HIP", "1")
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
import torch
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn import triton_paged as tp
ap = argparse.ArgumentParser()
diff --git a/tests/test_qgemm.py b/tests/test_qgemm.py
index c9564dd..0120f2f 100644
--- a/tests/test_qgemm.py
+++ b/tests/test_qgemm.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
torch.set_printoptions(precision = 5, sci_mode = False, linewidth = 200)
diff --git a/tests/test_quant_fn.py b/tests/test_quant_fn.py
index f60762c..cef04e5 100644
--- a/tests/test_quant_fn.py
+++ b/tests/test_quant_fn.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3 import Config, Model
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.modules.quant.exl3_lib.quantize import quantize_tiles
diff --git a/tests/test_qwrite.py b/tests/test_qwrite.py
index 5780c0f..ba86be0 100644
--- a/tests/test_qwrite.py
+++ b/tests/test_qwrite.py
@@ -3,6 +3,8 @@ python tests/test_qwrite.py"""
import os, sys, time
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
import torch
+from hardware import require
+require("ext")
from exllamav3 import ext_fallbacks as fb
dev = torch.device("cuda"); torch.manual_seed(0)
diff --git a/tests/test_rope.py b/tests/test_rope.py
index f7ede21..3c771a7 100644
--- a/tests/test_rope.py
+++ b/tests/test_rope.py
@@ -2,6 +2,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("gpu", "ext")
from exllamav3.ext import exllamav3_ext as ext
from exllamav3.util.rope import RoPE, RopeStyle, RopeSettings
import torch.testing
diff --git a/tests/test_rope_yarn.py b/tests/test_rope_yarn.py
index 23a1e36..06ba549 100644
--- a/tests/test_rope_yarn.py
+++ b/tests/test_rope_yarn.py
@@ -6,6 +6,8 @@ import pytest
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.util.rope import RoPE, RopeSettings
diff --git a/tests/test_row_groups_cpu.py b/tests/test_row_groups_cpu.py
index 734b3ec..9ef6fba 100644
--- a/tests/test_row_groups_cpu.py
+++ b/tests/test_row_groups_cpu.py
@@ -9,6 +9,8 @@ import types
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.generator import row_groups as RG
from exllamav3.generator.generator import Generator
from exllamav3.util.row_inv import ROW_INV_MAX_ROWS
diff --git a/tests/test_row_invariance_cpu.py b/tests/test_row_invariance_cpu.py
index e24d297..bfd9633 100644
--- a/tests/test_row_invariance_cpu.py
+++ b/tests/test_row_invariance_cpu.py
@@ -7,6 +7,8 @@ import os
import torch
import pytest
+from hardware import require
+require("ext")
from exllamav3.util.row_inv import ROW_INV, ROW_INV_MAX_ROWS
from exllamav3.modules import block_sparse_mlp_routing as R
from exllamav3.modules.mla_attn import MLAttention, _rowloop_max
diff --git a/tests/test_row_slices_cpu.py b/tests/test_row_slices_cpu.py
index 9951f46..8ebc99c 100644
--- a/tests/test_row_slices_cpu.py
+++ b/tests/test_row_slices_cpu.py
@@ -2,6 +2,8 @@
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.modules import block_sparse_mlp as B
from exllamav3.util.row_inv import ROW_INV_MAX_ROWS
diff --git a/tests/test_sampler.py b/tests/test_sampler.py
index e830306..bd66fcf 100644
--- a/tests/test_sampler.py
+++ b/tests/test_sampler.py
@@ -3,6 +3,8 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import numpy as np
import torch
+from hardware import require
+require("ext")
from exllamav3.ext import exllamav3_ext as ext
from exllamav3 import (
TopKSampler,
diff --git a/tests/test_spec_sample.py b/tests/test_spec_sample.py
index 521205c..b595362 100644
--- a/tests/test_spec_sample.py
+++ b/tests/test_spec_sample.py
@@ -7,6 +7,8 @@ import os, sys, math, random, unittest
os.environ.setdefault("HIP_VISIBLE_DEVICES", ""); os.environ.setdefault("CUDA_VISIBLE_DEVICES", "")
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.generator import spec_sample as ss
from exllamav3.generator.sampler import ComboSampler, ArgmaxSampler
diff --git a/tests/test_tail_ckpt_rows.py b/tests/test_tail_ckpt_rows.py
index dbbf56d..35e021d 100644
--- a/tests/test_tail_ckpt_rows.py
+++ b/tests/test_tail_ckpt_rows.py
@@ -1,6 +1,8 @@
"""Job.tail_ckpt_rows: which chunk rows get a dense prompt-tail checkpoint (CPU only)."""
import os, sys, types
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+from hardware import require
+require("ext")
from exllamav3.generator.job import Job
from exllamav3.generator.pagetable import PAGE_SIZE
diff --git a/tests/test_tail_page_usable_.py b/tests/test_tail_page_usable_.py
index 76c416f..51a1220 100644
--- a/tests/test_tail_page_usable_.py
+++ b/tests/test_tail_page_usable_.py
@@ -5,6 +5,8 @@ so the restore must take the deeper copy from the disk. Pure torch on CPU.
import os, sys, types
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
+from hardware import require
+require("ext")
from exllamav3.generator.prefix_disk import tail_page_usable
ids = torch.arange(100).view(1, -1)
diff --git a/tests/test_tokenizer_decode_specials.py b/tests/test_tokenizer_decode_specials.py
index a6c4a15..03b7e35 100644
--- a/tests/test_tokenizer_decode_specials.py
+++ b/tests/test_tokenizer_decode_specials.py
@@ -1,5 +1,7 @@
import os, sys, unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3 import Config, Tokenizer
# gemma4: most HF-special tokens are outside exllamav3's extended-token map and go through the HF decode call
diff --git a/tests/test_tp_export_attention.py b/tests/test_tp_export_attention.py
index 35b8e08..b6ee09a 100644
--- a/tests/test_tp_export_attention.py
+++ b/tests/test_tp_export_attention.py
@@ -7,6 +7,8 @@ import sys, os, unittest
from unittest.mock import patch
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.modules.attn import Attention
from exllamav3.modules.sliding_attn import SlidingAttention
diff --git a/tests/test_tq_cache.py b/tests/test_tq_cache.py
index f8ebdf0..74a8c57 100644
--- a/tests/test_tq_cache.py
+++ b/tests/test_tq_cache.py
@@ -11,6 +11,8 @@ import torch
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import pytest
+from hardware import require
+require("ext")
from exllamav3.cache import tq
from exllamav3.cache.kvwin import KVWinLayerState, KVWinCtx, KVWinCfg, parse_spec
diff --git a/tests/test_triton_paged_hdpad.py b/tests/test_triton_paged_hdpad.py
index 411c56b..f569177 100644
--- a/tests/test_triton_paged_hdpad.py
+++ b/tests/test_triton_paged_hdpad.py
@@ -8,6 +8,8 @@ import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
import torch
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn.triton_paged import (
paged_attn_triton_decode, paged_attn_triton_prefill,
)
diff --git a/tests/test_triton_paged_overflow.py b/tests/test_triton_paged_overflow.py
index 2680022..25aac4b 100644
--- a/tests/test_triton_paged_overflow.py
+++ b/tests/test_triton_paged_overflow.py
@@ -7,6 +7,8 @@ import torch
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from hardware import require
+require("ext")
from exllamav3.modules.attention_fn.triton_paged import paged_attn_triton_prefill
diff --git a/tests/test_vision_pinned_no_stale_weights.py b/tests/test_vision_pinned_no_stale_weights.py
index e0414b7..ff37b64 100644
--- a/tests/test_vision_pinned_no_stale_weights.py
+++ b/tests/test_vision_pinned_no_stale_weights.py
@@ -4,6 +4,8 @@ import pytest
import torch
from PIL import Image
+from hardware import require
+require("ext")
from exllamav3 import Config, Model, Tokenizer
from exllamav3.modules import Linear
from exllamav3.util.memory import free_mem
diff --git a/tools/qualify/backends.py b/tools/qualify/backends.py
index a1fef62..8f52ab8 100644
--- a/tools/qualify/backends.py
+++ b/tools/qualify/backends.py
@@ -28,10 +28,10 @@ PROFILES = {
_TORCH_PROBE = "import torch,sys; sys.exit(0 if (torch.version.{attr} and torch.__version__) else 3)"
-def find_python(backend: str, repo: str | None = None) -> str:
+def find_python(backend: str, repo: str | None = None, required: bool = True) -> str | None:
"""The interpreter whose torch matches the backend (cuda: torch.version.cuda, rocm: torch.version.hip): QUALIFY_PYTHON, then the
engine checkout's own venv, $VIRTUAL_ENV, then every $QUALIFY_WORK_ROOT/*/{venv,.venv} (if set) and the current interpreter. No hand flag:
- drill 0 tried the system python first (no torch) and had to be told which venv the lanes use."""
+ drill 0 tried the system python first (no torch) and had to be told which venv the lanes use. Not required (--dry-run): None when none is found."""
import glob
import subprocess
if PYTHON:
@@ -55,6 +55,8 @@ def find_python(backend: str, repo: str | None = None) -> str:
return c
except Exception: # noqa: BLE001
continue
+ if not required:
+ return None
raise SystemExit(f"no python with a {attr} torch found (set QUALIFY_PYTHON)")
diff --git a/tools/qualify/qualify.py b/tools/qualify/qualify.py
index 73e9b98..a32701a 100644
--- a/tools/qualify/qualify.py
+++ b/tools/qualify/qualify.py
@@ -24,19 +24,30 @@ import report # noqa: E402
import stages as st # noqa: E402
+def int_list(ap: argparse.ArgumentParser, value: str, flag: str) -> list[int]:
+ """A comma list of positive integers; anything else is a usage error (exit 2), not a traceback."""
+ try:
+ out = [int(x) for x in value.split(",")]
+ except ValueError:
+ out = []
+ if not out or min(out) < 1:
+ ap.error(f"{flag} wants a comma list of positive integers, got {value!r}")
+ return out
+
+
def parse(argv=None) -> dict:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
- ap.add_argument("--backend", required=True, choices=sorted(backends.PROFILES))
+ ap.add_argument("--backend", required=True, choices=sorted(backends.PROFILES), help="GPU backend; picks the python whose torch matches it (QUALIFY_PYTHON overrides)")
ap.add_argument("--pack", required=True, help="converted pack directory")
ap.add_argument("--ref", help="BF16 reference model directory (for parity + KV KL; kept until the gate passes)")
ap.add_argument("--out", help="state/output dir (default: <repo>/qualify_out/<pack>/<backend>)")
ap.add_argument("--stage", help="comma list of stages to run (default: all). Stages: " + ",".join(planmod.ORDER))
ap.add_argument("--redo", help="comma list of stages to clear and rerun")
- ap.add_argument("--force-deps", action="store_true")
+ ap.add_argument("--force-deps", action="store_true", help="with --stage: also run the stages the selected ones need instead of stopping on them")
ap.add_argument("--dry-run", action="store_true", help="print the plan, derived serve command and estimates; touch no GPU")
ap.add_argument("--sessions", default="1,4", help="session counts for the max-ctx search; the largest is the served config (N=1..max matrix)")
ap.add_argument("--kv-bits", default="8,6,4", help="symmetric KV bits measured by the kv stage (8 is the baseline)")
- ap.add_argument("--kv-kl-max", type=float, default=0.02)
+ ap.add_argument("--kv-kl-max", type=float, default=0.02, help="largest KL vs the k8v8 cache for a narrower KV cache to be chosen (kv stage)")
ap.add_argument("--no-kv-modes", dest="kv_modes", action="store_false", help="skip the KV format auto-select (k6v6 vs tq6 vs tq5, decode-faithful 32K KL vs k8v8) in the kv stage")
ap.add_argument("--kvmode-steps", type=int, default=256, help="teacher-forced decode steps scored by the KV format auto-select")
ap.add_argument("--drafter", help="DFlash drafter directory (default: <pack>/dflash, ~/models/drafters/*, else a HF search '<model stem> dflash')")
@@ -44,24 +55,24 @@ def parse(argv=None) -> dict:
ap.add_argument("--soak-s", type=float, default=360, help="seconds of mixed agent-shaped load per session count at the max-ctx result (soak stage); on any error -c steps down 8 %% and the soak reruns")
ap.add_argument("--min-share", type=int, default=24576, help="tokens one session must get for the shipped session count (default 24,576: Hermes' live preamble is 15-30K)")
ap.add_argument("--ctx-cap", type=int, help="cap of the max-ctx search (default: the model's max_position_embeddings)")
- ap.add_argument("--disk-floor-gb", type=float, default=40)
+ ap.add_argument("--disk-floor-gb", type=float, default=40, help="free disk (GB) to keep after a download or a conversion; the fetch stage fails below it")
ap.add_argument("--convert-from", help="BF16 checkpoint directory: convert it into --pack first when the pack is missing/incomplete (own-PID memory guard, resume, convert.log + chat template carried into the pack)")
ap.add_argument("--bits", type=float, default=4.0, help="conversion bits per weight")
- ap.add_argument("--head-bits", type=int, default=6)
+ ap.add_argument("--head-bits", type=int, default=6, help="conversion bits of the output head")
ap.add_argument("--conv-work", help="converter work dir (default <out>/conv_work; kept until the conversion succeeds, deleted then unless --keep-work)")
ap.add_argument("--conv-extra", default="", help="extra converter flags, e.g. '-hq'")
ap.add_argument("--conv-pause-gib", type=float, default=6.0, help="SIGSTOP the converter when MemAvailable falls below this")
- ap.add_argument("--conv-resume-gib", type=float, default=10.0)
- ap.add_argument("--keep-work", action="store_true")
+ ap.add_argument("--conv-resume-gib", type=float, default=10.0, help="SIGCONT the paused converter when MemAvailable is back to this")
+ ap.add_argument("--keep-work", action="store_true", help="keep the converter work dir after a successful conversion")
ap.add_argument("--hf", help="HF repo to download into --pack first (license/size/disk-floor checked)")
ap.add_argument("--conv-log", help="converter log (per-layer SQNR); default <pack>/convert.log")
ap.add_argument("--smoke-tasks", default="", help="hermes_opt/eval task ids (default: 4 spread over the suite)")
- ap.add_argument("--port", type=int, default=8590)
+ ap.add_argument("--port", type=int, default=8590, help="first port tried for the test servers (the next free one is used)")
ap.add_argument("--repo", default=str(HERE.parents[1]), help="engine checkout with the BUILT extension: PYTHONPATH + cwd of the servers (default: this checkout)")
ap.add_argument("--gates", type=json.loads, default=None, help='JSON override of verdict gates, e.g. \'{"kl_mean": 0.1}\'')
a = vars(ap.parse_args(argv))
- a["sessions"] = sorted({int(x) for x in a["sessions"].split(",")})
- a["kv_bits"] = [int(x) for x in a["kv_bits"].split(",")]
+ a["sessions"] = sorted(set(int_list(ap, a["sessions"], "--sessions")))
+ a["kv_bits"] = int_list(ap, a["kv_bits"], "--kv-bits")
a["pack"] = str(Path(a["pack"]).expanduser().resolve())
a["repo"] = str(Path(a["repo"]).expanduser().resolve())
if a["ref"]:
@@ -70,6 +81,19 @@ def parse(argv=None) -> dict:
return a
+def read_pack_or_exit(pack: str) -> dict:
+ """The pack metadata, or a one-line error naming --pack instead of a traceback."""
+ p = Path(pack)
+ if not p.is_dir():
+ sys.exit(f"--pack {p}: no such directory")
+ if not (p / "config.json").is_file():
+ sys.exit(f"--pack {p}: no config.json, not a model directory")
+ try:
+ return packmod.read_pack(p)
+ except (OSError, ValueError, KeyError) as e:
+ sys.exit(f"--pack {p}: cannot read the model metadata ({type(e).__name__}: {e})")
+
+
def logger(out: Path):
def log(msg):
line = f"{time.strftime('%F %T')} qualify {msg}"
@@ -90,19 +114,24 @@ def main(argv=None) -> int:
_convert(a, out)
if a["ctx_cap"] is None:
a["ctx_cap"] = backends.PROFILES[a["backend"]].get("ctx_cap_default")
- meta = packmod.read_pack(a["pack"])
+ meta = read_pack_or_exit(a["pack"])
state = planmod.load_state(out)
only = a["stage"].split(",") if a["stage"] else None
for s in (only or []) + (a["redo"].split(",") if a["redo"] else []):
if s not in planmod.ORDER:
sys.exit(f"unknown stage {s!r}")
plan = planmod.build_plan(meta, a, state, only=only, redo=a["redo"].split(",") if a["redo"] else None, force_deps=a["force_deps"])
- cmd = [backends.profile(a["backend"], a["repo"])["python"], *packmod.serve_flags(meta, port=a["port"], ctx=0, sessions=max(a["sessions"]), k_bits=6, v_bits=6)]
+ # --dry-run touches no GPU and needs no GPU torch: without one, the serve command names $QUALIFY_PYTHON instead
+ prof = None if a["dry_run"] else backends.profile(a["backend"], a["repo"])
+ python = prof["python"] if prof else backends.find_python(a["backend"], a["repo"], required=False)
+ if python is None:
+ print(f"no python with a {a['backend']} torch found: the serve command below names $QUALIFY_PYTHON, set it before a real run", file=sys.stderr)
+ python = "$QUALIFY_PYTHON"
+ cmd = [python, *packmod.serve_flags(meta, port=a["port"], ctx=0, sessions=max(a["sessions"]), k_bits=6, v_bits=6)]
if a["dry_run"]:
print(planmod.render_plan(plan, meta, cmd, a))
return 0
log = logger(out)
- prof = backends.profile(a["backend"], a["repo"])
c = st.Ctx(meta, a, out, Path(a["repo"]), prof, log)
c.data = {n: s["data"] for n, s in state.items() if s.get("status") == "done"}
for s in plan:
diff --git a/tools/qualify/tests/test_plan.py b/tools/qualify/tests/test_plan.py
index c35db95..22e87f3 100644
--- a/tools/qualify/tests/test_plan.py
+++ b/tools/qualify/tests/test_plan.py
@@ -251,6 +251,42 @@ class CliTests(unittest.TestCase):
self.assertIn("serve command", buf.getvalue())
self.assertEqual([p.name for p in (Path(t) / "o").iterdir()], [])
+ def test_dry_run_without_a_gpu_torch_names_qualify_python(self):
+ import io, contextlib, qualify
+ from unittest import mock
+ with tempfile.TemporaryDirectory() as t:
+ (Path(t) / "p").mkdir()
+ pk = fake_pack(Path(t) / "p")
+ out, err = io.StringIO(), io.StringIO()
+ with mock.patch.object(qualify.backends, "find_python", return_value=None), contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
+ rc = qualify.main(["--backend", "rocm", "--pack", str(pk), "--dry-run", "--out", str(Path(t) / "o")])
+ self.assertEqual(rc, 0)
+ self.assertIn("$QUALIFY_PYTHON", out.getvalue())
+ self.assertIn("QUALIFY_PYTHON", err.getvalue())
+
+ def test_a_bad_pack_is_one_line_naming_the_flag(self):
+ import qualify
+ with tempfile.TemporaryDirectory() as t:
+ (Path(t) / "empty").mkdir()
+ (Path(t) / "broken").mkdir()
+ (Path(t) / "broken" / "config.json").write_text("{not json")
+ (Path(t) / "partial").mkdir()
+ (Path(t) / "partial" / "config.json").write_text(json.dumps({"architectures": ["LlamaForCausalLM"]}))
+ for name, want in (("missing", "no such directory"), ("empty", "no config.json"), ("broken", "JSONDecodeError"), ("partial", "KeyError")):
+ with self.subTest(name), self.assertRaises(SystemExit) as cm:
+ qualify.main(["--backend", "cuda", "--pack", str(Path(t) / name), "--dry-run", "--out", str(Path(t) / "o")])
+ self.assertIsInstance(cm.exception.code, str)
+ self.assertTrue(cm.exception.code.startswith("--pack "), cm.exception.code)
+ self.assertIn(want, cm.exception.code)
+
+ def test_a_bad_int_list_is_a_usage_error(self):
+ import io, contextlib, qualify
+ for flag, value in (("--sessions", "1,x"), ("--sessions", "0"), ("--kv-bits", "")):
+ with self.subTest(flag=flag, value=value), contextlib.redirect_stderr(io.StringIO()) as err, self.assertRaises(SystemExit) as cm:
+ qualify.parse(["--backend", "cuda", "--pack", "/p", flag, value])
+ self.assertEqual(cm.exception.code, 2)
+ self.assertIn(flag, err.getvalue())
+
class KvModeRule(unittest.TestCase):