mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
tools: require CUDA model offload in llama.cpp parity runs (#536)
Co-authored-by: shiaho <222622008+shiaho777@users.noreply.github.com>
This commit is contained in:
@ -78,6 +78,31 @@ class TestLlamaAndPerfBench(unittest.TestCase):
|
||||
self.assertEqual(bin_path, Path("./llama-bench").resolve())
|
||||
self.assertEqual(model_path, Path("./model.gguf").resolve())
|
||||
|
||||
def test_llama_parity_requires_cuda_model_offload(self):
|
||||
mod = _load_tool("llama_cpp_parity")
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
binary = Path(td) / "llama-completion"
|
||||
model = Path(td) / "model.gguf"
|
||||
binary.touch()
|
||||
model.touch()
|
||||
cuda = "load_tensors: CUDA2 model buffer size = 68.25 MiB"
|
||||
offload = "load_tensors: offloaded 25/25 layers to GPU"
|
||||
for log, expected in (
|
||||
("ggml_cuda_init: found 0 CUDA devices", False),
|
||||
("load_tensors: offloaded 0/25 layers to GPU\n" + cuda, False),
|
||||
(offload + "\nload_tensors: CUDA_Host model buffer size = 68.25 MiB", False),
|
||||
(offload + "\nload_tensors: CUDA2 model buffer size = 0.00 MiB", False),
|
||||
(offload + "\n" + cuda, True),
|
||||
):
|
||||
with self.subTest(log=log):
|
||||
result = subprocess.CompletedProcess([], 0, "A complete deterministic answer.", log)
|
||||
with (mock.patch.object(mod, "resolve_llama_paths", return_value=(binary, model, "")),
|
||||
mock.patch.object(mod.subprocess, "run", return_value=result),
|
||||
mock.patch("builtins.print") as output):
|
||||
rc = mod.main()
|
||||
self.assertEqual(rc, 0 if expected else 1)
|
||||
self.assertIs(json.loads(output.call_args.args[0])["passed"], expected)
|
||||
|
||||
def test_llama_parity_emits_json_when_missing(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
env = os.environ.copy()
|
||||
|
||||
@ -9,6 +9,7 @@ exact output text and SHA-256 digest for stock vs nvidia_rs.ko parity.
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
@ -75,9 +76,13 @@ def main() -> int:
|
||||
cuda_devs = [
|
||||
ln.strip()
|
||||
for ln in proc.stderr.splitlines()
|
||||
if any(k in ln for k in ("CUDA0", "CUDA1", "Tesla V100", "ggml_cuda_init", "offloaded", "graphs reused"))
|
||||
if re.search(r"\bCUDA\d+\b", ln)
|
||||
or any(k in ln for k in ("Tesla V100", "ggml_cuda_init", "offloaded", "graphs reused"))
|
||||
]
|
||||
passed = proc.returncode == 0 and len(out_text) > 20 and len(cuda_devs) > 0
|
||||
offloaded = re.search(r"\boffloaded [1-9]\d*/\d+ layers to GPU\b", proc.stderr)
|
||||
cuda_buffers = re.findall(r"\bCUDA\d+ model buffer size\s*=\s*(\d+(?:\.\d+)?) MiB\b", proc.stderr)
|
||||
passed = (proc.returncode == 0 and len(out_text) > 20 and offloaded is not None
|
||||
and any(float(size) > 0 for size in cuda_buffers))
|
||||
result = {
|
||||
"passed": passed,
|
||||
"rc": proc.returncode,
|
||||
|
||||
Reference in New Issue
Block a user