Files
OBLITERATUS/tests/conditional/test_backend_qualification_cuda.py
Joseph MaglyandClaude Opus 5.5 458059e066 feat(experiments): backend qualification and support matrix
Start milestone 5 (F20): qualify each saved artifact on an explicit
backend against the CPU float32 reference of the same artifact, and
record exactly which pairs qualify.

- Only fully verified persistent candidates are accepted; each run
  loads the saved artifact fresh from disk on the reference and on the
  declared backend after checking digests.
- Backend descriptors make device, dtype, quantization, attention,
  tokenizer and cache mode explicit; their digest is the backend id, so
  native and quantized results are separate rows.
- Paired evaluation on independent rows checks realized settings,
  target rate, completion agreement, logit and site-activation drift and
  collateral endpoints. Latency and memory stay outside the digest.
- Unsupported combinations are recorded unsupported without loading or
  falling back; unavailable hardware is refused and leaves the pair
  untested. Failures are permanent and block broader claims.
- A versioned support matrix lists exactly the qualified pairs. CUDA
  tests run in the cuda-runtime conditional gate.
- `obliteratus experiments qualify run|matrix`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 13:05:58 -05:00

48 lines
2.1 KiB
Python

"""CUDA backend qualification of a saved fixture candidate against its CPU reference.
The planted fixture establishes software contracts only (saved artifact loaded on
the declared CUDA backend, realized placement, paired comparison, matrix rows),
never pretrained behaviour.
"""
from __future__ import annotations
import pytest
import torch
from obliteratus.experiments.backend_matrix import support_matrix
from tests.test_backend_qualification import CPU32, BackendIO, run, selected # noqa: F401
from tests.test_persistent_candidates import env # noqa: F401
pytestmark = pytest.mark.gpu
@pytest.fixture(autouse=True, scope="module")
def require_cuda():
if not torch.cuda.is_available():
pytest.skip("requires a CUDA runner; set ENABLE_CUDA_GATE and attach the cuda label")
def test_cuda_float32_runs_the_saved_artifact_and_float16_is_a_separate_row(env, selected): # noqa: F811
io = BackendIO()
record = run(env, selected, "edit", {**CPU32, "device": "cuda"}, io)
found = {c["check"]: c["passed"] for c in record["checks"]}
assert found["realized_device"] and found["realized_dtype"]
assert record["backend"]["device"] == "cuda:0" and len(io.loads) == 2
assert next(iter(io.models[1].parameters())).device.type == "cuda"
assert record["status"] in ("qualified", "failed")
assert "peak_device_bytes" in record["host"]["backend"]
half = run(env, selected, "edit", {**CPU32, "device": "cuda", "dtype": "float16"})
assert half["backend_id"] != record["backend_id"]
matrix = support_matrix(selected["edit"][0], candidate=selected["edit"][1]["id"])
qualified = {q["backend_id"] for q in matrix["qualified_pairs"]}
for item in (record, half):
assert (item["backend_id"] in qualified) == (item["status"] == "qualified")
def test_cuda_quantization_without_a_quantized_loader_is_unsupported(env, selected): # noqa: F811
record = run(env, selected, "edit", {**CPU32, "device": "cuda", "dtype": "float16",
"quantization": "bnb-int8"})
assert record["status"] == "unsupported" and "provides no bnb-int8 load" in record["reason"]
assert record["class"] == "quantized"