Skip to content

fix(tests,jit): repair false-green gates and report the real ninja failure - #3525

Merged
Qubitium merged 3 commits into
mainfrom
fix/test-gates-and-jit-ninja
Nov 4, 2026
Merged

Qubitium merged 3 commits into
mainfrom
fix/test-gates-and-jit-ninja

Conversation

@ZX-ModelCloud

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

Copy link
Copy Markdown
Collaborator

Summary

Four test-gating and diagnostic defects, plus one audit finding that was already
fixed upstream. Each item was reproduced on real hardware before anything was
changed, and the one review finding that proved real was fixed and re-verified.

Area Verdict
Test setup binding in tests/kernels/test_intel_cpu_xpu.py Confirmed, fixed
Weak hardware gates in tests/kernels/test_asymmetric_real_models.py Confirmed, fixed (also Marlin/ROCm)
Stale GGUFCudaKernel assertion in tests/kernels/test_selection.py Confirmed, fixed + process-abort hazard found
Misleading Ninja is required JIT error in gptqmodel/utils/cpp.py Confirmed, fixed
Expanded E4M3 weight plane assertion in tests/kernels/test_w4a_nvfp4_gb10.py Already fixed upstream by #3492

Changes

Test setup was bound to the class, not the instance

tests/kernels/test_intel_cpu_xpu.py decorated setUp with @classmethod, so
unittest passed the class as self and self.forward(self.torch_model, ...)
bound unbound:

TypeError: forward() missing 1 required positional argument: 'x'

6 failed before, 8 passed after (2x RTX 4090).

Hardware gates relied on torch.cuda.is_available()

tests/kernels/test_asymmetric_real_models.py gated Machete cases only on
torch.cuda.is_available(), but Machete is Hopper-only (SM90, and >=204800
bytes opt-in shared memory), so all four failed on an SM89 4090. The cases now
ask each kernel's own runtime check instead of re-deriving capability:

  • machete_runtime_error()
  • marlin_runtime_error() — Marlin is CUDA-only and also failed on ROCm, where
    torch.cuda.is_available() is True (same class of gate error)

Result: 2 passed / 4 skipped on the 4090 and on AMD GPUs 2,3.

Selection assertion contradicted the kernel contract

tests/kernels/test_selection.py asserted GGUFCudaKernel not in candidates,
but #3434 added bits 1/2/3 to that kernel, leaving the assertion stale. Verified
against an independent Torch GGUF oracle on the 4090 that every AUTO-routed
qtype agrees with the Triton/Torch reference:

qtype max abs diff (fp16)
Q1_0 4.88e-4
IQ1_S, IQ1_M 1.95e-3 / 9.77e-4
Q2_K, Q2_0, IQ2_* <= 1.95e-3
Q4_0..Q8_0, Q4_K..Q6_K <= 1.95e-3

The assertion now requires GGUFCudaKernel to appear only after
GGUFTritonKernel, keeping AUTO's Triton-first priority while allowing the CUDA
kernel as a fallback.

Additional hazard found while validating: TQ1_0 and TQ2_0 have no GPU
convert kernel, and ggml-cuda hits GGML_ASSERT(convert_func != nullptr), which
aborts the whole interpreter rather than raising — yet GGUFCudaKernel
advertises bits 1/2. The guard is a CUDA-only reject set:

_GGML_CPU_MATMUL_UNSUPPORTED  = frozenset({"Q8_1", "Q8_K"})
_GGML_CUDA_MATMUL_UNSUPPORTED = _GGML_CPU_MATMUL_UNSUPPORTED | frozenset({"TQ1_0", "TQ2_0"})

The CPU-side Q8_1/Q8_K guard already exists on main (gguf_cpp.py:715);
this PR only extends the mechanism to the CUDA backend, which is where the
process-abort hazard lives. The CPU path handles TQ1_0/TQ2_0 correctly
(maxdiff 0.0 vs the Torch oracle), so the sets are deliberately split and a CPU
regression test pins that split.

The CUDA rejection moved into the constructor

Review on real hardware showed the first version of this guard did not produce
the fallback it claimed. select_quant_linear validates candidates by bits
only, so it cannot see the GGUF qtype and GGUFCudaKernel stayed a legitimate
AUTO candidate for ternary weights. GGUFTritonKernel already rejects those
types in __init__, so create_quant_layer fell through to GGUFCudaKernel,
which constructed successfully — the guard lived in quantized_matmul_cuda,
i.e. the first forward. Since create_quant_layer only retries the next AUTO
candidate on a NotImplementedError raised during construction, there was no
runtime fallback at all: the layer was built and then failed during inference.

GGUFCudaKernel.__init__ now raises NotImplementedError for
_GGML_CUDA_MATMUL_UNSUPPORTED, matching the precedent in GGUFTritonKernel,
and the quantized_matmul_cuda check stays as defence in depth. Through the
real loader path on 2x RTX 4090:

tq1_0: AUTO first choice = GGUFTritonKernel
   GGUFTritonKernel construction rejected -> next
   GGUFCudaKernel construction rejected -> next
tq1_0: create_quant_layer would pick GGUFTorchLinear
tq1_0: FORWARD OK shape=(9, 48)
tq2_0: AUTO first choice = GGUFCudaKernel
   GGUFCudaKernel construction rejected -> next
tq2_0: create_quant_layer would pick GGUFTorchLinear
tq2_0: FORWARD OK shape=(9, 48)

Test coverage was corrected alongside it:

  • test_gguf_cuda_kernel_rejects_qtypes_without_gpu_kernels asserted the
    rejection happened at forward, which encoded the bug. It now requires the
    explicit constructor call to raise.
  • New test_gguf_auto_selection_falls_back_to_torch_for_ternary covers the AUTO
    path that the explicit-constructor test cannot reach. It mirrors
    create_quant_layer: build candidates in priority order, skip constructor
    rejections, and require the selection to land on GGUFTorchLinear with a
    working forward. It asserts on the constructed outcome rather than on the
    multi_select candidate list, because that list is bits-based and
    GGUFCudaKernel legitimately remains a candidate.

JIT failure reported the symptom instead of the cause

An ExLlamaV2 JIT failure surfaced Ninja is required to load C++ extensions
verbatim while the real cause was ninja living in $CONDA_PREFIX/bin with
that bin directory missing from PATH. Reproduced both directions: fails without
the env bin on PATH, builds in 20s with it.

gptqmodel/utils/cpp.py diagnostics now report shutil.which("ninja") /
shutil.which("cmake") resolution and versions, a $CONDA_PREFIX PATH hint,
and an actionable hint naming the missing PATH entry, instead of only echoing
the upstream exception.

Expanded-weight assertion is already fixed upstream

tests/kernels/test_w4a_nvfp4_gb10.py asserted
_weight_e4m3.numel() == in * out, which encoded the expanded-cache violation
as expected behavior. #3492 already moved NVFP4 to stage the E4M3 operand per
forward, so the audit finding was against a branch 22 commits behind
origin/main. No change is needed here.

Validation

All GPU runs are non-sandboxed on the host, with the worktree first on
PYTHONPATH so the editable package under test is the one being measured.

Environment Result
2x RTX 4090, touched suites (test_selection, test_gguf_cpp, test_torch_ops_jit_extension, test_intel_cpu_xpu, test_asymmetric_real_models, test_w4a_nvfp4_gb10) 218 passed / 81 skipped
tests/kernels/test_gguf_cpp.py alone (all CUDA cases executed, none skipped) 25 passed
tests/test_gguf_all_formats.py (with llama-cpp CUDA runtime) 271 passed / 429 skipped
ROCm, AMD GPUs 2,3 only Same skips, no new failures

The GGUF CUDA suites need LD_LIBRARY_PATH pointed at a nvidia/*/lib tree:
this env's llama_cpp links libcudart.so.12 while the env ships CUDA 13.2, so
import llama_cpp fails otherwise. That is an environment quirk, not a PR
defect, but it means the GGUF rows are only reproducible with the shim:

LD_LIBRARY_PATH=$CONDA_PREFIX/../gp_314t_vllm091/lib/python3.12/site-packages/nvidia/cuda_runtime/lib:$LD_LIBRARY_PATH

Pre-existing failures, reproduced on unmodified main via git stash:

  • tests/test_extension_load_api.py::test_load_defaults_to_all_extensions
  • 2 ROCm test_selection.py cases

ruff check clean on all touched files. ruff format --check reports a
pre-existing multiline-list difference in gguf_cpp.py that is present at
HEAD and unrelated to these edits, so it is left alone.

Storage-gate note

No inference path retains a dense or expanded weight cache. The GGUF guard now
rejects unsupported qtypes at construction, before any graph or tensor is built.

…ilure

Five audited P0/P1 items; each was reproduced on hardware before changing it.

B1 test_intel_cpu_xpu.py: `setUp` was a @classmethod, so unittest passed the
class as `self` and `self.forward(self.torch_model, ...)` bound unbound:
6x `TypeError: forward() missing 1 required positional argument: 'x'`. Drop
the decorator; 8 passed on 2x RTX 4090 (was 6 failed / 2 passed).

B2 test_asymmetric_real_models.py: Machete is Hopper-only (SM90, and >=204800
bytes opt-in shared memory), but the cases only gated on
`torch.cuda.is_available()`, so all four failed on an SM89 4090. Gate on the
kernels' own runtime checks instead: `machete_runtime_error()`, plus
`marlin_runtime_error()` for Marlin, which is CUDA-only and also failed on
ROCm (where `torch.cuda.is_available()` is True). 2 passed / 4 skipped on the
4090 and on ROCm GPUs 2,3.

B3 test_selection.py asserted `GGUFCudaKernel not in candidates`, but #3434
added bits 1/2/3 to that kernel, so the assertion was stale and contradicted
the implementation. Verified against an independent Torch GGUF oracle on the
4090 that all routed qtypes agree: Q1_0 maxdiff 4.88e-4, IQ1_S/IQ1_M 1.95e-3,
Q2_K/Q2_0/IQ2_* <= 1.95e-3, Q4-Q8 <= 1.95e-3 (fp16, atol 8e-2). Update the
assertion to require the kernel only after Triton.

Found while validating B3: TQ1_0 and TQ2_0 have no GPU convert kernel, and
ggml-cuda hits `GGML_ASSERT(convert_func != nullptr)`, which aborts the whole
interpreter rather than raising. The CPU backend does support them, so add a
CUDA-only reject set (sharing the existing Q8_1/Q8_K CPU set) and raise
`NotImplementedError` before any graph is built. Add CUDA oracle coverage for
1-bit/2-bit and a CPU ternary regression test that pins the set split.

B4 utils/cpp.py surfaced `Ninja is required to load C++ extensions` verbatim
while the real cause was ninja living in `$CONDA_PREFIX/bin` with that bin
directory missing from PATH. Reproduced both ways on ExLlamaV2 (JIT fails
without the env bin on PATH, builds in 20s with it). Add ninja/cmake
resolution, versions, `$CONDA_PREFIX` PATH hint, and an actionable hint to the
JIT failure diagnostics.

B5 test_w4a_nvfp4_gb10.py asserted `_weight_e4m3.numel() == in*out`, encoding
the expanded-cache violation as expected behavior. Already fixed upstream by
#3492 (NVFP4 stages the E4M3 operand per forward); the audit ran a branch 22
commits behind origin/main and no change is needed here.

Validation: 197 passed / 48 skipped for the touched CUDA suites on 2x RTX
4090; 271 passed / 429 skipped for tests/test_gguf_all_formats.py with the
llama-cpp CUDA runtime present; ROCm (GPUs 2,3) shows the same skips and no
new failures. A pre-existing `test_load_defaults_to_all_extensions` failure
and two pre-existing ROCm selection failures also fail on unmodified main.

ZX-ModelCloud commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Request changes — the new CUDA guard fires too late for AUTO

Verified on real hardware (2x RTX 4090, worktree fix-test-gates @ a2a06aa). Four of the five sections check out. The CUDA guard is real protection, but it does not achieve the fallback claimed in the description.

Blocking: AUTO still selects GGUFCudaKernel for TQ1_0/TQ2_0

select_quant_linear validates by bits only; it cannot see the qtype. GGUFTritonKernel rejects TQ in __init__, so create_quant_layer falls through to GGUFCudaKernel, which constructs fine. The guard is in quantized_matmul_cuda, i.e. first forward, and create_quant_layer only retries on NotImplementedError from construction — so no runtime fallback exists.

Through the real loader entry point make_quant (CUDA):

q1_0: make_quant -> GGUFTritonKernel                forward OK
tq1_0: make_quant -> GGUFCudaKernel   FORWARD FAIL: NotImplementedError ... use BACKEND.GGUF_TORCH instead.
tq2_0: make_quant -> GGUFCudaKernel   FORWARD FAIL: NotImplementedError ...

select_quant_linear(multi_select=True): tq1_0 -> [GGUFTritonKernel, GGUFCudaKernel, GGUFTorchLinear], tq2_0 -> [GGUFCudaKernel, GGUFTorchLinear].

So the class comment "…so AUTO/GGUF_TORCH must stay available as the fallback" and the body line "rejects unsupported qtypes before graph construction" both overstate it: rejection happens before graph construction but after kernel selection.

For contrast, main (ca5255805) has no CUDA-side guard and make_quant on tq1_0 aborts the interpreter (GGML_ASSERT(convert_func != nullptr), exit 134). Direction is right; scope is wrong.

Fix — reject in GGUFCudaKernel.__init__ (as GGUFTritonKernel already does), keeping the runtime guard as defence in depth:

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    if self.gguf_tensor_qtype in _GGML_CUDA_MATMUL_UNSUPPORTED:
        raise NotImplementedError(
            f"ggml CUDA matmul does not support `{self.gguf_tensor_qtype}` weights; "
            "use BACKEND.GGUF_TORCH instead."
        )

I monkeypatched exactly this and re-ran the same script — AUTO falls back and forward succeeds:

q1_0: chosen=GGUFTritonKernel forward OK
tq1_0: chosen=GGUFTorchLinear forward OK
tq2_0: chosen=GGUFTorchLinear forward OK

GGUFTorchLinear.SUPPORTS_BITS already contains 1/2 and its TQ dequant is correct, so the fallback is sound.

Also add AUTO-path coverage: test_gguf_cuda_kernel_rejects_qtypes_without_gpu_kernels builds the CUDA kernel explicitly, so it cannot catch this. An assertion that auto-selection never picks GGUFCudaKernel for TQ1_0/TQ2_0 fails today and passes with the constructor reject.

Minor

  • The Q8_1/Q8_K CPU guard already exists on main (gguf_cpp.py:715); this PR only extends it to CUDA. Reword the table to avoid over-crediting.
  • gp_314t's llama_cpp links libcudart.so.12 while the env is cu13, so import llama_cpp fails. I ran the GGUF suite with LD_LIBRARY_PATH pointing at another env's nvidia/*/lib; not a PR defect, but the Validation row is not reproducible as-is.

Verified as correct

  • test_intel_cpu_xpu.py: 13 passed / 8 skipped (2x4090); main has the @classmethod at line 74.
  • Machete/Marlin gates: 4090 machete → "Hopper-only (SM90)", marlin → ""; ROCm both → "not supported on ROCm" while torch.cuda.is_available() is True.
  • test_selection.py + test_torch_ops_jit_extension.py: 164 passed / 31 skipped; ruff check clean on all 7 files.
  • _toolchain_diagnostic_lines() does not trigger a JIT build; 3 new tests pass.
  • Bypassing the guard: TQ1_0/TQ2_0/Q8_1/Q8_K all SIGABRT at ggml-cuda.cu:1449, exit 134.
  • CPU TQ path: tq1_0, tq2_0, q1_0, q8_1, q8_k all maxdiff = 0.000e+00.
  • test_w4a_nvfp4_gb10.py has no diff vs origin/main; lines 262–267 assert not hasattr(module, "_weight_e4m3").
  • ROCm test_selection.py 2 failures reproduce on main-baseline (ca5255805).

Not verified: the full test_asymmetric_real_models.py run (needs Qwen/Qwen2.5-0.5B-Instruct-AWQ), so "2 passed / 4 skipped on the 4090" is unconfirmed; I only checked the gate return values.

Storage gate

No retained dense/expanded weight cache — the guard rejects before any graph or tensor is built. No objection.

`select_quant_linear` validates candidates by `bits` only, so it cannot see
the GGUF qtype. For TQ1_0/TQ2_0 it kept `GGUFCudaKernel` in the AUTO candidate
list; `GGUFTritonKernel` rejects those types in `__init__`, so
`create_quant_layer` fell through to `GGUFCudaKernel`, which constructed fine.
The existing guard lived in `quantized_matmul_cuda`, i.e. the first `forward`,
and `create_quant_layer` only retries the next AUTO candidate on a
`NotImplementedError` raised during construction. The result was no runtime
fallback at all: AUTO built the layer and then failed during inference, while
the class comment claimed GGUF_TORCH was the fallback.

Move the rejection into `GGUFCudaKernel.__init__`, matching the precedent in
`GGUFTritonKernel`, and keep the `quantized_matmul_cuda` check as defence in
depth. Verified on 2x RTX 4090 through the real loader entry point: AUTO now
resolves tq1_0/tq2_0 to `GGUFTorchLinear` and forward succeeds.

Update the explicit-constructor test to assert the constructor raises, and add
AUTO-path coverage that mirrors `create_quant_layer`: build candidates in
priority order, skip constructor rejections, and require the selection to land
on `GGUFTorchLinear` with a working forward. Asserting on the `multi_select`
candidate list would be wrong, since selection is bits-based and
`GGUFCudaKernel` legitimately remains a candidate.
@ZX-ModelCloud

ZX-ModelCloud commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

#3525 (comment)
The blocking finding was correct and I reproduced it independently before changing anything.

Confirmed: on a2a06aa8d, select_quant_linear(multi_select=True) returned
tq1_0 -> [GGUFTritonKernel, GGUFCudaKernel, GGUFTorchLinear] and
tq2_0 -> [GGUFCudaKernel, GGUFTorchLinear], and constructing GGUFCudaKernel
for either qtype succeeded — the guard only fired in quantized_matmul_cuda.
So create_quant_layer had nothing to catch, the layer was built, and the
failure surfaced at first forward. No runtime fallback existed.

Fixed in 48380834f: GGUFCudaKernel.__init__ now raises
NotImplementedError for _GGML_CUDA_MATMUL_UNSUPPORTED (the exact shape you
suggested, matching GGUFTritonKernel's precedent), and the
quantized_matmul_cuda check stays as defence in depth. Through the real loader
path on the 4090:

tq1_0: AUTO first choice = GGUFTritonKernel
   GGUFTritonKernel construction rejected -> next
   GGUFCudaKernel construction rejected -> next
tq1_0: create_quant_layer would pick GGUFTorchLinear
tq1_0: FORWARD OK shape=(9, 48)
tq2_0: AUTO first choice = GGUFCudaKernel
   GGUFCudaKernel construction rejected -> next
tq2_0: create_quant_layer would pick GGUFTorchLinear
tq2_0: FORWARD OK shape=(9, 48)

Test coverage — test_gguf_cuda_kernel_rejects_qtypes_without_gpu_kernels
previously asserted the forward-time rejection, i.e. it pinned the bug; it now
requires the constructor to raise. I also added
test_gguf_auto_selection_falls_back_to_torch_for_ternary, which mirrors
create_quant_layer — build candidates in priority order, skip constructor
rejections, require GGUFTorchLinear plus a working forward.

One note on your suggested assertion: "auto-selection never picks
GGUFCudaKernel" is only true of the constructed pick. The multi_select
candidate list is bits-based, so GGUFCudaKernel legitimately stays in it; the
first version of my new test asserted non-membership and failed for that reason.
The test now asserts the constructed outcome instead.

Minor points, both correct:

  • The Q8_1/Q8_K CPU guard does already exist on main (gguf_cpp.py:715);
    this PR only extends the mechanism to CUDA. I reworded the PR table so it
    no longer reads as a new CPU guard.
  • libcudart.so.12 vs the cu13 env is real — I reproduced
    libggml-cuda.so* -> libcudart.so.12 => not found. The Validation section now
    states the LD_LIBRARY_PATH shim is required for the GGUF CUDA rows rather
    than implying they run as-is.

Re-validation after the fix:

Run Result
test_selection, test_gguf_cpp, test_torch_ops_jit_extension, test_intel_cpu_xpu, test_asymmetric_real_models, test_w4a_nvfp4_gb10 218 passed / 81 skipped
test_gguf_cpp.py alone (no CUDA skips) 25 passed
ROCm, AMD GPUs 2,3 only same skips, no new failures

ruff check clean on both changed files.

Also noted: ruff format --check flags a multiline-list difference in
gguf_cpp.py, but that is present at HEAD and untouched by these commits.

@ZX-ModelCloud
ZX-ModelCloud marked this pull request as ready for review November 4, 2026 09:31

Qubitium commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Review of 48380834f: one remaining P2 issue.

Build failures are converted to test skips in tests/kernels/test_asymmetric_real_models.py:129–131. machete_runtime_error() and marlin_runtime_error() include extension compilation/loading failures, so unconditionally skipping their errors can hide regressions on supported GPUs. On an RTX 4090, injecting a Marlin compilation failure produced Skipped instead of a test failure. Use the candidate kernel's device-only validation for skipping, and let extension failures propagate through model loading.

The earlier GGUF constructor-fallback issue is fixed. I installed llama-cpp-python 0.3.36 with CUDA support and verified all 25 native GGUF tests pass without skips. Actual make_quant fallback for TQ1_0/TQ2_0 passed independent Torch checks in FP16/BF16/FP32 (maximum error 1.19e-7). JIT and selection suites: 163 passed / 32 skipped. Intel setup binding passed an in-memory check; full model validation was incomplete because the required model was uncached during the offline run.

Fixed and pushed in f3704eeb7. The gate now calls case.candidate_cls.validate_device(cuda:0) and skips only its NotImplementedError. Extension compilation/loading errors remain visible during model loading. Using the candidate class also preserves AWQ Marlin's compute-capability >= 8.0 requirement.

Added 21 regression cases covering Hopper, Ada, Blackwell, Turing, insufficient shared memory, ROCm, explicit target-device validation, and build-error propagation through the generation test entry point. Before the fix: 11 failed / 10 passed. After the fix, the regression, selection, JIT, and native GGUF suites report 211 passed / 30 skipped. The four Machete real-model cases still correctly skip on the RTX 4090. Ruff check, formatting check for the new test file, and git diff --check pass. This review finding is resolved.

@Qubitium
Qubitium merged commit 239bed0 into main Nov 4, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/test-gates-and-jit-ninja branch November 4, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants