-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper_arithmetic.test.js
More file actions
337 lines (247 loc) · 12 KB
/
Copy pathpaper_arithmetic.test.js
File metadata and controls
337 lines (247 loc) · 12 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/**
* Paper Arithmetic Verification
*
* Every derived number (ratio, comparison, percentage) in the paper
* must be traceable to the raw data in the tables. This test catches
* copy-paste errors, stale numbers, and hallucinated calculations.
*
* Run: node tests/paper_arithmetic.test.js
*/
let failures = 0;
let passes = 0;
function check(name, actual, expected, tolerance = 0.05) {
const ratio = Math.abs(actual - expected) / Math.max(Math.abs(expected), 0.001);
if (ratio > tolerance) {
console.error(`FAIL: ${name}`);
console.error(` Expected: ${expected}, Got: ${actual}, Off by: ${(ratio * 100).toFixed(1)}%`);
failures++;
} else {
console.log(` OK: ${name} = ${actual} (expected ${expected})`);
passes++;
}
}
function checkExact(name, actual, expected) {
if (actual !== expected) {
console.error(`FAIL: ${name}`);
console.error(` Expected: ${expected}, Got: ${actual}`);
failures++;
} else {
console.log(` OK: ${name} = ${actual}`);
passes++;
}
}
// ═══════════════════════════════════════════
// RAW DATA FROM TABLES (source of truth)
// ═══════════════════════════════════════════
const TABLE1 = {
numpy: 3.9,
jax_cpu: 20.6,
pytorch_mps: 160.5,
webgpu: 170.3,
wgpu_native: 326.5,
pytorch_cuda: 311.1,
jax_gpu: 1163.9,
};
const TABLE2 = {
numpy: 0.056,
jax_cpu: 0.157,
pytorch_mps: 0.29,
pytorch_cuda: 0.49,
jax_gpu: 6.43,
webgpu: 46.2,
};
const TABLE3 = {
pytorch_cuda: 0.61,
pytorch_mps: 2.52,
webgpu_unfused: 62.3,
jax_gpu: 105.1,
webgpu_fused: 135.9,
};
const TABLE6 = {
pop_512: 12948,
pop_1024: 12791,
pop_2048: 12842,
pop_4096: 12685,
pop_8192: 12714,
pop_16384: 12741,
pop_32768: 12702,
};
const TABLE10 = {
tabs_1_per: 11607, tabs_1_total: 11607,
tabs_2_per: 11296, tabs_2_total: 22593,
tabs_4_per: 9727, tabs_4_total: 38909,
tabs_8_per: 9314, tabs_8_total: 74512,
};
const TABLE11 = {
pytorch_mps: 18.7,
webgpu: 1258.8,
};
// ═══════════════════════════════════════════
// ABSTRACT CLAIMS
// ═══════════════════════════════════════════
console.log("\n=== ABSTRACT ===");
check("Abstract: WebGPU 7.2x over JAX GPU (financial)",
TABLE2.webgpu / TABLE2.jax_gpu, 7.2, 0.05);
check("Abstract: WebGPU 94x over PyTorch CUDA (financial)",
TABLE2.webgpu / TABLE2.pytorch_cuda, 94, 0.05);
check("Abstract: Acrobot 1.29x over JAX GPU",
TABLE3.webgpu_fused / TABLE3.jax_gpu, 1.29, 0.05);
check("Abstract: JAX GPU 1164 vs WebGPU 170 on Rastrigin",
TABLE1.jax_gpu / TABLE1.webgpu, 6.8, 0.05);
check("Abstract: native Metal 1.92x over WebGPU",
TABLE1.wgpu_native / TABLE1.webgpu, 1.92, 0.02);
// ═══════════════════════════════════════════
// CONTRIBUTIONS (C1)
// ═══════════════════════════════════════════
console.log("\n=== CONTRIBUTIONS ===");
check("C1: 159x over PyTorch MPS (financial)",
TABLE2.webgpu / TABLE2.pytorch_mps, 159, 0.05);
check("C1: 94x over PyTorch CUDA (financial)",
TABLE2.webgpu / TABLE2.pytorch_cuda, 94, 0.05);
check("C1: 223x over CUDA (Acrobot)",
TABLE3.webgpu_fused / TABLE3.pytorch_cuda, 223, 0.05);
// ═══════════════════════════════════════════
// TABLE 1 (Rastrigin) — "vs NumPy" column
// ═══════════════════════════════════════════
console.log("\n=== TABLE 1: vs NumPy ===");
check("Table 1: JAX CPU 5.3x over NumPy",
TABLE1.jax_cpu / TABLE1.numpy, 5.3, 0.05);
check("Table 1: PyTorch MPS 41x over NumPy",
TABLE1.pytorch_mps / TABLE1.numpy, 41, 0.05);
check("Table 1: WebGPU 44x over NumPy",
TABLE1.webgpu / TABLE1.numpy, 44, 0.05);
check("Table 1: wgpu-native 84x over NumPy",
TABLE1.wgpu_native / TABLE1.numpy, 84, 0.05);
check("Table 1: PyTorch CUDA 80x over NumPy",
TABLE1.pytorch_cuda / TABLE1.numpy, 80, 0.05);
check("Table 1: JAX GPU 298x over NumPy",
TABLE1.jax_gpu / TABLE1.numpy, 298, 0.05);
// ═══════════════════════════════════════════
// TABLE 1 — inline claims
// ═══════════════════════════════════════════
console.log("\n=== TABLE 1: Inline claims ===");
check("WebGPU 1.06x parity with PyTorch MPS",
TABLE1.webgpu / TABLE1.pytorch_mps, 1.06, 0.02);
check("JAX GPU 6.8x over WebGPU",
TABLE1.jax_gpu / TABLE1.webgpu, 6.8, 0.05);
check("PyTorch CUDA 1.83x over WebGPU",
TABLE1.pytorch_cuda / TABLE1.webgpu, 1.83, 0.05);
check("WebGPU 0.55x of PyTorch CUDA",
TABLE1.webgpu / TABLE1.pytorch_cuda, 0.55, 0.05);
check("Browser overhead 48% (1 - webgpu/native)",
(1 - TABLE1.webgpu / TABLE1.wgpu_native) * 100, 48, 0.05);
// ═══════════════════════════════════════════
// TABLE 2 (Financial) — "vs" columns
// ═══════════════════════════════════════════
console.log("\n=== TABLE 2: Financial ratios ===");
check("Table 2: JAX CPU 2.8x over NumPy",
TABLE2.jax_cpu / TABLE2.numpy, 2.8, 0.05);
check("Table 2: PyTorch MPS 5.2x over NumPy",
TABLE2.pytorch_mps / TABLE2.numpy, 5.2, 0.05);
check("Table 2: PyTorch CUDA 8.8x over NumPy",
TABLE2.pytorch_cuda / TABLE2.numpy, 8.8, 0.05);
check("Table 2: JAX GPU 115x over NumPy",
TABLE2.jax_gpu / TABLE2.numpy, 115, 0.05);
check("Table 2: WebGPU 825x over NumPy",
TABLE2.webgpu / TABLE2.numpy, 825, 0.05);
check("Table 2: WebGPU 159x over PyTorch MPS",
TABLE2.webgpu / TABLE2.pytorch_mps, 159, 0.05);
check("Table 2: WebGPU 94x over PyTorch CUDA",
TABLE2.webgpu / TABLE2.pytorch_cuda, 94, 0.05);
check("Table 2: PyTorch CUDA 1.7x over PyTorch MPS",
TABLE2.pytorch_cuda / TABLE2.pytorch_mps, 1.7, 0.05);
check("Table 2: JAX GPU 22x over PyTorch MPS",
TABLE2.jax_gpu / TABLE2.pytorch_mps, 22, 0.05);
check("Table 2: JAX GPU 13x over PyTorch CUDA",
TABLE2.jax_gpu / TABLE2.pytorch_cuda, 13, 0.05);
check("Table 2: WebGPU 7.2x over JAX GPU",
TABLE2.webgpu / TABLE2.jax_gpu, 7.2, 0.05);
// ═══════════════════════════════════════════
// TABLE 3 (Acrobot) — ratios
// ═══════════════════════════════════════════
console.log("\n=== TABLE 3: Acrobot ratios ===");
check("Table 3: PyTorch MPS 4.1x over PyTorch CUDA",
TABLE3.pytorch_mps / TABLE3.pytorch_cuda, 4.1, 0.05);
check("Table 3: WebGPU unfused 24.7x over PyTorch MPS",
TABLE3.webgpu_unfused / TABLE3.pytorch_mps, 24.7, 0.05);
check("Table 3: WebGPU unfused 102x over PyTorch CUDA",
TABLE3.webgpu_unfused / TABLE3.pytorch_cuda, 102, 0.05);
check("Table 3: JAX GPU 41.7x over PyTorch MPS",
TABLE3.jax_gpu / TABLE3.pytorch_mps, 41.7, 0.05);
check("Table 3: JAX GPU 172x over PyTorch CUDA",
TABLE3.jax_gpu / TABLE3.pytorch_cuda, 172, 0.05);
check("Table 3: WebGPU fused 54x over PyTorch MPS",
TABLE3.webgpu_fused / TABLE3.pytorch_mps, 54, 0.05);
check("Table 3: WebGPU fused 223x over PyTorch CUDA",
TABLE3.webgpu_fused / TABLE3.pytorch_cuda, 223, 0.05);
check("Ablation: fusion provides 2.18x on top of unfused",
TABLE3.webgpu_fused / TABLE3.webgpu_unfused, 2.18, 0.05);
check("JAX GPU 1.29x slower than fused WebGPU (Acrobot)",
TABLE3.webgpu_fused / TABLE3.jax_gpu, 1.29, 0.05);
// ═══════════════════════════════════════════
// TABLE 5 (Population scaling) — <2.1% variation
// ═══════════════════════════════════════════
console.log("\n=== TABLE 6: Population scaling ===");
const popValues = Object.values(TABLE6);
const popMin = Math.min(...popValues);
const popMax = Math.max(...popValues);
const popVariation = ((popMax - popMin) / popMax) * 100;
check("Population scaling <2.1% variation",
popVariation, 2.0, 0.10);
// ═══════════════════════════════════════════
// TABLE 10 (Multi-tab) — efficiency claims
// ═══════════════════════════════════════════
console.log("\n=== TABLE 10: Multi-tab ===");
check("2-tab efficiency 97%",
(TABLE10.tabs_2_per / TABLE10.tabs_1_per) * 100, 97, 0.02);
check("4-tab efficiency 84%",
(TABLE10.tabs_4_per / TABLE10.tabs_1_per) * 100, 84, 0.02);
check("8-tab efficiency 80%",
(TABLE10.tabs_8_per / TABLE10.tabs_1_per) * 100, 80, 0.02);
check("8-tab total throughput 6.4x",
TABLE10.tabs_8_total / TABLE10.tabs_1_total, 6.4, 0.05);
check("4-tab total throughput 3.4x",
TABLE10.tabs_4_total / TABLE10.tabs_1_total, 3.4, 0.05);
// ═══════════════════════════════════════════
// TABLE 11 (MountainCar)
// ═══════════════════════════════════════════
console.log("\n=== TABLE 11: MountainCar ===");
check("MountainCar: WebGPU 67x over PyTorch MPS",
TABLE11.webgpu / TABLE11.pytorch_mps, 67, 0.05);
// ═══════════════════════════════════════════
// CONCLUSION claims
// ═══════════════════════════════════════════
console.log("\n=== CONCLUSION ===");
check("Conclusion: 7.2x over JAX GPU (financial)",
TABLE2.webgpu / TABLE2.jax_gpu, 7.2, 0.05);
check("Conclusion: 94x over PyTorch CUDA (financial)",
TABLE2.webgpu / TABLE2.pytorch_cuda, 94, 0.05);
check("Conclusion: 1.29x over JAX GPU (Acrobot)",
TABLE3.webgpu_fused / TABLE3.jax_gpu, 1.29, 0.05);
check("Conclusion: JAX GPU 6.8x over WebGPU (Rastrigin)",
TABLE1.jax_gpu / TABLE1.webgpu, 6.8, 0.05);
check("Conclusion: native Metal 1.92x",
TABLE1.wgpu_native / TABLE1.webgpu, 1.92, 0.02);
// ═══════════════════════════════════════════
// CROSS-TABLE CONSISTENCY
// ═══════════════════════════════════════════
console.log("\n=== CROSS-TABLE CONSISTENCY ===");
// Abstract says "46.2 gen/s" — matches Table 2
checkExact("Abstract WebGPU financial matches Table 2", TABLE2.webgpu, 46.2);
// Abstract says "6.43 gen/s" for JAX GPU — matches Table 2
checkExact("Abstract JAX GPU financial matches Table 2", TABLE2.jax_gpu, 6.43);
// Abstract says "1,164" for JAX Rastrigin — check rounding
check("Abstract JAX GPU Rastrigin rounds to 1164",
Math.round(TABLE1.jax_gpu), 1164, 0.001);
// ═══════════════════════════════════════════
// SUMMARY
// ═══════════════════════════════════════════
console.log(`\n${"=".repeat(50)}`);
console.log(`RESULTS: ${passes} passed, ${failures} failed`);
console.log(`${"=".repeat(50)}`);
if (failures > 0) {
console.error(`\n${failures} ARITHMETIC ERROR(S) IN PAPER — FIX BEFORE SUBMISSION`);
process.exit(1);
} else {
console.log("\nAll paper arithmetic verified. Safe to submit.");
}