| |
| """Validate RTX PRO 4000 benchmark JSONL rows.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import re |
| import sys |
| from pathlib import Path |
| from typing import Any |
|
|
|
|
| REQUIRED = [ |
| "variant", |
| "vram_gb", |
| "memory_type", |
| "bus_width_bit", |
| "bandwidth_gbps", |
| "tdp_w", |
| "pcie_lanes", |
| "gpu_count", |
| "model", |
| "params_b", |
| "quant", |
| "backend", |
| "backend_version", |
| "driver_version", |
| "os", |
| "context_len", |
| "concurrency", |
| "tok_s_prefill", |
| "tok_s_decode", |
| "vram_used_gb", |
| "power_w", |
| "thinking", |
| "source", |
| "submitter", |
| "date", |
| "notes", |
| ] |
|
|
| ENUMS = { |
| "variant": {"desktop", "sff", "laptop"}, |
| "memory_type": {"gddr7", "gddr6"}, |
| "quant": {"gguf-q4_k_m", "gguf-q8_0", "nvfp4", "fp8", "bf16", "other"}, |
| "backend": {"llama.cpp", "vllm", "tensorrt-llm", "other"}, |
| "thinking": {"on", "off", "n/a"}, |
| "source": {"owner-measured"}, |
| } |
|
|
| VARIANT_DISCRIMINATORS = { |
| "desktop": { |
| "bandwidth_gbps": 672, |
| "tdp_w": 140, |
| "pcie_lanes": 16, |
| }, |
| "sff": { |
| "bandwidth_gbps": 432, |
| "tdp_w": 70, |
| "pcie_lanes": 8, |
| }, |
| "laptop": { |
| "vram_gb": 16, |
| "bandwidth_gbps": 896, |
| }, |
| } |
|
|
| VARIANT_METADATA = { |
| "desktop": { |
| "vram_gb": 24, |
| "memory_type": "gddr7", |
| "bus_width_bit": 192, |
| }, |
| "sff": { |
| "vram_gb": 24, |
| "memory_type": "gddr7", |
| "bus_width_bit": 192, |
| }, |
| "laptop": { |
| "vram_gb": 16, |
| "memory_type": "gddr7", |
| "bus_width_bit": 256, |
| }, |
| } |
|
|
| NUMERIC = { |
| "vram_gb", |
| "bandwidth_gbps", |
| "tdp_w", |
| "params_b", |
| "tok_s_prefill", |
| "tok_s_decode", |
| "vram_used_gb", |
| "power_w", |
| } |
|
|
| INTEGER = {"gpu_count", "bus_width_bit", "pcie_lanes", "context_len", "concurrency"} |
|
|
|
|
| def row_errors(row: dict[str, Any], line_no: int) -> list[str]: |
| errors: list[str] = [] |
|
|
| for field in REQUIRED: |
| if field not in row: |
| errors.append(f"line {line_no}: missing required field {field}") |
|
|
| for field in row: |
| if field not in REQUIRED: |
| errors.append(f"line {line_no}: unexpected field {field}") |
|
|
| for field, allowed in ENUMS.items(): |
| value = row.get(field) |
| if value not in allowed: |
| errors.append(f"line {line_no}: {field}={value!r} not in {sorted(allowed)}") |
|
|
| |
| |
| |
| nullable_numeric = {"tok_s_prefill", "power_w"} |
| for field in NUMERIC: |
| value = row.get(field) |
| if value is None and field in nullable_numeric: |
| continue |
| if not isinstance(value, (int, float)) or isinstance(value, bool): |
| errors.append(f"line {line_no}: {field} must be numeric") |
| elif value < 0: |
| errors.append(f"line {line_no}: {field} must be >= 0") |
|
|
| for field in INTEGER: |
| value = row.get(field) |
| if not isinstance(value, int) or isinstance(value, bool): |
| errors.append(f"line {line_no}: {field} must be an integer") |
| elif value < 1: |
| errors.append(f"line {line_no}: {field} must be >= 1") |
|
|
| for field in ("model", "backend_version", "driver_version", "os", "submitter", "notes"): |
| value = row.get(field) |
| if not isinstance(value, str) or not value.strip(): |
| errors.append(f"line {line_no}: {field} must be a non-empty string") |
|
|
| date_value = row.get("date") |
| if not isinstance(date_value, str) or not re.fullmatch(r"\d{4}-\d{2}-\d{2}", date_value): |
| errors.append(f"line {line_no}: date must be YYYY-MM-DD") |
|
|
| variant = row.get("variant") |
| discriminator_expected = VARIANT_DISCRIMINATORS.get(variant) |
| if discriminator_expected: |
| for field, expected_value in discriminator_expected.items(): |
| actual = row.get(field) |
| if actual != expected_value: |
| errors.append( |
| f"line {line_no}: {variant} discriminator requires {field}={expected_value}, got {actual!r}" |
| ) |
|
|
| metadata_expected = VARIANT_METADATA.get(variant) |
| if metadata_expected: |
| for field, expected_value in metadata_expected.items(): |
| actual = row.get(field) |
| if actual != expected_value: |
| errors.append( |
| f"line {line_no}: {variant} metadata expects {field}={expected_value}, got {actual!r}" |
| ) |
|
|
| if row.get("source") != "owner-measured": |
| errors.append(f"line {line_no}: source must be owner-measured") |
|
|
| return errors |
|
|
|
|
| def validate(path: Path) -> tuple[int, list[str]]: |
| errors: list[str] = [] |
| count = 0 |
|
|
| try: |
| lines = path.read_text(encoding="utf-8").splitlines() |
| except OSError as exc: |
| return 0, [f"{path}: {exc}"] |
|
|
| for line_no, line in enumerate(lines, start=1): |
| if not line.strip(): |
| continue |
| try: |
| row = json.loads(line) |
| except json.JSONDecodeError as exc: |
| errors.append(f"line {line_no}: invalid JSON: {exc}") |
| continue |
| if not isinstance(row, dict): |
| errors.append(f"line {line_no}: row must be a JSON object") |
| continue |
| count += 1 |
| errors.extend(row_errors(row, line_no)) |
|
|
| if count == 0: |
| errors.append(f"{path}: no rows found") |
| return count, errors |
|
|
|
|
| def main() -> int: |
| parser = argparse.ArgumentParser(description="Validate benchmark JSONL rows") |
| parser.add_argument("path", nargs="?", default="data/results.jsonl") |
| args = parser.parse_args() |
|
|
| count, errors = validate(Path(args.path)) |
| if errors: |
| for error in errors: |
| print(error, file=sys.stderr) |
| return 1 |
| print(f"OK: {count} rows valid") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|