98 lines
5.3 KiB
Python
98 lines
5.3 KiB
Python
"""Verify a real Windows package and its default-mode no-GPU CPU inference.
|
|
|
|
No desktop UI or GPU inference is exercised. The upstream Vulkan provider is
|
|
disabled only inside the child process to expose a genuinely CPU-only registry.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import math
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
import zipfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--archive", type=Path, default=ROOT / ".searchi/packages/searchi-windows.zip")
|
|
parser.add_argument("--models", type=Path, default=ROOT / ".searchi/models/embeddinggemma2")
|
|
parser.add_argument("--output", type=Path, default=ROOT / ".searchi/packages/smoke.json")
|
|
parser.add_argument("--baseline", action="store_true", help="Extract only the baseline CPU module to test the packaged fallback")
|
|
parser.add_argument("--role", choices=("indexing", "query"), default="indexing")
|
|
args = parser.parse_args()
|
|
manifest = json.loads(Path(__file__).with_name("model-manifest.json").read_text())
|
|
model = args.models / manifest["files"][0]["path"]
|
|
with model.open("rb") as stream:
|
|
assert hashlib.file_digest(stream, "sha256").hexdigest() == manifest["files"][0]["sha256"]
|
|
parent = ROOT / ".searchi/packages"
|
|
parent.mkdir(parents=True, exist_ok=True)
|
|
with tempfile.TemporaryDirectory(prefix="smoke-", dir=parent) as folder:
|
|
target = Path(folder).resolve()
|
|
assert target.is_relative_to(parent.resolve())
|
|
with zipfile.ZipFile(args.archive) as archive:
|
|
package = json.loads(archive.read("PACKAGE.json"))
|
|
for record in package["files"]:
|
|
path = target / record["path"]
|
|
assert path.resolve().is_relative_to(target)
|
|
data = archive.read(record["path"])
|
|
assert len(data) == record["bytes"]
|
|
assert hashlib.sha256(data).hexdigest() == record["sha256"]
|
|
if args.baseline and record["path"].startswith("ggml-cpu-") and record["path"] != "ggml-cpu-x64.dll":
|
|
continue
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_bytes(data)
|
|
environment = dict(os.environ, GGML_DISABLE_VULKAN="1")
|
|
environment.pop("SEARCHI_FORCE_CPU", None)
|
|
started = time.perf_counter()
|
|
worker = subprocess.Popen([str(target / "searchi-gemma-worker.exe"), "--model", str(model),
|
|
"--threads", "1", "--device", "auto", "--role", args.role], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE, text=True, encoding="utf-8", env=environment,
|
|
creationflags=subprocess.CREATE_NO_WINDOW)
|
|
request = json.dumps({"op": "code_query", "text": "retry failed requests with exponential backoff"}) + "\n"
|
|
try:
|
|
stdout, stderr = worker.communicate(request, timeout=120)
|
|
except BaseException:
|
|
worker.kill()
|
|
worker.wait(timeout=10)
|
|
raise
|
|
assert worker.returncode == 0, f"Worker exit {worker.returncode:#x}: {stderr}"
|
|
worker_duration_ms = (time.perf_counter()-started)*1000
|
|
hello, result = [json.loads(line) for line in stdout.splitlines()]
|
|
assert hello["ready"] and hello["device"] == "cpu" and result["device"] == "cpu" and result["ok"]
|
|
assert hello.get("vulkan_module_loaded") is False
|
|
assert hello.get("role") == args.role
|
|
assert hello.get("context_tokens") == (512 if args.role == "query" else 2048)
|
|
if args.baseline:
|
|
assert hello.get("cpu_backend_module") == "ggml-cpu-x64.dll"
|
|
vector = result["vectors"][0]
|
|
assert len(vector) == 768 and all(math.isfinite(x) for x in vector)
|
|
assert abs(sum(x*x for x in vector) - 1) < 0.0001
|
|
decoder = subprocess.run([str(target / "media-runtime/bin/ffprobe.exe"), "-version"],
|
|
env=dict(os.environ, SEARCHI_FORCE_CPU="1"), capture_output=True, text=True,
|
|
creationflags=subprocess.CREATE_NO_WINDOW, check=True, timeout=30)
|
|
with args.archive.open("rb") as stream:
|
|
archive_checksum = hashlib.file_digest(stream, "sha256").hexdigest()
|
|
report = {"architecture": package["architecture"], "verified_files": len(package["files"]),
|
|
"cpu_backend_module": hello.get("cpu_backend_module"),
|
|
"vulkan_module_loaded": hello.get("vulkan_module_loaded"),
|
|
"baseline_only": args.baseline,
|
|
"worker_role": hello["role"], "context_tokens": hello["context_tokens"],
|
|
"archive_sha256": archive_checksum,
|
|
"worker_requested_device": "auto", "worker_actual_device": hello["device"],
|
|
"no_gpu_condition": "GGML_DISABLE_VULKAN=1 only in child; SEARCHI_FORCE_CPU absent",
|
|
"worker_startup_query_and_exit_ms": worker_duration_ms,
|
|
"query_dimensions": len(vector), "decoder": decoder.stdout.splitlines()[0],
|
|
"scope": "Real packaged worker default-mode CPU fallback with disabled provider; no GPU, native UI or clean-machine certification"}
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(json.dumps(report, indent=2)+"\n")
|
|
print(json.dumps(report, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|