File size: 8,007 Bytes
7ef4465
 
 
 
 
 
41512f4
7ef4465
 
b5551af
 
 
7ef4465
 
 
 
 
41512f4
 
 
 
 
 
 
 
7ef4465
 
 
 
 
 
 
41512f4
7ef4465
 
 
 
 
 
 
 
41512f4
 
7ef4465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41512f4
7ef4465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41512f4
7ef4465
 
 
 
 
 
 
b5551af
 
7ef4465
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3

import argparse
import datetime
import hashlib
import json
import re
from pathlib import Path

import pyarrow as pa
import pyarrow.parquet as pq


def iso_from_unix(timestamp):
    return datetime.datetime.fromtimestamp(timestamp, datetime.UTC).isoformat().replace("+00:00", "Z")


def public_text(value):
    if value is None:
        return None
    private_source_name = "local" + "maxxing"
    return re.sub(private_source_name, "external source", value, flags=re.IGNORECASE)


def external_rows(cache):
    scraped_at = cache["scraped_at"]
    seen = {}
    for preset, group in cache["presets"].items():
        for row in group["rows"]:
            previous = seen.get(row["id"])
            if previous is not None:
                if previous != row:
                    raise ValueError(f"conflicting external rows for {row['id']}")
                continue
            seen[row["id"]] = row
            model = row["model"]
            hardware = row["hardware"]
            engine = row["engine"]
            flags = row.get("engineFlags") or {}
            user = row.get("user") or {}
            yield {
                "benchmark_id": f"external-community:{row['id']}",
                "source": "external-community",
                "source_record_id": row["id"],
                "source_snapshot_at": scraped_at,
                "measured_at": row.get("createdAt"),
                "schema_version": 1,
                "model_id": model.get("hfId"),
                "model_revision": row.get("modelRevision"),
                "model_display_name": model.get("displayName"),
                "base_model_id": (model.get("baseModel") or {}).get("hfId"),
                "model_family": model.get("family"),
                "model_params_billion": model.get("params"),
                "model_active_params_billion": model.get("activeParams"),
                "model_is_moe": model.get("isMoE"),
                "runtime": engine.get("engineName"),
                "runtime_version": engine.get("engineVersion"),
                "backend": engine.get("backend"),
                "quantization": engine.get("quantization"),
                "hardware_label": row.get("hardwareGroupLabel") or preset,
                "hardware_class": hardware.get("hwClass"),
                "accelerator": hardware.get("gpuName"),
                "accelerator_count": hardware.get("gpuCount"),
                "vram_gb": hardware.get("vramGb"),
                "unified_memory_gb": hardware.get("unifiedMemoryGb"),
                "ram_gb": None,
                "cpu": hardware.get("cpu"),
                "cpu_cores": None,
                "os": hardware.get("os"),
                "prompt_tokens": row.get("promptTokens"),
                "output_tokens": row.get("outputTokens"),
                "context_length": row.get("contextLength"),
                "batch_size": row.get("batchSize"),
                "num_runs": None,
                "ttft_ms": row.get("ttftMs"),
                "output_tps": row.get("tokSOut"),
                "prefill_tps": row.get("tokSPrefill"),
                "total_tps": row.get("tokSTotal"),
                "min_tps": None,
                "max_tps": None,
                "total_time_ms": None,
                "peak_vram_gb": row.get("peakVramGb"),
                "gpu_power_watts": row.get("gpuPowerWatts") or [],
                "total_power_watts": row.get("totalPowerWatts"),
                "tensor_parallel": flags.get("tensorParallel"),
                "gpu_layers": flags.get("gpuLayers"),
                "kv_cache_dtype": flags.get("kvCacheDtype"),
                "attention_backend": flags.get("attentionBackend"),
                "flash_attention": flags.get("flashAttn"),
                "speculative_decoding": flags.get("specDecoding"),
                "mtp_enabled": flags.get("mtpEnabled"),
                "submitter": user.get("username"),
                "submitter_verified": user.get("verified"),
                "notes": public_text(row.get("notes")),
            }


def community_rows(community_dir):
    for path in sorted(community_dir.glob("*/*.json")):
        submission = json.loads(path.read_text())
        hardware = submission["hardware"]
        relative = path.relative_to(community_dir).as_posix()
        measured_at = iso_from_unix(submission["submittedAtUnix"])
        for index, result in enumerate(submission["results"]):
            record_id = f"{relative}#{index}"
            digest = hashlib.sha256(record_id.encode()).hexdigest()[:24]
            yield {
                "benchmark_id": f"llmfit-community:{digest}",
                "source": "llmfit-community",
                "source_record_id": record_id,
                "source_snapshot_at": None,
                "measured_at": measured_at,
                "schema_version": submission["schemaVersion"],
                "model_id": result["model"],
                "model_revision": None,
                "model_display_name": None,
                "base_model_id": None,
                "model_family": None,
                "model_params_billion": None,
                "model_active_params_billion": None,
                "model_is_moe": None,
                "runtime": result["provider"],
                "runtime_version": submission["tool"].get("version"),
                "backend": None,
                "quantization": None,
                "hardware_label": hardware["hardwareName"],
                "hardware_class": hardware["hwClass"],
                "accelerator": hardware["hardwareName"],
                "accelerator_count": hardware["gpuCount"],
                "vram_gb": hardware["vramGb"],
                "unified_memory_gb": hardware["memTierGb"] if hardware["unifiedMemory"] else None,
                "ram_gb": hardware["ramGb"],
                "cpu": hardware["cpu"],
                "cpu_cores": hardware["cpuCores"],
                "os": hardware["os"],
                "prompt_tokens": None,
                "output_tokens": result["avgOutputTokens"],
                "context_length": None,
                "batch_size": None,
                "num_runs": result["numRuns"],
                "ttft_ms": result["avgTtftMs"],
                "output_tps": result["avgTps"],
                "prefill_tps": None,
                "total_tps": None,
                "min_tps": result["minTps"],
                "max_tps": result["maxTps"],
                "total_time_ms": result["avgTotalMs"],
                "peak_vram_gb": None,
                "gpu_power_watts": [],
                "total_power_watts": None,
                "tensor_parallel": None,
                "gpu_layers": None,
                "kv_cache_dtype": None,
                "attention_backend": None,
                "flash_attention": None,
                "speculative_decoding": None,
                "mtp_enabled": None,
                "submitter": None,
                "submitter_verified": None,
                "notes": None,
            }


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("llmfit", type=Path)
    parser.add_argument("output", type=Path)
    args = parser.parse_args()

    data_dir = args.llmfit / "llmfit-core" / "data"
    cache = json.loads((data_dir / "benchmark_cache.json").read_text())
    rows = list(external_rows(cache)) + list(community_rows(data_dir / "community"))
    rows.sort(key=lambda row: (row["measured_at"] or "", row["benchmark_id"]))

    ids = [row["benchmark_id"] for row in rows]
    if len(ids) != len(set(ids)):
        raise SystemExit("duplicate benchmark_id")

    args.output.parent.mkdir(parents=True, exist_ok=True)
    table = pa.Table.from_pylist(rows)
    pq.write_table(table, args.output, compression="zstd")

    by_source = {}
    for row in rows:
        by_source[row["source"]] = by_source.get(row["source"], 0) + 1
    print(json.dumps({"rows": len(rows), "sources": by_source}, sort_keys=True))


if __name__ == "__main__":
    main()