NakliTechie commited on
Commit
8fce7d2
Β·
1 Parent(s): 0162c27

Sync from GitHub 2026-10-30T17:46:32Z

Browse files
Files changed (1) hide show
  1. index.html +81 -32
index.html CHANGED
@@ -8040,7 +8040,7 @@ const engineFetch = async (url, init = {}) => {
8040
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy
8041
  // of the engine (Gemma4Mobile) and, with ple, builds the OPFS per-layer-embedding table itself. The worker then drives
8042
  // session.engine exactly as it drove its own engine. Pinned to the same anyformer as anyformer_models.js.
8043
- const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.15/index.js';
8044
 
8045
  let anyformerLoad = null;
8046
  let session = null;
@@ -8185,7 +8185,7 @@ self.onmessage = async (e) => {
8185
  // rolled-in module URLs (moduleUrl()).
8186
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy of
8187
  // the engine (TernaryBonsai2); the worker drives session.engine as before and attaches DFlash / MTP itself.
8188
- const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.15/index.js';
8189
  const DFLASH_URL = '__TERNARY_BONSAI2_DFLASH_URL__';
8190
  const MTP_URL = '__TERNARY_BONSAI2_MTP_URL__';
8191
  // MTP speculative decoding (Settings β†’ Models, default OFF; posted as `mtp` + `mtpDepth` on the
@@ -24155,7 +24155,7 @@ self.addEventListener('message', async (e) => {
24155
  */
24156
  const THINK_CLOSE = -2;
24157
 
24158
- export const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.15/index.js';
24159
 
24160
  // anyformer's progress events β†’ the engine events the SSD worker posts. The llama.cpp path reports 'download' (bytes
24161
  // into OPFS) and 'load' / 'plan'; a hand engine (diskformer back end) reports its own engine events, 'weights' with
@@ -32565,7 +32565,7 @@ const GGUF_FILE = 'LFM2.5-230M-Q4_0.gguf';
32565
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy of
32566
  // the LFM2.5 engine (Lfm2Mobile) and returns a session with the same generate / reset / dispose. Pinned to an exact
32567
  // version; LocalMind's anyformer_models.js pins the same one.
32568
- const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.15/index.js';
32569
 
32570
  let anyformerLoad = null;
32571
  let model = null;
@@ -32881,7 +32881,10 @@ export const FORMAT = 'diskformer-gguf/1';
32881
  // ── Ingest: GGUF (over HTTP Range, or a local file) β†’ OPFS, in the engine layout ──
32882
  export const storeKey = (file) => file.replace(/\.gguf$/i, '').toLowerCase().replace(/[^a-z0-9._-]+/g, '-');
32883
 
32884
- export async function readHeader(url, fetchFn, signal) {
 
 
 
32885
  let n = 16 << 20;
32886
  for (;;) {
32887
  const r = await fetchFn(url, { headers: { Range: `bytes=0-${n - 1}` }, signal, cache: 'no-store' });
@@ -32889,11 +32892,37 @@ export async function readHeader(url, fetchFn, signal) {
32889
  const h = (name) => (r.headers && r.headers.get ? r.headers.get(name) : null);
32890
  const total = /\/(\d+)\s*$/.exec(h('content-range') || '');
32891
  const file = { size: total ? Number(total[1]) : null, etag: h('etag') }; // for the resume identity
32892
- const u8 = new Uint8Array(await r.arrayBuffer());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32893
  try { return { gguf: parseGguf(u8), bytes: u8, file }; } catch (e) { if (!e.needBytes) throw e; n = e.needBytes; }
32894
  }
32895
  }
32896
 
 
 
 
 
 
 
 
 
 
 
32897
  // A local file as the source: a fetch-shaped function that answers ingestGguf's Range requests from a Blob (a GGUF
32898
  // the user picked, e.g. from a Hugging Face or LM Studio cache), so nothing is downloaded. Pass it as `fetch`.
32899
  // No ETag: an interrupted ingest resumes from the same file (same header and size), never from a download's state.
@@ -32929,7 +32958,7 @@ async function ingest({ url, key, plan, root = ROOT, format = FORMAT, fetch: fet
32929
  rangeBytes = 1 << 30, io = { OpfsWriter, readOpfsText, writeOpfsText } }) {
32930
  if (!plan || !plan.layout || !plan.units) throw new Error('ingestGguf: plan { layout, units } is required');
32931
  const t0 = performance.now();
32932
- const { gguf, bytes: headerBuf, file } = await readHeader(url, fetchFn, signal);
32933
  const layout = plan.layout(gguf);
32934
  const dir = `${root}/${key}`;
32935
  const storage = typeof navigator !== 'undefined' && navigator.storage;
@@ -32998,26 +33027,39 @@ async function ingest({ url, key, plan, root = ROOT, format = FORMAT, fetch: fet
32998
  let pos = units[startUnit].src;
32999
  for (let start = pos; start < last; start += rangeBytes) {
33000
  const end = Math.min(last, start + rangeBytes) - 1;
33001
- const r = await fetchFn(url, { headers: { Range: `bytes=${start}-${end}` }, signal, cache: 'no-store' });
33002
- if (r.status !== 206) throw new Error(`GGUF range ${start}-${end}: HTTP ${r.status}`);
33003
- const reader = r.body.getReader();
33004
- for (;;) {
33005
- const { done: eof, value } = await reader.read();
33006
- if (eof) break;
33007
- let off = 0;
33008
- while (off < value.byteLength && ui < units.length) {
33009
- const u = units[ui];
33010
- if (pos < u.src) { const skip = Math.min(u.src - pos, value.byteLength - off); pos += skip; off += skip; continue; }
33011
- const take = Math.min(u.len - fill, value.byteLength - off);
33012
- unitBuf.set(value.subarray(off, off + take), fill);
33013
- fill += take; off += take; pos += take;
33014
- if (fill === u.len) { await flushUnit(u); ui++; fill = 0; }
33015
- }
33016
- done = pos - first;
33017
- onProgress({ status: 'ingest', loaded: done, total: last - first, resumedFrom, written, secs: (performance.now() - t0) / 1000 });
33018
- if (written - quotaLog[quotaLog.length - 1].written > 4 * 2 ** 30 && storage && storage.estimate) {
33019
- const e = await storage.estimate();
33020
- quotaLog.push({ written, quota: e.quota, usage: e.usage });
 
 
 
 
 
 
 
 
 
 
 
 
 
33021
  }
33022
  }
33023
  // Every unit before ui is written: flush, then record ui as the resume point.
@@ -33050,8 +33092,13 @@ async function ingest({ url, key, plan, root = ROOT, format = FORMAT, fetch: fet
33050
  // Ingest progress as hosts read it: a 'weights' event with byte counts. The spread goes first, so the
33051
  // event's own status ('ingest') cannot overwrite 'weights' (LocalMind's 2026-10-04 bug: a host's load
33052
  // watchdog, seeing no progress, killed a 37 GB first download).
 
 
33053
  export function ingestProgress(e) {
33054
- return e && e.status === 'ingest' ? { ...e, status: 'weights', loaded: e.loaded, total: e.total } : e;
 
 
 
33055
  }
33056
 
33057
  // ── The stores on disk: which are usable, which to remove ──
@@ -43900,6 +43947,7 @@ function guarded(src) {
43900
  }
43901
 
43902
  export class Qwen35MoeSsd extends Qwen3MoeSsd {
 
43903
  // Without a url, the pinned Hugging Face file; with one (a local serve, a layer cut), the OPFS
43904
  // directory is named after the file, never after rung 2a's model.
43905
  static async load(modelId = null, opts = {}) {
@@ -43910,7 +43958,7 @@ export class Qwen35MoeSsd extends Qwen3MoeSsd {
43910
  constructor(device, manifest, gguf, opts) {
43911
  super(device, manifest, gguf, opts);
43912
  const c = this.cfg;
43913
- if (c.arch !== 'qwen35moe') throw new Error(`Qwen35MoeSsd needs a qwen35moe GGUF, got ${c.arch}`);
43914
  if (c.ssm.dConv !== 4) throw new Error(`gdnConv assumes a 4-tap conv, got ${c.ssm.dConv}`);
43915
  if (c.ssm.dState !== 128 || c.ssm.dInner !== c.ssm.vHeads * c.ssm.dState) throw new Error('gdnStep assumes 128-wide heads');
43916
  // Weight type: Q8_0 (Qwen3.6, MiniCPM-V Q8_0) or Q4_0 (MiniCPM-V Q4_0: Q4_0 matrices and experts, Q6_K output).
@@ -44846,12 +44894,13 @@ export { FORMAT as STORE_FORMAT, OPFS_ROOT as STORE_ROOT };
44846
 
44847
  // ── GGUF ────────────────────────────────────────────────────────────────────
44848
  // qwen3moe (rung 2a) and qwen35moe (Qwen3.5/3.6 MoE, rung 2b: qwen35_moe_ssd.js) share the
44849
- // expert layout; qwen35moe adds the Gated DeltaNet (ssm.*), partial RoPE and a shared expert.
 
44850
  export function configFromGguf(kv) {
44851
  const a = kv['general.architecture'];
44852
- if (a !== 'qwen3moe' && a !== 'qwen35moe') throw new Error(`expected a qwen3moe or qwen35moe GGUF, got ${a}`);
44853
  const g = (k) => kv[`${a}.${k}`];
44854
- const extra = a !== 'qwen35moe' ? {} : {
44855
  ropeDims: g('rope.dimension_count'), shexpFf: g('expert_shared_feed_forward_length'),
44856
  attnInterval: g('full_attention_interval') || 4,
44857
  ssm: { dConv: g('ssm.conv_kernel'), dInner: g('ssm.inner_size'), dState: g('ssm.state_size'), vHeads: g('ssm.time_step_rank'), kHeads: g('ssm.group_count') },
 
8040
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy
8041
  // of the engine (Gemma4Mobile) and, with ple, builds the OPFS per-layer-embedding table itself. The worker then drives
8042
  // session.engine exactly as it drove its own engine. Pinned to the same anyformer as anyformer_models.js.
8043
+ const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.16/index.js';
8044
 
8045
  let anyformerLoad = null;
8046
  let session = null;
 
8185
  // rolled-in module URLs (moduleUrl()).
8186
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy of
8187
  // the engine (TernaryBonsai2); the worker drives session.engine as before and attaches DFlash / MTP itself.
8188
+ const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.16/index.js';
8189
  const DFLASH_URL = '__TERNARY_BONSAI2_DFLASH_URL__';
8190
  const MTP_URL = '__TERNARY_BONSAI2_MTP_URL__';
8191
  // MTP speculative decoding (Settings β†’ Models, default OFF; posted as `mtp` + `mtpDepth` on the
 
24155
  */
24156
  const THINK_CLOSE = -2;
24157
 
24158
+ export const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.16/index.js';
24159
 
24160
  // anyformer's progress events β†’ the engine events the SSD worker posts. The llama.cpp path reports 'download' (bytes
24161
  // into OPFS) and 'load' / 'plan'; a hand engine (diskformer back end) reports its own engine events, 'weights' with
 
32565
  // The model loads through anyformer (convergence plan, 2026-10-22): anyformer resolves the repo to diskformer's copy of
32566
  // the LFM2.5 engine (Lfm2Mobile) and returns a session with the same generate / reset / dispose. Pinned to an exact
32567
  // version; LocalMind's anyformer_models.js pins the same one.
32568
+ const ANYFORMER_URL = 'https://cdn.jsdelivr.net/npm/anyformer@0.4.16/index.js';
32569
 
32570
  let anyformerLoad = null;
32571
  let model = null;
 
32881
  // ── Ingest: GGUF (over HTTP Range, or a local file) β†’ OPFS, in the engine layout ──
32882
  export const storeKey = (file) => file.replace(/\.gguf$/i, '').toLowerCase().replace(/[^a-z0-9._-]+/g, '-');
32883
 
32884
+ // The header bytes stream with 'ingest-header' progress ({ loaded, total }): on a slow link the first 16 MB (more for a
32885
+ // large tokenizer) take minutes, and a host's watchdog must see the download moving (LocalMind 2026-10-24: at 0.1 MB/s
32886
+ // a silent header fetch ended Flint's ingest after 3 minutes).
32887
+ export async function readHeader(url, fetchFn, signal, onProgress = () => {}) {
32888
  let n = 16 << 20;
32889
  for (;;) {
32890
  const r = await fetchFn(url, { headers: { Range: `bytes=0-${n - 1}` }, signal, cache: 'no-store' });
 
32892
  const h = (name) => (r.headers && r.headers.get ? r.headers.get(name) : null);
32893
  const total = /\/(\d+)\s*$/.exec(h('content-range') || '');
32894
  const file = { size: total ? Number(total[1]) : null, etag: h('etag') }; // for the resume identity
32895
+ const want = Math.min(n, file.size ?? n);
32896
+ let u8;
32897
+ if (r.body && r.body.getReader) {
32898
+ const reader = r.body.getReader(), parts = [];
32899
+ let got = 0;
32900
+ for (;;) {
32901
+ const { done, value } = await reader.read();
32902
+ if (done) break;
32903
+ parts.push(value); got += value.byteLength;
32904
+ onProgress({ status: 'ingest-header', loaded: got, total: want });
32905
+ }
32906
+ u8 = new Uint8Array(got);
32907
+ let at = 0;
32908
+ for (const p of parts) { u8.set(p, at); at += p.byteLength; }
32909
+ } else {
32910
+ u8 = new Uint8Array(await r.arrayBuffer());
32911
+ }
32912
  try { return { gguf: parseGguf(u8), bytes: u8, file }; } catch (e) { if (!e.needBytes) throw e; n = e.needBytes; }
32913
  }
32914
  }
32915
 
32916
+ // A network failure while a range streams (the connection dropped, a 5xx or 429) is retried from the last byte
32917
+ // consumed, up to RETRIES times with growing pauses (1, 2, 4, 8 s, then 15 s); an abort, a 4xx and a write failure are
32918
+ // not. Every retry reports 'ingest-retry' ({ attempt, at, error }).
32919
+ const RETRIES = 6;
32920
+ const retryable = (e) => { e.retryable = true; return e; };
32921
+ const pause = (ms, signal) => new Promise((resolve, reject) => {
32922
+ const t = setTimeout(resolve, ms);
32923
+ if (signal) signal.addEventListener('abort', () => { clearTimeout(t); reject(signal.reason ?? new Error('aborted')); }, { once: true });
32924
+ });
32925
+
32926
  // A local file as the source: a fetch-shaped function that answers ingestGguf's Range requests from a Blob (a GGUF
32927
  // the user picked, e.g. from a Hugging Face or LM Studio cache), so nothing is downloaded. Pass it as `fetch`.
32928
  // No ETag: an interrupted ingest resumes from the same file (same header and size), never from a download's state.
 
32958
  rangeBytes = 1 << 30, io = { OpfsWriter, readOpfsText, writeOpfsText } }) {
32959
  if (!plan || !plan.layout || !plan.units) throw new Error('ingestGguf: plan { layout, units } is required');
32960
  const t0 = performance.now();
32961
+ const { gguf, bytes: headerBuf, file } = await readHeader(url, fetchFn, signal, onProgress);
32962
  const layout = plan.layout(gguf);
32963
  const dir = `${root}/${key}`;
32964
  const storage = typeof navigator !== 'undefined' && navigator.storage;
 
33027
  let pos = units[startUnit].src;
33028
  for (let start = pos; start < last; start += rangeBytes) {
33029
  const end = Math.min(last, start + rangeBytes) - 1;
33030
+ for (let attempt = 1; pos <= end; attempt++) {
33031
+ try {
33032
+ // from pos, not start: a retry asks only for the bytes this range has not delivered yet
33033
+ const r = await fetchFn(url, { headers: { Range: `bytes=${pos}-${end}` }, signal, cache: 'no-store' }).catch((e) => { throw retryable(e); });
33034
+ if (r.status !== 206) {
33035
+ const e = new Error(`GGUF range ${pos}-${end}: HTTP ${r.status}`);
33036
+ throw r.status >= 500 || r.status === 429 ? retryable(e) : e;
33037
+ }
33038
+ const reader = r.body.getReader();
33039
+ for (;;) {
33040
+ const { done: eof, value } = await reader.read().catch((e) => { throw retryable(e); });
33041
+ if (eof) break;
33042
+ let off = 0;
33043
+ while (off < value.byteLength && ui < units.length) {
33044
+ const u = units[ui];
33045
+ if (pos < u.src) { const skip = Math.min(u.src - pos, value.byteLength - off); pos += skip; off += skip; continue; }
33046
+ const take = Math.min(u.len - fill, value.byteLength - off);
33047
+ unitBuf.set(value.subarray(off, off + take), fill);
33048
+ fill += take; off += take; pos += take;
33049
+ if (fill === u.len) { await flushUnit(u); ui++; fill = 0; }
33050
+ }
33051
+ done = pos - first;
33052
+ onProgress({ status: 'ingest', loaded: done, total: last - first, resumedFrom, written, secs: (performance.now() - t0) / 1000 });
33053
+ if (written - quotaLog[quotaLog.length - 1].written > 4 * 2 ** 30 && storage && storage.estimate) {
33054
+ const e = await storage.estimate();
33055
+ quotaLog.push({ written, quota: e.quota, usage: e.usage });
33056
+ }
33057
+ }
33058
+ if (pos <= end) throw retryable(new Error(`GGUF range ended at byte ${pos}, expected ${end + 1}`));
33059
+ } catch (e) {
33060
+ if ((signal && signal.aborted) || !e.retryable || attempt >= RETRIES) throw e;
33061
+ onProgress({ status: 'ingest-retry', attempt, at: pos - first, total: last - first, error: String(e && e.message || e) });
33062
+ await pause(Math.min(15000, 1000 * 2 ** (attempt - 1)), signal);
33063
  }
33064
  }
33065
  // Every unit before ui is written: flush, then record ui as the resume point.
 
33092
  // Ingest progress as hosts read it: a 'weights' event with byte counts. The spread goes first, so the
33093
  // event's own status ('ingest') cannot overwrite 'weights' (LocalMind's 2026-10-04 bug: a host's load
33094
  // watchdog, seeing no progress, killed a 37 GB first download).
33095
+ // The header download and a retry pause count as progress too ('weights' with phase 'header' / 'retry'), so a watchdog
33096
+ // that waits for 'weights' keeps a slow or flaky download alive.
33097
  export function ingestProgress(e) {
33098
+ if (e && e.status === 'ingest') return { ...e, status: 'weights', loaded: e.loaded, total: e.total };
33099
+ if (e && e.status === 'ingest-header') return { ...e, status: 'weights', phase: 'header', loaded: e.loaded, total: e.total };
33100
+ if (e && e.status === 'ingest-retry') return { ...e, status: 'weights', phase: 'retry', loaded: e.at, total: e.total };
33101
+ return e;
33102
  }
33103
 
33104
  // ── The stores on disk: which are usable, which to remove ──
 
43947
  }
43948
 
43949
  export class Qwen35MoeSsd extends Qwen3MoeSsd {
43950
+ static archs = ['qwen35moe'];
43951
  // Without a url, the pinned Hugging Face file; with one (a local serve, a layer cut), the OPFS
43952
  // directory is named after the file, never after rung 2a's model.
43953
  static async load(modelId = null, opts = {}) {
 
43958
  constructor(device, manifest, gguf, opts) {
43959
  super(device, manifest, gguf, opts);
43960
  const c = this.cfg;
43961
+ if (!this.constructor.archs.includes(c.arch)) throw new Error(`${this.constructor.name} needs a ${this.constructor.archs.join(' or ')} GGUF, got ${c.arch}`);
43962
  if (c.ssm.dConv !== 4) throw new Error(`gdnConv assumes a 4-tap conv, got ${c.ssm.dConv}`);
43963
  if (c.ssm.dState !== 128 || c.ssm.dInner !== c.ssm.vHeads * c.ssm.dState) throw new Error('gdnStep assumes 128-wide heads');
43964
  // Weight type: Q8_0 (Qwen3.6, MiniCPM-V Q8_0) or Q4_0 (MiniCPM-V Q4_0: Q4_0 matrices and experts, Q6_K output).
 
44894
 
44895
  // ── GGUF ────────────────────────────────────────────────────────────────────
44896
  // qwen3moe (rung 2a) and qwen35moe (Qwen3.5/3.6 MoE, rung 2b: qwen35_moe_ssd.js) share the
44897
+ // expert layout; qwen35moe adds the Gated DeltaNet (ssm.*), partial RoPE and a shared expert. clover_moe (Clover,
44898
+ // block diffusion on Qwen3.6: clover_moe_ssd.js) is qwen35moe plus per-DeltaNet-layer preview tensors.
44899
  export function configFromGguf(kv) {
44900
  const a = kv['general.architecture'];
44901
+ if (a !== 'qwen3moe' && a !== 'qwen35moe' && a !== 'clover_moe') throw new Error(`expected a qwen3moe, qwen35moe or clover_moe GGUF, got ${a}`);
44902
  const g = (k) => kv[`${a}.${k}`];
44903
+ const extra = a === 'qwen3moe' ? {} : {
44904
  ropeDims: g('rope.dimension_count'), shexpFf: g('expert_shared_feed_forward_length'),
44905
  attnInterval: g('full_attention_interval') || 4,
44906
  ssm: { dConv: g('ssm.conv_kernel'), dInner: g('ssm.inner_size'), dState: g('ssm.state_size'), vHeads: g('ssm.time_step_rank'), kHeads: g('ssm.group_count') },