Humuhumu33 commited on
Commit
5b034d2
·
verified ·
1 Parent(s): e020433

Upload holo-load2bit.mjs with huggingface_hub

Browse files
Files changed (1) hide show
  1. holo-load2bit.mjs +8 -1
holo-load2bit.mjs CHANGED
@@ -10,6 +10,7 @@
10
  // SAME { manifest, fetchTensor } shape — so the engine, KV-cache, and Q's brain loader need no changes.
11
  import { f16ToF32 } from "./qvac-ingest.mjs";
12
  import { blake3hex } from "./holo-blake3.mjs"; // BLAKE3 σ-axis κ verify (opt-in via manifest.hash==="blake3") — the GPU-parallel tree hash
 
13
 
14
  async function gunzip(u8) { const ds = new DecompressionStream("gzip"); const w = ds.writable.getWriter(); w.write(u8); w.close(); return new Uint8Array(await new Response(ds.readable).arrayBuffer()); }
15
  const hex = (buf) => [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
@@ -107,7 +108,13 @@ export async function loadKappaObject(baseUrl, opts = {}) {
107
  const gz = await cachedBytes(baseUrl + "/b/" + kappa.replace(":", "_") + ".gz");
108
  // Law L5: re-derive the κ. BLAKE3 (σ-axis, GPU-parallel tree hash) when the manifest declares it — the same
109
  // hash the on-GPU verifier reproduces; else SHA-256 (SRI axis, default). Untrusted-CDN-safe either way.
110
- const got = man.hash === "blake3" ? "blake3:" + blake3hex(gz) : "sha256:" + hex(await crypto.subtle.digest("SHA-256", gz));
 
 
 
 
 
 
111
  if (got !== kappa) throw new Error("κ MISMATCH " + kappa.slice(0, 24));
112
  return await gunzip(gz);
113
  };
 
10
  // SAME { manifest, fetchTensor } shape — so the engine, KV-cache, and Q's brain loader need no changes.
11
  import { f16ToF32 } from "./qvac-ingest.mjs";
12
  import { blake3hex } from "./holo-blake3.mjs"; // BLAKE3 σ-axis κ verify (opt-in via manifest.hash==="blake3") — the GPU-parallel tree hash
13
+ import { gpuBlake3Hex } from "./gpu-blake3.mjs"; // the SAME BLAKE3, run entirely on the GPU (2.74 GB/s) — used when globalThis.__gpuVerify
14
 
15
  async function gunzip(u8) { const ds = new DecompressionStream("gzip"); const w = ds.writable.getWriter(); w.write(u8); w.close(); return new Uint8Array(await new Response(ds.readable).arrayBuffer()); }
16
  const hex = (buf) => [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
 
108
  const gz = await cachedBytes(baseUrl + "/b/" + kappa.replace(":", "_") + ".gz");
109
  // Law L5: re-derive the κ. BLAKE3 (σ-axis, GPU-parallel tree hash) when the manifest declares it — the same
110
  // hash the on-GPU verifier reproduces; else SHA-256 (SRI axis, default). Untrusted-CDN-safe either way.
111
+ let got;
112
+ if (man.hash === "blake3") {
113
+ if (typeof globalThis !== "undefined" && globalThis.__gpuVerify) {
114
+ try { got = "blake3:" + await gpuBlake3Hex(gz); } // re-derive on the GPU (no CPU hash on the hot path)
115
+ catch (e) { got = "blake3:" + blake3hex(gz); } // fall back to CPU if WebGPU verify is unavailable
116
+ } else got = "blake3:" + blake3hex(gz);
117
+ } else got = "sha256:" + hex(await crypto.subtle.digest("SHA-256", gz));
118
  if (got !== kappa) throw new Error("κ MISMATCH " + kappa.slice(0, 24));
119
  return await gunzip(gz);
120
  };