Upload web/public/verified_core.js with huggingface_hub
Browse files- web/public/verified_core.js +10 -3
web/public/verified_core.js
CHANGED
|
@@ -185,6 +185,13 @@
|
|
| 185 |
const f32 = Math.fround;
|
| 186 |
function epi(s, a, b) { return f32(f32(f32(s) * a) * b); }
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
// CPU mirror of the fused GPU kernel: batched int8 GEMM through the LUT with
|
| 189 |
// the epilogue (block dequant + optional ReLU) applied before returning —
|
| 190 |
// exactly what the WGSL kernel does on-device. d.acc=true returns the raw
|
|
@@ -230,8 +237,8 @@
|
|
| 230 |
let v = epi(acc, rs[bz * m + i], cs[bz * n + j]);
|
| 231 |
if (relu && v < 0) v = 0;
|
| 232 |
const idx = (bz * m + i) * n + j;
|
| 233 |
-
if (got[idx]
|
| 234 |
-
return `GEMM audit failed at [b${bz},${i},${j}] shape ${m}x${k}x${n}: kernel ${got[idx]} vs units ${v}`;
|
| 235 |
}
|
| 236 |
return null;
|
| 237 |
}
|
|
@@ -384,7 +391,7 @@
|
|
| 384 |
|
| 385 |
const api = { quantize, quantize2, quantizeRows, quantizeCols, quantizeHeadCols, lutMatmulJS, lutMatmul3JS, lutMatmul3,
|
| 386 |
bgemmJS, vgemmBlock, auditTile, epi, attScoresJS, attCtxJS, linearFwd, forward, backward, splitApply,
|
| 387 |
-
rowAbsMax, scalesFromAbsMax, quantizeRowsInv, vmlpBlock };
|
| 388 |
if (typeof module !== "undefined" && module.exports) { TC = require("./traincore.js"); module.exports = api; }
|
| 389 |
else { TC = root.TrainCore; root.Verified = api; }
|
| 390 |
})(typeof self !== "undefined" ? self : this);
|
|
|
|
| 185 |
const f32 = Math.fround;
|
| 186 |
function epi(s, a, b) { return f32(f32(f32(s) * a) * b); }
|
| 187 |
|
| 188 |
+
// f32 equality at the BIT level: `!==` says -0 === 0, but replicas are
|
| 189 |
+
// compared by hashing raw bytes, so an audit that can't see the sign of zero
|
| 190 |
+
// could pass a device that later forks the fleet. (Real ISAs have non-IEEE
|
| 191 |
+
// modes that flush -0 to +0 — e.g. RDNA2 output modifiers / legacy muls.)
|
| 192 |
+
const _fb = new Float32Array(1), _ub = new Uint32Array(_fb.buffer);
|
| 193 |
+
function bitDiff(a, b) { _fb[0] = a; const u = _ub[0]; _fb[0] = b; return u !== _ub[0]; }
|
| 194 |
+
|
| 195 |
// CPU mirror of the fused GPU kernel: batched int8 GEMM through the LUT with
|
| 196 |
// the epilogue (block dequant + optional ReLU) applied before returning —
|
| 197 |
// exactly what the WGSL kernel does on-device. d.acc=true returns the raw
|
|
|
|
| 237 |
let v = epi(acc, rs[bz * m + i], cs[bz * n + j]);
|
| 238 |
if (relu && v < 0) v = 0;
|
| 239 |
const idx = (bz * m + i) * n + j;
|
| 240 |
+
if (bitDiff(got[idx], v))
|
| 241 |
+
return `GEMM audit failed at [b${bz},${i},${j}] shape ${m}x${k}x${n}: kernel ${Object.is(got[idx], -0) ? "-0" : got[idx]} vs units ${Object.is(v, -0) ? "-0" : v}`;
|
| 242 |
}
|
| 243 |
return null;
|
| 244 |
}
|
|
|
|
| 391 |
|
| 392 |
const api = { quantize, quantize2, quantizeRows, quantizeCols, quantizeHeadCols, lutMatmulJS, lutMatmul3JS, lutMatmul3,
|
| 393 |
bgemmJS, vgemmBlock, auditTile, epi, attScoresJS, attCtxJS, linearFwd, forward, backward, splitApply,
|
| 394 |
+
rowAbsMax, scalesFromAbsMax, quantizeRowsInv, vmlpBlock, bitDiff };
|
| 395 |
if (typeof module !== "undefined" && module.exports) { TC = require("./traincore.js"); module.exports = api; }
|
| 396 |
else { TC = root.TrainCore; root.Verified = api; }
|
| 397 |
})(typeof self !== "undefined" ? self : this);
|