File size: 6,090 Bytes
ecf89a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709f280
 
 
 
ecf89a6
 
709f280
 
ecf89a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
"""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)}")

    # tok_s_prefill / power_w may be null (JSON null) on concurrency>1 rows where they are
    # NOT separately measured - the row's headline is tok_s_decode (the aggregate). A null is
    # the honest sentinel there; an arbitrary borrowed single-stream value would be misleading.
    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())