Skip to content

test(gpu): repair the #4387, #5014 and #5020 host gates - #5138

Merged
Qubitium merged 1 commit into
mainfrom
fix/5113-test-red-gpu-hosts
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5113-test-red-gpu-hosts

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5113

Test-only fixes for three tests that were red on GPU hosts for test-side reasons. No product code changes.

Item 1 — test_gguf_cuda_weight_storage_4387.py::test_forward_leaves_one_device_copy_of_the_packed_weight[True]

Root cause. tests/kernels/test_gguf_cuda_weight_storage_4387.py:104 asserted memory_allocated() <= allocated_before - qweight.nbytes with zero slack. Since #5035 the biased GGUFCudaKernel dequantizes through GGUFTorchLinear, whose _u8_shift() (gptqmodel/nn_modules/qlinear/gguf.py:1506) caches the immutable (0, 4) uint8 shift table on the device (#5014). The 2-byte table occupies one 512-byte allocator block, so the first forward retains 512 B more than the exact bound.

Fix. tests/kernels/test_gguf_cuda_weight_storage_4387.py:112-130: allow the module's small cached constants (4 KiB, 18x below the 73 KiB packed weight), then call clear_weight_cache() and assert the exact allocated_before - nbytes bound. Anything the forward retained outside those derived caches still fails the exact assertion.

Before (GPU 0, this branch's parent):

FAILED tests/kernels/test_gguf_cuda_weight_storage_4387.py::test_forward_leaves_one_device_copy_of_the_packed_weight[True]
E       AssertionError: assert 10240 <= (83456 - 73728)
1 failed, 6 passed in 6.04s

After (GPU 0):

7 passed in 5.22s

Still guaranteed. qweight's Torch allocation is released by the first forward; _ggml_cuda_weight.backs(kernel.qweight) and the shared data_ptr prove one device copy; a second copy (73,728 B) fails both the allowance and the exact post-clear bound.

Item 2 — test_gguf_kquant_graph_capture_5014.py::test_graph_capture_declaration_is_per_format

Root cause. _build("q2_k") / _build("q3_k") call GGUFTorchLinear.pack_original, and _pack_weight_tensor → _quantize_gguf_tensor_numpy (gptqmodel/nn_modules/qlinear/gguf.py:911-918) needs llama.cpp's native quantizer for Q2_K/Q3_K. On hosts without llama-cpp-python that raises instead of skipping.

Fix. tests/kernels/test_gguf_kquant_graph_capture_5014.py:47-64 adds _host_dequant_skip_reason(), and the declaration test is parametrized (:180-211) so only the two host-dequant nodes skip when llama_cpp is missing. :214-228 adds a unit check that the skip reason is returned and the node raises Skipped when importlib.util.find_spec("llama_cpp") returns None.

Before (simulated no-llama host, exact pre-fix path):

NotImplementedError: Unsupported GGUF quantize target `Q2_K`: install `llama-cpp-python` for native ggml quantization of this format.

After (this host has llama-cpp-python, no new skips):

27 passed in 3.62s

After (simulated no-llama host, full file):

25 passed, 2 skipped in 3.71s
SKIPPED [2] ... Q2_K/Q3_K packing needs llama-cpp-python's native ggml quantizer; install llama-cpp-python to run the host-dequant declaration nodes

Still guaranteed. The capturable formats (q4_0/q8_0/q4_k/q5_k/q6_k) assert supports_graph_capture() is True; Q2_K/Q3_K still assert False on hosts that can pack them, and the class-level graph_capture_safe(GGUFTorchLinear) is True assertion is unchanged.

Item 3 — test_optimize_dynamo_release_5020.py::test_optimize_generate_does_not_pin_the_model[gptq_triton]

Root cause. The parametrization hard-coded BACKEND.GPTQ_TRITON; TritonV2Linear is CUDA-only and raises ValueError: TritonV2Linear is CUDA-only and does not run on ROCm on a HIP build instead of skipping.

Fix. tests/test_optimize_dynamo_release_5020.py:36 imports the shared #5056 predicate tests.accelerator_gates.requires_nvidia_cuda; :62-66 adds _require_nvidia_for(), used at :198 for the parametrized node and :232 for test_repeated_generate_does_not_accumulate, which also hard-codes GPTQ_TRITON through _run_two_generates. :253-261 unit-checks that a HIP build skips GPTQ_TRITON while GPTQ_TORCH is not gated.

On this CUDA host (GPU 0):

5 passed, 1 warning in 97.62s

The end-to-end nodes need HuggingFaceTB/SmolLM2-135M; this host's cache lacks refs/main (the environment note in #5113), so the run used a temporary HF_HUB_CACHE overlay that only adds the missing ref to the already-present snapshot. No repository or test-fixture change was made for that.

Item 3 is ROCm-only and was not executed here. It is verified by gate inspection and by the unit check above: the node now calls the same requires_nvidia_cuda() predicate (torch.cuda.is_available() and torch.version.hip is None) that #5056 uses for the other CUDA-only nodes, and the unit check patches torch.version.hip to a HIP string to confirm the skip.

Validation

All commands run as cd /root/work/issue-5113 && CUDA_VISIBLE_DEVICES=0 PYTHONPATH=/root/work/issue-5113 HF_HUB_OFFLINE=1 /root/venv/bin/python -m pytest ...:

File Result
tests/kernels/test_gguf_cuda_weight_storage_4387.py 7 passed
tests/kernels/test_gguf_kquant_graph_capture_5014.py 27 passed (25 passed, 2 skipped with llama-cpp blocked)
tests/test_optimize_dynamo_release_5020.py 5 passed (with the temporary HF cache overlay)
tests/test_accelerator_gates.py 26 passed
tests/test_optimize_no_reference_cycle_4937.py 3 passed

ruff check on the three changed files: all checks passed.

- #4387: the biased GGUFCudaKernel layer now caches its (0, 4) uint8
  shift table as an immutable per-module constant (#5014), so the exact
  `before - qweight.nbytes` bound is 512 B short. Allow the module's small
  cached constants, then drop the derived caches and assert the exact
  packed-weight release, so a second weight copy still fails.
- #5014: Q2_K/Q3_K packing needs llama.cpp's native quantizer. Skip only
  the host-dequant declaration nodes when llama-cpp-python is absent and
  add a unit check for that skip reason.
- #5020: gate the GPTQ_TRITON node, and the repeated-generate node that
  uses the same backend, on the shared #5056 `requires_nvidia_cuda()`
  predicate instead of hard-coding a CUDA-only kernel on ROCm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant