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.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Run the whole test suite without a GPU; clearer qualify errors (#131)
Idriss091792a5dd80acc
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 581ab26..dbdba88 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -32,6 +32,10 @@ pip install pytestfor 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 requestsdiff --git a/tests/conftest.py b/tests/conftest.pyindex 4f98a30..1d6468f 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -1,6 +1,25 @@+import os+import sys+import pytestimport 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.pyindex 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: E402from exllamav3.modules import ablit_runtime # noqa: E402import arch as A # noqa: E402diff --git a/tests/dsv41/test_dsv41_calib.py b/tests/dsv41/test_dsv41_calib.pyindex 5f41b2c..9c57376 100644--- a/tests/dsv41/test_dsv41_calib.py+++ b/tests/dsv41/test_dsv41_calib.py@@ -11,6 +11,8 @@ import os, sysimport pytestimport torchsys.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_minefrom exllamav3.dsv41 import ops, quantdiff --git a/tests/dsv41/test_dsv41_e2e.py b/tests/dsv41/test_dsv41_e2e.pyindex 5eab93f..e761b17 100644--- a/tests/dsv41/test_dsv41_e2e.py+++ b/tests/dsv41/test_dsv41_e2e.py@@ -10,6 +10,8 @@ import os, sysimport pytestimport torchsys.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, MemoryEngramStorefrom exllamav3.dsv41.weights import DictWeightSourcediff --git a/tests/dsv41/test_dsv41_engram_io.py b/tests/dsv41/test_dsv41_engram_io.pyindex 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 npimport pytestimport torch+from hardware import require+require("ext")from exllamav3.dsv41.engram import DirectRowReaderfrom exllamav3.modules.dsv41_fn.engram_io import ParallelRowReader, NativeRowReaderdiff --git a/tests/dsv41/test_dsv41_engram_prefetch.py b/tests/dsv41/test_dsv41_engram_prefetch.pyindex 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 npimport pytestimport torch+from hardware import require+require("ext")from exllamav3.dsv41.engram import EngramLayout, NgramHasher, compute_multipliers, EngramRowStorefrom exllamav3.modules.dsv41_fn.engram_prefetch import HostEngramHash, EngramPrefetcherdiff --git a/tests/dsv41/test_dsv41_engram_wkv_fp8.py b/tests/dsv41/test_dsv41_engram_wkv_fp8.pyindex 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 torchfrom safetensors.torch import save_filesys.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 SafetensorsCollectionfrom exllamav3.modules import Lineardiff --git a/tests/dsv41/test_dsv41_framework.py b/tests/dsv41/test_dsv41_framework.pyindex 9d48cf1..54753d6 100644--- a/tests/dsv41/test_dsv41_framework.py+++ b/tests/dsv41/test_dsv41_framework.py@@ -12,6 +12,8 @@ import json, os, sysimport pytestimport torchsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+from hardware import require+require("ext")from tiny_ckpt import write_tiny, fw_configfrom harness import *from exllamav3.dsv41 import opsdiff --git a/tests/dsv41/test_dsv41_hip.py b/tests/dsv41/test_dsv41_hip.pyindex 8f40f79..bc536de 100644--- a/tests/dsv41/test_dsv41_hip.py+++ b/tests/dsv41/test_dsv41_hip.py@@ -16,6 +16,8 @@ import numpy as npimport pytestimport torchsys.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_minefrom exllamav3.dsv41 import ops, quantdiff --git a/tests/dsv41/test_dsv41_hipk.py b/tests/dsv41/test_dsv41_hipk.pyindex a32e76f..7ec73bb 100644--- a/tests/dsv41/test_dsv41_hipk.py+++ b/tests/dsv41/test_dsv41_hipk.py@@ -18,6 +18,8 @@ import pytestimport torchsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+from hardware import require+require("ext")from exllamav3.dsv41 import ops, quantfrom 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.pyindex 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 quantpytestmark = 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.pyindex 879d4b9..2a51368 100644--- a/tests/dsv41/test_dsv41_loaders.py+++ b/tests/dsv41/test_dsv41_loaders.py@@ -10,6 +10,8 @@ import numpy as npimport pytestimport torchsys.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, TOLdiff --git a/tests/dsv41/test_dsv41_num.py b/tests/dsv41/test_dsv41_num.pyindex 256de95..2dab513 100644--- a/tests/dsv41/test_dsv41_num.py+++ b/tests/dsv41/test_dsv41_num.py@@ -8,6 +8,8 @@ import numpy as npimport pytestimport torch+from hardware import require+require("ext")from exllamav3.dsv41 import quantfrom 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.pyindex c797b1a..ac00684 100644--- a/tests/dsv41/test_dsv41_ops.py+++ b/tests/dsv41/test_dsv41_ops.py@@ -6,6 +6,8 @@ import numpy as npimport pytestimport torchsys.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_quantfrom exllamav3.dsv41 import ops, quantdiff --git a/tests/dsv41/test_dsv41_packwire.py b/tests/dsv41/test_dsv41_packwire.pyindex 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: E402from exllamav3.dsv41 import packspec as PS # noqa: E402from exllamav3.dsv41.engram import MemoryEngramStore # noqa: E402diff --git a/tests/dsv41/test_dsv41_real_headers.py b/tests/dsv41/test_dsv41_real_headers.pyindex 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, sysimport pytestimport torchsys.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 DSV41Configfrom exllamav3.dsv41.weights import WeightSourcefrom exllamav3.dsv41.linear import DenseLindiff --git a/tests/dsv41/test_dsv41_real_slices.py b/tests/dsv41/test_dsv41_real_slices.pyindex 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, sysimport pytestimport torchsys.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 GR = 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.pyindex b181938..5fcf4f1 100644--- a/tests/dsv41/test_dsv41_serving.py+++ b/tests/dsv41/test_dsv41_serving.py@@ -19,6 +19,8 @@ import torchHERE = 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 harnessfrom harness import FakeTok, make_state_dict, make_engram_tables, tiny_configfrom exllamav3.dsv41.config import DSV41Configdiff --git a/tests/dsv41/test_dsv41_serving_spec.py b/tests/dsv41/test_dsv41_serving_spec.pyindex 3515fe8..b507645 100644--- a/tests/dsv41/test_dsv41_serving_spec.py+++ b/tests/dsv41/test_dsv41_serving_spec.py@@ -16,6 +16,8 @@ import torchHERE = 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 Simport test_dsv41_spec as Timport dspark as ctldiff --git a/tests/dsv41/test_dsv41_spec.py b/tests/dsv41/test_dsv41_spec.pyindex 31123bf..b992ce4 100644--- a/tests/dsv41/test_dsv41_spec.py+++ b/tests/dsv41/test_dsv41_spec.py@@ -19,6 +19,8 @@ import torchHERE = 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 harnessfrom harness import FakeTok, make_state_dict, make_engram_tables, tiny_configfrom test_dsv41_e2e import build_minediff --git a/tests/dsv41/test_dsv41_spec_real.py b/tests/dsv41/test_dsv41_spec_real.pyindex de20f9d..7063480 100644--- a/tests/dsv41/test_dsv41_spec_real.py+++ b/tests/dsv41/test_dsv41_spec_real.py@@ -15,6 +15,8 @@ import torchHERE = 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 DSV41Configfrom exllamav3.dsv41.safetensors_io import SafetensorsWeightSourcefrom exllamav3.dsv41.experts import SourceExpertProviderdiff --git a/tests/dsv41/test_dsv41_stream.py b/tests/dsv41/test_dsv41_stream.pyindex 479b477..d7593f6 100644--- a/tests/dsv41/test_dsv41_stream.py+++ b/tests/dsv41/test_dsv41_stream.py@@ -7,6 +7,8 @@ import os, sysimport pytestimport torchsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+from hardware import require+require("ext")from tiny_ckpt import write_tinyfrom harness import *from exllamav3.dsv41.weights import DictWeightSourcediff --git a/tests/dsv41/test_dsv41_vision_model.py b/tests/dsv41/test_dsv41_vision_model.pyindex 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 ImageHERE = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, HERE)from pathlib import Path+from hardware import require+require("ext")import harnessfrom harness import FakeTok, build_reference, make_engram_tables, make_state_dict, tiny_configfrom exllamav3.dsv41 import vision as Vdiff --git a/tests/hardware.py b/tests/hardware.pynew file mode 100644index 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.pyindex 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 gridif 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_SIZEfrom exllamav3.modules.attention_fn import triton_paged as tpdiff --git a/tests/test_attn_optimizer_targets.py b/tests/test_attn_optimizer_targets.pyindex 4d9f6d0..4eb9e52 100644--- a/tests/test_attn_optimizer_targets.py+++ b/tests/test_attn_optimizer_targets.py@@ -1,5 +1,7 @@import os, sys, unittestsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.modules.attn import Attentionclass FakeLinear:diff --git a/tests/test_bc_recurrent_graph_geometry_.py b/tests/test_bc_recurrent_graph_geometry_.pyindex 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, gcimport torchsys.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, ArgmaxSamplerfrom exllamav3.modules.block_sparse_mlp import BlockSparseMLPdiff --git a/tests/test_bc_shared_expert_graph_.py b/tests/test_bc_shared_expert_graph_.pyindex 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, gcimport torchsys.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, ArgmaxSamplerfrom exllamav3.modules.block_sparse_mlp import BlockSparseMLPdiff --git a/tests/test_block_ldl_threads.py b/tests/test_block_ldl_threads.pyindex 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 qN, B = 1024, 16diff --git a/tests/test_cache_rotate.py b/tests/test_cache_rotate.pyindex 40203fc..33dcc24 100644--- a/tests/test_cache_rotate.py+++ b/tests/test_cache_rotate.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extfrom itertools import pairwisediff --git a/tests/test_capture_h_batched.py b/tests/test_capture_h_batched.pyindex 08bc6cd..1396e71 100644--- a/tests/test_capture_h_batched.py+++ b/tests/test_capture_h_batched.py@@ -17,6 +17,8 @@ import numpy as npsys.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 lindiff --git a/tests/test_cpu_cache.py b/tests/test_cpu_cache.pyindex b3c7662..975e163 100644--- a/tests/test_cpu_cache.py+++ b/tests/test_cpu_cache.py@@ -3,6 +3,8 @@ import torchfrom collections import namedtuplefrom 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 adiff --git a/tests/test_cpu_cache_tp.py b/tests/test_cpu_cache_tp.pyindex b488367..5ff33c9 100644--- a/tests/test_cpu_cache_tp.py+++ b/tests/test_cpu_cache_tp.py@@ -3,6 +3,8 @@ import torchfrom collections import namedtuplefrom types import SimpleNamespace+from hardware import require+require("ext")from exllamav3.generator.cpu_cache import CPUPageCachefrom 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.pyindex 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 # noqafrom exllamav3.modules.quant.exl3 import dec_workspacefrom exllamav3.modules.block_sparse_mlp_routing import _routing_nogroup_torchdiff --git a/tests/test_dense_tune_seed.py b/tests/test_dense_tune_seed.pyindex 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, unittestsys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))+from hardware import require+require("ext")from exllamav3.model.dense_warmup import seed_dense_tunediff --git a/tests/test_device_copy_.py b/tests/test_device_copy_.pyindex 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, syssys.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 dcfrom exllamav3.util.device_copy import to_devicediff --git a/tests/test_disk_store_cpu.py b/tests/test_disk_store_cpu.pyindex 7bdee02..97c3501 100644--- a/tests/test_disk_store_cpu.py+++ b/tests/test_disk_store_cpu.py@@ -4,6 +4,8 @@ import timeimport torch+from hardware import require+require("ext")from exllamav3.util import disk_store as dsdiff --git a/tests/test_draft_head_blocks_.py b/tests/test_draft_head_blocks_.pyindex 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 = Noneimport torch+from hardware import require+require("ext")from exllamav3.architecture.qwen3_5_mtp import exl3_block_subheadfrom exllamav3.modules.quant.exl3 import LinearEXL3diff --git a/tests/test_ds41_k1_cpu.py b/tests/test_ds41_k1_cpu.pyindex b2f4dff..df7f591 100644--- a/tests/test_ds41_k1_cpu.py+++ b/tests/test_ds41_k1_cpu.py@@ -19,18 +19,41 @@ from unittest import mockimport pytestimport 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] = mROOT = 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.pyindex 4e9a97e..518a7b4 100644--- a/tests/test_dsa_kernels.py+++ b/tests/test_dsa_kernels.py@@ -13,6 +13,8 @@ import syssys.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_scoresfrom exllamav3.ext import exllamav3_ext as extdiff --git a/tests/test_dsv4_cached.py b/tests/test_dsv4_cached.pyindex 045108d..8eb13d2 100644--- a/tests/test_dsv4_cached.py+++ b/tests/test_dsv4_cached.py@@ -13,8 +13,12 @@ import syssys.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 pytestimport 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, Modelfrom exllamav3.cache.cache import Cachediff --git a/tests/test_dsv4_compress_kernel.py b/tests/test_dsv4_compress_kernel.pyindex b6c9546..0b8c891 100644--- a/tests/test_dsv4_compress_kernel.py+++ b/tests/test_dsv4_compress_kernel.py@@ -16,6 +16,8 @@ import syssys.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 extdiff --git a/tests/test_dsv4_state.py b/tests/test_dsv4_state.pyindex 31e0f2f..63976d5 100644--- a/tests/test_dsv4_state.py+++ b/tests/test_dsv4_state.py@@ -13,8 +13,12 @@ import syssys.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 pytestimport 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, Modelfrom exllamav3.modules.dsv4 import DSV4CompressorStatediff --git a/tests/test_embedding_mmap.py b/tests/test_embedding_mmap.pyindex 06d4afb..bc8b957 100644--- a/tests/test_embedding_mmap.py+++ b/tests/test_embedding_mmap.py@@ -1,5 +1,7 @@import os, torchfrom safetensors.torch import save_file+from hardware import require+require("ext")from exllamav3.loader.safetensors import SafetensorsCollectiondiff --git a/tests/test_expert_store_mixedk_cpu.py b/tests/test_expert_store_mixedk_cpu.pyindex 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 npimport torch+from hardware import require+require("ext")import exllamav3.modules.quant.exl3 as exl3modfrom exllamav3.modules import expert_store as esfrom exllamav3.modules.moe_mixedk import MixedKStore, expert_ksdiff --git a/tests/test_ext_norm_.py b/tests/test_ext_norm_.pyindex ab4bab9..f3e1935 100644--- a/tests/test_ext_norm_.py+++ b/tests/test_ext_norm_.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("gpu", "ext")from exllamav3.ext import exllamav3_ext as exttorch.set_printoptions(precision = 5, sci_mode = False, linewidth = 200)diff --git a/tests/test_ext_routing_.py b/tests/test_ext_routing_.pyindex 5241834..0d053f1 100644--- a/tests/test_ext_routing_.py+++ b/tests/test_ext_routing_.py@@ -11,6 +11,8 @@ import pytestimport torchimport torch.nn.functional as Fsys.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 indiff --git a/tests/test_ext_sampling_edges_.py b/tests/test_ext_sampling_edges_.pyindex 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 odimport os, sysimport torchsys.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 extdevice = "cuda:0"diff --git a/tests/test_ext_strings_.py b/tests/test_ext_strings_.pyindex 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 oimport os, sysimport numpy as npsys.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 extfrom exllamav3.generator.job import _strings_to_utf32diff --git a/tests/test_failure_containment.py b/tests/test_failure_containment.pyindex 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 ArgmaxSamplerfrom exllamav3.generator.generator import Generatorfrom exllamav3.generator.async_generator import AsyncGeneratordiff --git a/tests/test_gdn_rewind_batch_.py b/tests/test_gdn_rewind_batch_.pyindex f01d2fb..e289465 100644--- a/tests/test_gdn_rewind_batch_.py+++ b/tests/test_gdn_rewind_batch_.py@@ -7,6 +7,8 @@ import os, syssys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))from types import SimpleNamespaceimport torch+from hardware import require+require("ext")from exllamav3.modules import gated_delta_net as gdndev = torch.device("cuda:0")diff --git a/tests/test_gemm_rows24.py b/tests/test_gemm_rows24.pyindex 39b2ca8..bafc570 100644--- a/tests/test_gemm_rows24.py+++ b/tests/test_gemm_rows24.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport 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 tilesdiff --git a/tests/test_gemv_pair_.py b/tests/test_gemv_pair_.pyindex 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, syssys.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 extmode = 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_.pyindex 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, inspectsys.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, ArgmaxSamplerDEFAULT_MODEL = "/mnt/str/models/qwen3.5-0.8b/exl3/2.00bpw/"diff --git a/tests/test_glm_dec2.py b/tests/test_glm_dec2.pyindex 483596a..92ca21d 100644--- a/tests/test_glm_dec2.py+++ b/tests/test_glm_dec2.py@@ -27,6 +27,8 @@ import pytestimport torchsys.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: E402DEV = "cuda:0"diff --git a/tests/test_hgemm_f16acc.py b/tests/test_hgemm_f16acc.pyindex da75878..a15633a 100644--- a/tests/test_hgemm_f16acc.py+++ b/tests/test_hgemm_f16acc.py@@ -2,6 +2,8 @@import pytestimport torch+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extdiff --git a/tests/test_hip_add_sigmoid_gate_proj.py b/tests/test_hip_add_sigmoid_gate_proj.pyindex 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 annotationsimport pytestimport torch+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extdiff --git a/tests/test_hip_block_graph.py b/tests/test_hip_block_graph.pyindex 69a525e..119c238 100644--- a/tests/test_hip_block_graph.py+++ b/tests/test_hip_block_graph.py@@ -8,6 +8,8 @@ from pathlib import Pathimport pytestimport torch+from hardware import require+require("ext")from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizerfrom exllamav3.modules import block_graphfrom exllamav3.modules.block_graph import BlockGraphRunner, maybe_graph_forwarddiff --git a/tests/test_hip_dec_glm_gates.py b/tests/test_hip_dec_glm_gates.pyindex 6d13474..ee4d2cc 100644--- a/tests/test_hip_dec_glm_gates.py+++ b/tests/test_hip_dec_glm_gates.py@@ -26,6 +26,8 @@ import pytestimport torchsys.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: E402HIDDEN = 512 # % 512 == 0 (exl3_dec_moe requirement)diff --git a/tests/test_hip_gemv_decode.py b/tests/test_hip_gemv_decode.pyindex e363641..c503c2e 100644--- a/tests/test_hip_gemv_decode.py+++ b/tests/test_hip_gemv_decode.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("ext")from exllamav3 import Config, Modelfrom exllamav3.ext import exllamav3_ext as extfrom exllamav3.modules.quant import exl3 as exl3_quantdiff --git a/tests/test_hip_gemv_k5_flash.py b/tests/test_hip_gemv_k5_flash.pyindex fa01bfe..f2a585f 100644--- a/tests/test_hip_gemv_k5_flash.py+++ b/tests/test_hip_gemv_k5_flash.py@@ -8,6 +8,8 @@ import pytestimport torchfrom hip_flash_quant import exl3_expert_quant+from hardware import require+require("ext")from exllamav3 import Config, Modelfrom exllamav3.ext import exllamav3_ext as extdiff --git a/tests/test_hip_grouped_moe_flash_oracle.py b/tests/test_hip_grouped_moe_flash_oracle.pyindex 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 Pathimport pytestimport torch+from hardware import require+require("ext")from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizerfrom exllamav3.ext import exllamav3_ext as extfrom exllamav3.modules.block_sparse_mlp import BlockSparseMLPdiff --git a/tests/test_hip_grouped_moe_k3.py b/tests/test_hip_grouped_moe_k3.pyindex 598cd36..20efdd9 100644--- a/tests/test_hip_grouped_moe_k3.py+++ b/tests/test_hip_grouped_moe_k3.py@@ -11,6 +11,8 @@ import torchfrom safetensors.torch import save_filefrom hip_flash_quant import exl3_expert_quant+from hardware import require+require("ext")from exllamav3 import Config, Modelfrom exllamav3.ext import exllamav3_ext as extfrom exllamav3.model.lora import LoRAdiff --git a/tests/test_hip_hc_mix.py b/tests/test_hip_hc_mix.pyindex d7b8ad3..cbfb8ed 100644--- a/tests/test_hip_hc_mix.py+++ b/tests/test_hip_hc_mix.py@@ -7,6 +7,8 @@ import pytestimport torchimport torch.nn.functional as F+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extfrom exllamav3.modules import hyperconnections as hcdiff --git a/tests/test_hip_prefill_rows_oracle.py b/tests/test_hip_prefill_rows_oracle.pyindex 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 Pathimport pytestimport torch+from hardware import require+require("ext")from exllamav3 import Cache, Config, Generator, GreedySampler, Job, Model, Tokenizerfrom exllamav3.ext import exllamav3_ext as extfrom exllamav3.modules.block_sparse_mlp import BlockSparseMLPdiff --git a/tests/test_job_params.py b/tests/test_job_params.pyindex a22e89b..213f3f4 100644--- a/tests/test_job_params.py+++ b/tests/test_job_params.py@@ -1,6 +1,8 @@import os, sys, unittestimport torchsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.generator.job import Jobdiff --git a/tests/test_kernel_seed.py b/tests/test_kernel_seed.pyindex 92ac5d0..2178d06 100644--- a/tests/test_kernel_seed.py+++ b/tests/test_kernel_seed.py@@ -2,6 +2,8 @@import json, os, subprocess, sys, tempfilefrom pathlib import Pathsys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))+from hardware import require+require("ext")from exllamav3.util import kernel_seedREPO = str(Path(__file__).resolve().parents[1])diff --git a/tests/test_kv_quant.py b/tests/test_kv_quant.pyindex 16f4f73..6e30a14 100644--- a/tests/test_kv_quant.py+++ b/tests/test_kv_quant.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("gpu", "ext")from exllamav3.ext import exllamav3_ext as extimport randomdiff --git a/tests/test_kvwin.py b/tests/test_kvwin.pyindex 22120d6..1f4acd9 100644--- a/tests/test_kvwin.py+++ b/tests/test_kvwin.py@@ -14,6 +14,8 @@ import pytestpytestmark = 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_quantfrom exllamav3.cache import kvwinfrom exllamav3.cache.kvwin import KVWinLayerState, KVWinCtx, KVWinCfg, ring_rows, ring_positions, ov_write_ref, parse_specdiff --git a/tests/test_mla.py b/tests/test_mla.pyindex 242ef2f..bc30d50 100644--- a/tests/test_mla.py+++ b/tests/test_mla.py@@ -4,6 +4,8 @@ import mathimport pytestimport torch+from hardware import require+require("ext")from exllamav3.modules import MLAttentionfrom exllamav3.cache import CacheLayer_MLA_fp16from exllamav3.constants import PAGE_SIZEdiff --git a/tests/test_mla_dsa.py b/tests/test_mla_dsa.pyindex 15c9a06..d8abec8 100644--- a/tests/test_mla_dsa.py+++ b/tests/test_mla_dsa.py@@ -5,6 +5,8 @@ import pytestimport torchimport torch.nn.functional as F+from hardware import require+require("ext")from exllamav3.modules import MLAttentionfrom exllamav3.cache import CacheLayer_MLA_fp16, CacheLayer_MLA_quantfrom exllamav3.ext import exllamav3_ext as extdiff --git a/tests/test_model_tp_signals.py b/tests/test_model_tp_signals.pyindex 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 patchsys.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_fndiff --git a/tests/test_moe_coop.py b/tests/test_moe_coop.pyindex dfbd9f7..02afe3f 100644--- a/tests/test_moe_coop.py+++ b/tests/test_moe_coop.py@@ -10,6 +10,8 @@ reconstructed weights.import osimport pytestimport torch+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extpytestmark = 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_.pyindex 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 whicimport os, sysimport pytestsys.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 extpytestmark = pytest.mark.skipif(diff --git a/tests/test_moe_cpu_tiers_.py b/tests/test_moe_cpu_tiers_.pyindex 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, tempfilesys.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 _extpytestmark = pytest.mark.skipif(not hasattr(_ext, "exl3_moe_cpu_has_avx2"),diff --git a/tests/test_moe_foreign.py b/tests/test_moe_foreign.pyindex 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: E402import exllamav3.modules.foreign_linear as fl_mod # noqa: E402from exllamav3.modules.block_sparse_mlp import BlockSparseMLP # noqa: E402diff --git a/tests/test_moe_mixedk_cpu.py b/tests/test_moe_mixedk_cpu.pyindex 4028c92..23976d3 100644--- a/tests/test_moe_mixedk_cpu.py+++ b/tests/test_moe_mixedk_cpu.py@@ -26,6 +26,8 @@ import pytestimport torchimport 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.pyindex 7956d0b..a4167ec 100644--- a/tests/test_moe_sync_free_count.py+++ b/tests/test_moe_sync_free_count.py@@ -1,5 +1,7 @@import pytestimport 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.pyindex 3b274ad..70b5b56 100644--- a/tests/test_multimodal_rewind_prefill.py+++ b/tests/test_multimodal_rewind_prefill.py@@ -14,6 +14,8 @@ import torchsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.constants import PAGE_SIZEfrom exllamav3.generator.job import Jobfrom exllamav3.tokenizer import MMEmbeddingdiff --git a/tests/test_ngram_prefetch_.py b/tests/test_ngram_prefetch_.pyindex 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 = 248044DEV = torch.device("cuda:0")+from hardware import require+require("ext")from exllamav3.loader.safetensors import SafetensorsCollectionfrom exllamav3.modules import NGramEmbeddingfrom exllamav3.modules import ngram_embedding as nediff --git a/tests/test_padded_vocab.py b/tests/test_padded_vocab.pyindex 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, unittestsys.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_samplefrom exllamav3.generator.generator import Generatorfrom exllamav3.generator.job import Jobdiff --git a/tests/test_pf_split_plan.py b/tests/test_pf_split_plan.pyindex 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, typessys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))+from hardware import require+require("ext")from exllamav3.generator.job import Jobfrom exllamav3.generator.pagetable import PAGE_SIZEdiff --git a/tests/test_plain_rows_cpu.py b/tests/test_plain_rows_cpu.pyindex 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_verifyfrom exllamav3.util.row_inv import ROW_INV, ROW_INV_MAX_ROWSdiff --git a/tests/test_ple_stash_clone.py b/tests/test_ple_stash_clone.pyindex ee0e71b..881b859 100644--- a/tests/test_ple_stash_clone.py+++ b/tests/test_ple_stash_clone.py@@ -7,6 +7,8 @@ import os, sysfrom types import SimpleNamespaceimport torchsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.modules.ple import PLELayerStatediff --git a/tests/test_prefill_block_table_cpu.py b/tests/test_prefill_block_table_cpu.pyindex 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_SIZEfrom exllamav3.generator.generator import block_table_pagesfrom exllamav3.generator.pagetable import Sequencediff --git a/tests/test_prefill_ck.py b/tests/test_prefill_ck.pyindex 86939c9..ac6f882 100644--- a/tests/test_prefill_ck.py+++ b/tests/test_prefill_ck.py@@ -4,6 +4,8 @@ import torchpytestmark = 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.pyindex b19d218..68ba034 100644--- a/tests/test_prefill_ck_fallback.py+++ b/tests/test_prefill_ck_fallback.py@@ -1,6 +1,8 @@import pytestimport torch+from hardware import require+require("ext")from exllamav3.modules.attention_fn import triton_paged as tpdiff --git a/tests/test_prefill_fa2_rows.py b/tests/test_prefill_fa2_rows.pyindex 5fb5cf4..4b0e84e 100644--- a/tests/test_prefill_fa2_rows.py+++ b/tests/test_prefill_fa2_rows.py@@ -3,6 +3,8 @@ import torchpytestmark = 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 tpdiff --git a/tests/test_prefill_row_slice.py b/tests/test_prefill_row_slice.pyindex eb1ce60..a7e347a 100644--- a/tests/test_prefill_row_slice.py+++ b/tests/test_prefill_row_slice.py@@ -10,6 +10,8 @@ import torchpytestmark = 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 tpPAGE = 256diff --git a/tests/test_prefill_waves_per_eu.py b/tests/test_prefill_waves_per_eu.pyindex 27558bc..7d293be 100644--- a/tests/test_prefill_waves_per_eu.py+++ b/tests/test_prefill_waves_per_eu.py@@ -9,6 +9,8 @@ import torchpytestmark = 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 tpPAGE = 256diff --git a/tests/test_qdec_hip.py b/tests/test_qdec_hip.pyindex 811aee4..30d55cd 100644--- a/tests/test_qdec_hip.py+++ b/tests/test_qdec_hip.py@@ -4,6 +4,8 @@ import argparse, math, os, sys, timeos.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 tpap = argparse.ArgumentParser()diff --git a/tests/test_qgemm.py b/tests/test_qgemm.pyindex c9564dd..0120f2f 100644--- a/tests/test_qgemm.py+++ b/tests/test_qgemm.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("ext")from exllamav3 import Config, Modeltorch.set_printoptions(precision = 5, sci_mode = False, linewidth = 200)diff --git a/tests/test_quant_fn.py b/tests/test_quant_fn.pyindex f60762c..cef04e5 100644--- a/tests/test_quant_fn.py+++ b/tests/test_quant_fn.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("ext")from exllamav3 import Config, Modelfrom exllamav3.ext import exllamav3_ext as extfrom exllamav3.modules.quant.exl3_lib.quantize import quantize_tilesdiff --git a/tests/test_qwrite.py b/tests/test_qwrite.pyindex 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, timesys.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 fbdev = torch.device("cuda"); torch.manual_seed(0)diff --git a/tests/test_rope.py b/tests/test_rope.pyindex f7ede21..3c771a7 100644--- a/tests/test_rope.py+++ b/tests/test_rope.py@@ -2,6 +2,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport torch+from hardware import require+require("gpu", "ext")from exllamav3.ext import exllamav3_ext as extfrom exllamav3.util.rope import RoPE, RopeStyle, RopeSettingsimport torch.testingdiff --git a/tests/test_rope_yarn.py b/tests/test_rope_yarn.pyindex 23a1e36..06ba549 100644--- a/tests/test_rope_yarn.py+++ b/tests/test_rope_yarn.py@@ -6,6 +6,8 @@ import pytestsys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.util.rope import RoPE, RopeSettingsdiff --git a/tests/test_row_groups_cpu.py b/tests/test_row_groups_cpu.pyindex 734b3ec..9ef6fba 100644--- a/tests/test_row_groups_cpu.py+++ b/tests/test_row_groups_cpu.py@@ -9,6 +9,8 @@ import typesimport pytestimport torch+from hardware import require+require("ext")from exllamav3.generator import row_groups as RGfrom exllamav3.generator.generator import Generatorfrom exllamav3.util.row_inv import ROW_INV_MAX_ROWSdiff --git a/tests/test_row_invariance_cpu.py b/tests/test_row_invariance_cpu.pyindex e24d297..bfd9633 100644--- a/tests/test_row_invariance_cpu.py+++ b/tests/test_row_invariance_cpu.py@@ -7,6 +7,8 @@ import osimport torchimport pytest+from hardware import require+require("ext")from exllamav3.util.row_inv import ROW_INV, ROW_INV_MAX_ROWSfrom exllamav3.modules import block_sparse_mlp_routing as Rfrom exllamav3.modules.mla_attn import MLAttention, _rowloop_maxdiff --git a/tests/test_row_slices_cpu.py b/tests/test_row_slices_cpu.pyindex 9951f46..8ebc99c 100644--- a/tests/test_row_slices_cpu.py+++ b/tests/test_row_slices_cpu.py@@ -2,6 +2,8 @@import pytestimport torch+from hardware import require+require("ext")from exllamav3.modules import block_sparse_mlp as Bfrom exllamav3.util.row_inv import ROW_INV_MAX_ROWSdiff --git a/tests/test_sampler.py b/tests/test_sampler.pyindex 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 pytestimport numpy as npimport torch+from hardware import require+require("ext")from exllamav3.ext import exllamav3_ext as extfrom exllamav3 import (TopKSampler,diff --git a/tests/test_spec_sample.py b/tests/test_spec_sample.pyindex 521205c..b595362 100644--- a/tests/test_spec_sample.py+++ b/tests/test_spec_sample.py@@ -7,6 +7,8 @@ import os, sys, math, random, unittestos.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 ssfrom exllamav3.generator.sampler import ComboSampler, ArgmaxSamplerdiff --git a/tests/test_tail_ckpt_rows.py b/tests/test_tail_ckpt_rows.pyindex 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, typessys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))+from hardware import require+require("ext")from exllamav3.generator.job import Jobfrom exllamav3.generator.pagetable import PAGE_SIZEdiff --git a/tests/test_tail_page_usable_.py b/tests/test_tail_page_usable_.pyindex 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, typessys.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_usableids = torch.arange(100).view(1, -1)diff --git a/tests/test_tokenizer_decode_specials.py b/tests/test_tokenizer_decode_specials.pyindex a6c4a15..03b7e35 100644--- a/tests/test_tokenizer_decode_specials.py+++ b/tests/test_tokenizer_decode_specials.py@@ -1,5 +1,7 @@import os, sys, unittestsys.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 calldiff --git a/tests/test_tp_export_attention.py b/tests/test_tp_export_attention.pyindex 35b8e08..b6ee09a 100644--- a/tests/test_tp_export_attention.py+++ b/tests/test_tp_export_attention.py@@ -7,6 +7,8 @@ import sys, os, unittestfrom unittest.mock import patchimport torchsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+from hardware import require+require("ext")from exllamav3.modules.attn import Attentionfrom exllamav3.modules.sliding_attn import SlidingAttentiondiff --git a/tests/test_tq_cache.py b/tests/test_tq_cache.pyindex f8ebdf0..74a8c57 100644--- a/tests/test_tq_cache.py+++ b/tests/test_tq_cache.py@@ -11,6 +11,8 @@ import torchsys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))import pytest+from hardware import require+require("ext")from exllamav3.cache import tqfrom exllamav3.cache.kvwin import KVWinLayerState, KVWinCtx, KVWinCfg, parse_specdiff --git a/tests/test_triton_paged_hdpad.py b/tests/test_triton_paged_hdpad.pyindex 411c56b..f569177 100644--- a/tests/test_triton_paged_hdpad.py+++ b/tests/test_triton_paged_hdpad.py@@ -8,6 +8,8 @@ import sys, ossys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import pytestimport 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.pyindex 2680022..25aac4b 100644--- a/tests/test_triton_paged_overflow.py+++ b/tests/test_triton_paged_overflow.py@@ -7,6 +7,8 @@ import torchsys.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_prefilldiff --git a/tests/test_vision_pinned_no_stale_weights.py b/tests/test_vision_pinned_no_stale_weights.pyindex 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 pytestimport torchfrom PIL import Image+from hardware import require+require("ext")from exllamav3 import Config, Model, Tokenizerfrom exllamav3.modules import Linearfrom exllamav3.util.memory import free_memdiff --git a/tools/qualify/backends.py b/tools/qualify/backends.pyindex 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 theengine 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 globimport subprocessif PYTHON:@@ -55,6 +55,8 @@ def find_python(backend: str, repo: str | None = None) -> str:return cexcept Exception: # noqa: BLE001continue+ if not required:+ return Noneraise SystemExit(f"no python with a {attr} torch found (set QUALIFY_PYTHON)")diff --git a/tools/qualify/qualify.py b/tools/qualify/qualify.pyindex 73e9b98..a32701a 100644--- a/tools/qualify/qualify.py+++ b/tools/qualify/qualify.py@@ -24,19 +24,30 @@ import report # noqa: E402import 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 Nonefor 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 0log = 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.pyindex 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):