Spaces:
Running
Running
NakliTechie commited on
Commit ·
c0126f8
1
Parent(s): d9e4ace
Sync from GitHub 2026-10-28T14:14:37Z
Browse files- index.html +65 -28
index.html
CHANGED
|
@@ -2674,7 +2674,7 @@
|
|
| 2674 |
<li><strong>Ternary Bonsai 2 27B</strong> (~5.9 GB) — text + agent. PrismML's Ternary Bonsai 2 27B (Sept 2026; ternary 1.75-bit weights, Qwen3.8-27B backbone, 98% of the full-precision model's benchmark score) on a from-scratch WebGPU engine: hand-written WGSL for ternary dequant + Gated-DeltaNet linear attention, reading the PTQ1_0 GGUF directly. Ported from <em>webml-community/ternary-bonsai-2-webgpu-kernels</em>; Apache-2.0 weights. WebGPU-only — the biggest in-browser model here. A reasoning model: flip <strong>Show reasoning</strong> in Settings for its chain-of-thought. Text-only here (its optional vision tower is not loaded).</li>
|
| 2675 |
<li><strong>Underdog Saluki 27B</strong> (~7.9 GB) — text + agent. ConwayResearch's Underdog Saluki 27B 1.0 (Oct 2026): Qwen3.8-27B as one 2-bit-class IQ2-mix GGUF, tuned to keep tool calling intact (the vendor reports 88 of 120 on a frozen BFCL v4 tool-calling set, against 84 for the full-size model and 70 for Ternary Bonsai 2). Runs on a from-scratch WebGPU engine that reads the GGUF’s eleven llama.cpp block types directly; greedy output matches llama.cpp on the same file. The first load copies the 7.9 GB file into this browser’s on-device storage once (or pick the file you already have with <strong>Load .gguf from disk…</strong>); it needs about 8 GB of GPU memory. Apache-2.0 weights. A reasoning model: flip <strong>Show reasoning</strong> in Settings for its chain-of-thought. Text-only here (its optional vision add-on is not loaded).</li>
|
| 2676 |
<li><strong>Qwen3.5 4B</strong> (~3 GB) — text + image + agent (tool calling). Qwen3.5 at q4f16, Apache-2.0; its native 262K context is capped to 32K to keep browser memory bounded.</li>
|
| 2677 |
-
<li><strong>
|
| 2678 |
<li><strong>Gemini Nano</strong> (0 MB) — Google's on-device model built into Chrome, via the Prompt API. Zero download, no WebGPU. Chrome/Edge only; runs where your browser exposes <code>self.LanguageModel</code>. When Nano is already downloaded on desktop Chrome/Edge, LocalMind starts on it by default so you can chat with no model download.</li>
|
| 2679 |
<li><strong>LFM2.5 230M · WebGPU kernels</strong> (~140 MB) — the same LFM2.5 230M run on a from-scratch WebGPU engine whose every kernel (RoPE, RMSNorm, Q4_0 dequant, the LFM2 short-conv, GQA attention) is hand-written WGSL, reading a Q4_0 GGUF directly (no ONNX, no llama.cpp). Ported from <em>webml-community/lfm2-webgpu-kernels</em>. WebGPU-only, tuned for maximal decode throughput.</li>
|
| 2680 |
<li><strong>Gemma 4 E2B · WebGPU kernels</strong> (~2 GB) — text + agent. Google's Gemma 4 E2B (QAT mobile, int4) on a from-scratch WebGPU engine: hand-written WGSL for QAT int4 matmul, embed-gather-norm, RoPE/RMSNorm and GQA + sliding-window attention, reading the QAT-mobile weights directly. Ported from <em>webml-community/gemma-4-webgpu-kernels</em>. WebGPU-only. About 4× the ONNX Gemma 4 E2B’s decode speed on the same Mac (171 vs 42 tok/s, M4 Pro); text-only.</li>
|
|
@@ -2996,7 +2996,7 @@
|
|
| 2996 |
<option value="ternary-bonsai-2-27b-webgpu">Ternary Bonsai 2 27B · Agent (~5.9 GB)</option>
|
| 2997 |
<option value="underdog-saluki-27b">Underdog Saluki 27B · Agent (~7.9 GB)</option>
|
| 2998 |
<option value="qwen35-4b">Qwen3.5 4B · Vision + Agent (~3 GB)</option>
|
| 2999 |
-
<option value="
|
| 3000 |
<option value="gemini-nano">Gemini Nano · Built into Chrome (0 MB)</option>
|
| 3001 |
<option value="gemma4-e2b">Gemma 4 E2B · Multimodal (~1.5 GB)</option>
|
| 3002 |
<option value="gemma4-e4b">Gemma 4 E4B · Multimodal (~4.9 GB)</option>
|
|
@@ -7483,7 +7483,7 @@ reply({ type: 'worker-ready' });
|
|
| 7483 |
// recipe (fused fp16 for WebGPU) are in reference/MDLM-algorithm.md.
|
| 7484 |
|
| 7485 |
import * as ortDefault from 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.26.0/dist/ort.webgpu.min.mjs';
|
| 7486 |
-
import { AutoTokenizer } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 7487 |
|
| 7488 |
// Tiny-A2D Qwen3-0.6B MDLM token ids (tokenizer.mask_token_id / <|im_end|>).
|
| 7489 |
export const MASK_ID = 151669n;
|
|
@@ -8810,7 +8810,7 @@ self.onmessage = async (e) => {
|
|
| 8810 |
// WASM by default so it never contends with the chat model's WebGPU. On-device
|
| 8811 |
// only — the sole network touch is the one-time model fetch. (Non-English turns
|
| 8812 |
// route to the existing Whisper worker on the main thread instead.)
|
| 8813 |
-
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 8814 |
env.allowLocalModels = false;
|
| 8815 |
env.allowRemoteModels = true;
|
| 8816 |
|
|
@@ -8853,7 +8853,7 @@ self.onmessage = async (e) => {
|
|
| 8853 |
// every module fp16 (~1.0 GB); Light = q4f16 (~0.36 GB) for phones. (q4f16 was
|
| 8854 |
// degenerate on the 256M under 4.2.0; the 500M on this 3.7.1 pin is under test.)
|
| 8855 |
//
|
| 8856 |
-
// VERSION PIN — this vision worker pins transformers.js to 3.7.1, NOT the @4.3.
|
| 8857 |
// the chat/OCR workers use. Verified live 2026-08-21: on 4.2.0 SmolVLM's Idefics3
|
| 8858 |
// processor preprocesses fine but generation is DEGENERATE (pure gibberish); on
|
| 8859 |
// 3.7.1 the identical model+image+dtype produces a coherent, image-grounded
|
|
@@ -8940,7 +8940,7 @@ import {
|
|
| 8940 |
ChatterboxModel,
|
| 8941 |
AutoProcessor,
|
| 8942 |
Tensor,
|
| 8943 |
-
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 8944 |
|
| 8945 |
env.allowLocalModels = true;
|
| 8946 |
env.localModelPath = '/models/';
|
|
@@ -9055,6 +9055,7 @@ self.addEventListener('message', async (e) => {
|
|
| 9055 |
'onnx-community/Apertus-v1.1-4B-Instruct-ONNX', 'onnx-community/Qwen3-4B-ONNX',
|
| 9056 |
'onnx-community/granite-4.0-1b-ONNX-web', 'onnx-community/granite-4.0-micro-ONNX-web',
|
| 9057 |
'onnx-community/Ternary-Bonsai-4B-ONNX', // first-generation ternary 4B, replaced by Ternary Bonsai 2 4B (2026-10-16)
|
|
|
|
| 9058 |
];
|
| 9059 |
|
| 9060 |
const MODELS = {
|
|
@@ -9077,23 +9078,23 @@ self.addEventListener('message', async (e) => {
|
|
| 9077 |
// top_k 20. Apache-2.0, native tool calling.
|
| 9078 |
genConfig: { temperature: 0.7, top_k: 20, top_p: 0.8, max_new_tokens: 2048, repetition_penalty: 1.05 },
|
| 9079 |
},
|
| 9080 |
-
'
|
| 9081 |
-
id: 'LiquidAI/
|
| 9082 |
-
label: '
|
| 9083 |
dtype: 'q4f16',
|
| 9084 |
-
size: '~
|
| 9085 |
type: 'causal',
|
| 9086 |
multimodal: false,
|
| 9087 |
agentCapable: true,
|
| 9088 |
contextSize: 32768,
|
| 9089 |
-
// Liquid AI
|
| 9090 |
-
//
|
| 9091 |
-
//
|
| 9092 |
-
//
|
| 9093 |
-
//
|
| 9094 |
-
//
|
| 9095 |
-
//
|
| 9096 |
-
genConfig: { temperature: 0.
|
| 9097 |
},
|
| 9098 |
'gemini-nano': {
|
| 9099 |
id: 'chrome-builtin/gemini-nano',
|
|
@@ -10485,6 +10486,7 @@ self.addEventListener('message', async (e) => {
|
|
| 10485 |
const TOKEN_WEIGHTS = {
|
| 10486 |
qwen: [0.196, 0.549, 0.473, 0.515, 0.933, 0.717, 1.011, 0.488, 0.644, 0.612, 0.615, 0.291, 0.236, 0.371, 2.845],
|
| 10487 |
lfm2: [0.202, 0.578, 1.495, 2.353, 2.97, 2.964, 2.971, 2.494, 2.966, 2.956, 2.98, 0.485, 0.357, 0.446, 5.534],
|
|
|
|
| 10488 |
gemma: [0.199, 0.618, 0.28, 0.237, 0.659, 0.424, 0.908, 0.25, 0.361, 0.34, 0.331, 0.352, 0.233, 0.412, 2.692],
|
| 10489 |
minicpm5: [0.212, 0.427, 0.902, 1.846, 3.18, 3.191, 3.124, 1.986, 2.127, 1.452, 2.386, 1.054, 0.278, 0.626, 0.01],
|
| 10490 |
unknown: [0.244, 0.711, 1.719, 2.706, 3.657, 3.67, 3.593, 2.868, 3.411, 3.4, 3.427, 1.212, 0.411, 0.729, 6.364],
|
|
@@ -10502,7 +10504,7 @@ self.addEventListener('message', async (e) => {
|
|
| 10502 |
'gemma4-26b-a4b-ssd': 'gemma',
|
| 10503 |
'ternary-bonsai-2-2b-webgpu': 'qwen',
|
| 10504 |
'ternary-bonsai-2-4b-webgpu': 'qwen',
|
| 10505 |
-
'
|
| 10506 |
'lfm2-230m-gguf': 'lfm2',
|
| 10507 |
'lfm2-230m-webgpu': 'lfm2',
|
| 10508 |
'gemma4-e2b': 'gemma',
|
|
@@ -17620,7 +17622,7 @@ import {
|
|
| 17620 |
pipeline,
|
| 17621 |
AutoTokenizer,
|
| 17622 |
AutoModelForSequenceClassification,
|
| 17623 |
-
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 17624 |
|
| 17625 |
env.allowLocalModels = true;
|
| 17626 |
env.localModelPath = '/models/';
|
|
@@ -17931,7 +17933,7 @@ import {
|
|
| 17931 |
Sam3TrackerModel,
|
| 17932 |
AutoProcessor,
|
| 17933 |
RawImage,
|
| 17934 |
-
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 17935 |
|
| 17936 |
env.allowLocalModels = true;
|
| 17937 |
env.localModelPath = '/models/';
|
|
@@ -18072,7 +18074,7 @@ import {
|
|
| 18072 |
RawImage,
|
| 18073 |
TextStreamer,
|
| 18074 |
InterruptableStoppingCriteria,
|
| 18075 |
-
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 18076 |
|
| 18077 |
env.allowLocalModels = true;
|
| 18078 |
env.localModelPath = '/models/';
|
|
@@ -18245,7 +18247,7 @@ import {
|
|
| 18245 |
AutoTokenizer,
|
| 18246 |
WhisperForConditionalGeneration,
|
| 18247 |
full,
|
| 18248 |
-
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 18249 |
|
| 18250 |
env.allowLocalModels = true;
|
| 18251 |
env.localModelPath = '/models/';
|
|
@@ -18724,10 +18726,10 @@ __rdbCleanup();
|
|
| 18724 |
// would race the 'load' postMessage from the main thread — it can arrive
|
| 18725 |
// before the module-body handler is registered and get dropped. Kick off
|
| 18726 |
// the import eagerly and have the message handler await it.
|
| 18727 |
-
let env, AutoTokenizer, AutoModelForCausalLM, AutoProcessor, Gemma4ForConditionalGeneration, Qwen3_5ForConditionalGeneration, load_image, TextStreamer, InterruptableStoppingCriteria;
|
| 18728 |
let stopping_criteria;
|
| 18729 |
|
| 18730 |
-
const __modReady = import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.
|
| 18731 |
env = m.env;
|
| 18732 |
AutoTokenizer = m.AutoTokenizer;
|
| 18733 |
AutoModelForCausalLM = m.AutoModelForCausalLM;
|
|
@@ -18737,6 +18739,7 @@ const __modReady = import('https://cdn.jsdelivr.net/npm/@huggingface/transformer
|
|
| 18737 |
load_image = m.load_image;
|
| 18738 |
TextStreamer = m.TextStreamer;
|
| 18739 |
InterruptableStoppingCriteria = m.InterruptableStoppingCriteria;
|
|
|
|
| 18740 |
env.allowLocalModels = true;
|
| 18741 |
env.localModelPath = '/models/';
|
| 18742 |
env.allowRemoteModels = true;
|
|
@@ -18756,6 +18759,20 @@ function progressCallback(p) {
|
|
| 18756 |
self.postMessage({ type: 'progress', data: p });
|
| 18757 |
}
|
| 18758 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18759 |
async function loadCausal(modelId, dtype) {
|
| 18760 |
processor = null; tokenizer = null; model = null;
|
| 18761 |
|
|
@@ -18768,6 +18785,7 @@ async function loadCausal(modelId, dtype) {
|
|
| 18768 |
device: 'webgpu',
|
| 18769 |
progress_callback: progressCallback,
|
| 18770 |
});
|
|
|
|
| 18771 |
|
| 18772 |
// Warmup: compile WebGPU shaders with a single token
|
| 18773 |
self.postMessage({ type: 'warmup' });
|
|
@@ -18790,7 +18808,7 @@ async function loadMultimodal(modelId, dtype, modelClass) {
|
|
| 18790 |
? Qwen3_5ForConditionalGeneration
|
| 18791 |
: Gemma4ForConditionalGeneration;
|
| 18792 |
if (!ConditionalGenerationModel) {
|
| 18793 |
-
throw new Error('Transformers.js 4.3.
|
| 18794 |
}
|
| 18795 |
model = await ConditionalGenerationModel.from_pretrained(modelId, {
|
| 18796 |
dtype: dtype,
|
|
@@ -18807,8 +18825,10 @@ async function loadMultimodal(modelId, dtype, modelClass) {
|
|
| 18807 |
self.postMessage({ type: 'ready' });
|
| 18808 |
}
|
| 18809 |
|
| 18810 |
-
async function generateCausal(chatMessages, id, genConfig) {
|
| 18811 |
stopping_criteria.reset();
|
|
|
|
|
|
|
| 18812 |
|
| 18813 |
try {
|
| 18814 |
let inputs;
|
|
@@ -18816,6 +18836,7 @@ async function generateCausal(chatMessages, id, genConfig) {
|
|
| 18816 |
inputs = tokenizer.apply_chat_template(chatMessages, {
|
| 18817 |
add_generation_prompt: true,
|
| 18818 |
return_dict: true,
|
|
|
|
| 18819 |
});
|
| 18820 |
} catch (tplErr) {
|
| 18821 |
// The pinned transformers.js jinja can't parse some real templates — e.g.
|
|
@@ -18838,6 +18859,7 @@ async function generateCausal(chatMessages, id, genConfig) {
|
|
| 18838 |
inputs = tokenizer.apply_chat_template(chatMessages, {
|
| 18839 |
add_generation_prompt: true,
|
| 18840 |
return_dict: true,
|
|
|
|
| 18841 |
chat_template: raw,
|
| 18842 |
});
|
| 18843 |
salvaged = true;
|
|
@@ -18860,10 +18882,25 @@ async function generateCausal(chatMessages, id, genConfig) {
|
|
| 18860 |
}
|
| 18861 |
}
|
| 18862 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18863 |
const streamer = new TextStreamer(tokenizer, {
|
| 18864 |
skip_prompt: true,
|
| 18865 |
skip_special_tokens: true,
|
| 18866 |
callback_function: (text) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18867 |
self.postMessage({ type: 'token', token: text, id });
|
| 18868 |
},
|
| 18869 |
});
|
|
@@ -18992,7 +19029,7 @@ self.addEventListener('message', async (e) => {
|
|
| 18992 |
if (loadedType === 'multimodal') {
|
| 18993 |
await generateMultimodal(messages, id, attData, enableThinking, generationConfig);
|
| 18994 |
} else {
|
| 18995 |
-
await generateCausal(messages, id, generationConfig);
|
| 18996 |
}
|
| 18997 |
} else if (type === 'stop') {
|
| 18998 |
stopping_criteria.interrupt();
|
|
|
|
| 2674 |
<li><strong>Ternary Bonsai 2 27B</strong> (~5.9 GB) — text + agent. PrismML's Ternary Bonsai 2 27B (Sept 2026; ternary 1.75-bit weights, Qwen3.8-27B backbone, 98% of the full-precision model's benchmark score) on a from-scratch WebGPU engine: hand-written WGSL for ternary dequant + Gated-DeltaNet linear attention, reading the PTQ1_0 GGUF directly. Ported from <em>webml-community/ternary-bonsai-2-webgpu-kernels</em>; Apache-2.0 weights. WebGPU-only — the biggest in-browser model here. A reasoning model: flip <strong>Show reasoning</strong> in Settings for its chain-of-thought. Text-only here (its optional vision tower is not loaded).</li>
|
| 2675 |
<li><strong>Underdog Saluki 27B</strong> (~7.9 GB) — text + agent. ConwayResearch's Underdog Saluki 27B 1.0 (Oct 2026): Qwen3.8-27B as one 2-bit-class IQ2-mix GGUF, tuned to keep tool calling intact (the vendor reports 88 of 120 on a frozen BFCL v4 tool-calling set, against 84 for the full-size model and 70 for Ternary Bonsai 2). Runs on a from-scratch WebGPU engine that reads the GGUF’s eleven llama.cpp block types directly; greedy output matches llama.cpp on the same file. The first load copies the 7.9 GB file into this browser’s on-device storage once (or pick the file you already have with <strong>Load .gguf from disk…</strong>); it needs about 8 GB of GPU memory. Apache-2.0 weights. A reasoning model: flip <strong>Show reasoning</strong> in Settings for its chain-of-thought. Text-only here (its optional vision add-on is not loaded).</li>
|
| 2676 |
<li><strong>Qwen3.5 4B</strong> (~3 GB) — text + image + agent (tool calling). Qwen3.5 at q4f16, Apache-2.0; its native 262K context is capped to 32K to keep browser memory bounded.</li>
|
| 2677 |
+
<li><strong>LFM3 1.7B</strong> (~1.4 GB) — text + agent (tool calling). Liquid AI's LFM3-1.7B (Oct 2026), post-trained for agent use, on a new hybrid of short convolutions, sliding-window and global attention. Its tokenizer spends 3 to 4 times fewer tokens on Indic scripts than LFM2.5. A reasoning model: flip <strong>Show reasoning</strong> in Settings for its chain-of-thought. q4f16, 32K context.</li>
|
| 2678 |
<li><strong>Gemini Nano</strong> (0 MB) — Google's on-device model built into Chrome, via the Prompt API. Zero download, no WebGPU. Chrome/Edge only; runs where your browser exposes <code>self.LanguageModel</code>. When Nano is already downloaded on desktop Chrome/Edge, LocalMind starts on it by default so you can chat with no model download.</li>
|
| 2679 |
<li><strong>LFM2.5 230M · WebGPU kernels</strong> (~140 MB) — the same LFM2.5 230M run on a from-scratch WebGPU engine whose every kernel (RoPE, RMSNorm, Q4_0 dequant, the LFM2 short-conv, GQA attention) is hand-written WGSL, reading a Q4_0 GGUF directly (no ONNX, no llama.cpp). Ported from <em>webml-community/lfm2-webgpu-kernels</em>. WebGPU-only, tuned for maximal decode throughput.</li>
|
| 2680 |
<li><strong>Gemma 4 E2B · WebGPU kernels</strong> (~2 GB) — text + agent. Google's Gemma 4 E2B (QAT mobile, int4) on a from-scratch WebGPU engine: hand-written WGSL for QAT int4 matmul, embed-gather-norm, RoPE/RMSNorm and GQA + sliding-window attention, reading the QAT-mobile weights directly. Ported from <em>webml-community/gemma-4-webgpu-kernels</em>. WebGPU-only. About 4× the ONNX Gemma 4 E2B’s decode speed on the same Mac (171 vs 42 tok/s, M4 Pro); text-only.</li>
|
|
|
|
| 2996 |
<option value="ternary-bonsai-2-27b-webgpu">Ternary Bonsai 2 27B · Agent (~5.9 GB)</option>
|
| 2997 |
<option value="underdog-saluki-27b">Underdog Saluki 27B · Agent (~7.9 GB)</option>
|
| 2998 |
<option value="qwen35-4b">Qwen3.5 4B · Vision + Agent (~3 GB)</option>
|
| 2999 |
+
<option value="lfm3-1.7b">LFM3 1.7B · Agent (~1.4 GB)</option>
|
| 3000 |
<option value="gemini-nano">Gemini Nano · Built into Chrome (0 MB)</option>
|
| 3001 |
<option value="gemma4-e2b">Gemma 4 E2B · Multimodal (~1.5 GB)</option>
|
| 3002 |
<option value="gemma4-e4b">Gemma 4 E4B · Multimodal (~4.9 GB)</option>
|
|
|
|
| 7483 |
// recipe (fused fp16 for WebGPU) are in reference/MDLM-algorithm.md.
|
| 7484 |
|
| 7485 |
import * as ortDefault from 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.26.0/dist/ort.webgpu.min.mjs';
|
| 7486 |
+
import { AutoTokenizer } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 7487 |
|
| 7488 |
// Tiny-A2D Qwen3-0.6B MDLM token ids (tokenizer.mask_token_id / <|im_end|>).
|
| 7489 |
export const MASK_ID = 151669n;
|
|
|
|
| 8810 |
// WASM by default so it never contends with the chat model's WebGPU. On-device
|
| 8811 |
// only — the sole network touch is the one-time model fetch. (Non-English turns
|
| 8812 |
// route to the existing Whisper worker on the main thread instead.)
|
| 8813 |
+
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 8814 |
env.allowLocalModels = false;
|
| 8815 |
env.allowRemoteModels = true;
|
| 8816 |
|
|
|
|
| 8853 |
// every module fp16 (~1.0 GB); Light = q4f16 (~0.36 GB) for phones. (q4f16 was
|
| 8854 |
// degenerate on the 256M under 4.2.0; the 500M on this 3.7.1 pin is under test.)
|
| 8855 |
//
|
| 8856 |
+
// VERSION PIN — this vision worker pins transformers.js to 3.7.1, NOT the @4.3.2
|
| 8857 |
// the chat/OCR workers use. Verified live 2026-08-21: on 4.2.0 SmolVLM's Idefics3
|
| 8858 |
// processor preprocesses fine but generation is DEGENERATE (pure gibberish); on
|
| 8859 |
// 3.7.1 the identical model+image+dtype produces a coherent, image-grounded
|
|
|
|
| 8940 |
ChatterboxModel,
|
| 8941 |
AutoProcessor,
|
| 8942 |
Tensor,
|
| 8943 |
+
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 8944 |
|
| 8945 |
env.allowLocalModels = true;
|
| 8946 |
env.localModelPath = '/models/';
|
|
|
|
| 9055 |
'onnx-community/Apertus-v1.1-4B-Instruct-ONNX', 'onnx-community/Qwen3-4B-ONNX',
|
| 9056 |
'onnx-community/granite-4.0-1b-ONNX-web', 'onnx-community/granite-4.0-micro-ONNX-web',
|
| 9057 |
'onnx-community/Ternary-Bonsai-4B-ONNX', // first-generation ternary 4B, replaced by Ternary Bonsai 2 4B (2026-10-16)
|
| 9058 |
+
'LiquidAI/LFM2.5-1.2B-Instruct-ONNX', // replaced by LFM3 1.7B (2026-10-28)
|
| 9059 |
];
|
| 9060 |
|
| 9061 |
const MODELS = {
|
|
|
|
| 9078 |
// top_k 20. Apache-2.0, native tool calling.
|
| 9079 |
genConfig: { temperature: 0.7, top_k: 20, top_p: 0.8, max_new_tokens: 2048, repetition_penalty: 1.05 },
|
| 9080 |
},
|
| 9081 |
+
'lfm3-1.7b': {
|
| 9082 |
+
id: 'LiquidAI/LFM3-1.7B-ONNX',
|
| 9083 |
+
label: 'LFM3 1.7B',
|
| 9084 |
dtype: 'q4f16',
|
| 9085 |
+
size: '~1.4 GB',
|
| 9086 |
type: 'causal',
|
| 9087 |
multimodal: false,
|
| 9088 |
agentCapable: true,
|
| 9089 |
contextSize: 32768,
|
| 9090 |
+
// Liquid AI LFM3-1.7B (2026-10-23), replacing LFM2.5 1.2B (2026-10-28). model_type 'lfm3' (13 short-conv,
|
| 9091 |
+
// 5 sliding-window and 6 global attention layers), which transformers.js loads from 4.3.2 on. First-party
|
| 9092 |
+
// ONNX (q4f16, 1.38 GB). Post-trained for agent harnesses; its tool calls are the Qwen3-Coder XML form
|
| 9093 |
+
// (<tool_call><function=…><parameter=…>), which parseToolCalls already reads. A reasoning model: the
|
| 9094 |
+
// template thinks unless enable_thinking is false, so generateCausal passes the Show-reasoning toggle.
|
| 9095 |
+
// LFM Open License v1.0. Native 256K context capped to 32K. Liquid's "general" sampling (chat, tools,
|
| 9096 |
+
// agents): temperature 0.1, top_k 50, repetition_penalty 1.1, no top_p.
|
| 9097 |
+
genConfig: { temperature: 0.1, top_k: 50, top_p: 1.0, max_new_tokens: 2048, repetition_penalty: 1.1 },
|
| 9098 |
},
|
| 9099 |
'gemini-nano': {
|
| 9100 |
id: 'chrome-builtin/gemini-nano',
|
|
|
|
| 10486 |
const TOKEN_WEIGHTS = {
|
| 10487 |
qwen: [0.196, 0.549, 0.473, 0.515, 0.933, 0.717, 1.011, 0.488, 0.644, 0.612, 0.615, 0.291, 0.236, 0.371, 2.845],
|
| 10488 |
lfm2: [0.202, 0.578, 1.495, 2.353, 2.97, 2.964, 2.971, 2.494, 2.966, 2.956, 2.98, 0.485, 0.357, 0.446, 5.534],
|
| 10489 |
+
lfm3: [0.218, 0.387, 0.578, 0.682, 0.851, 0.661, 0.858, 0.716, 0.682, 0.66, 0.643, 0.312, 0.334, 0.494, 2.457],
|
| 10490 |
gemma: [0.199, 0.618, 0.28, 0.237, 0.659, 0.424, 0.908, 0.25, 0.361, 0.34, 0.331, 0.352, 0.233, 0.412, 2.692],
|
| 10491 |
minicpm5: [0.212, 0.427, 0.902, 1.846, 3.18, 3.191, 3.124, 1.986, 2.127, 1.452, 2.386, 1.054, 0.278, 0.626, 0.01],
|
| 10492 |
unknown: [0.244, 0.711, 1.719, 2.706, 3.657, 3.67, 3.593, 2.868, 3.411, 3.4, 3.427, 1.212, 0.411, 0.729, 6.364],
|
|
|
|
| 10504 |
'gemma4-26b-a4b-ssd': 'gemma',
|
| 10505 |
'ternary-bonsai-2-2b-webgpu': 'qwen',
|
| 10506 |
'ternary-bonsai-2-4b-webgpu': 'qwen',
|
| 10507 |
+
'lfm3-1.7b': 'lfm3',
|
| 10508 |
'lfm2-230m-gguf': 'lfm2',
|
| 10509 |
'lfm2-230m-webgpu': 'lfm2',
|
| 10510 |
'gemma4-e2b': 'gemma',
|
|
|
|
| 17622 |
pipeline,
|
| 17623 |
AutoTokenizer,
|
| 17624 |
AutoModelForSequenceClassification,
|
| 17625 |
+
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 17626 |
|
| 17627 |
env.allowLocalModels = true;
|
| 17628 |
env.localModelPath = '/models/';
|
|
|
|
| 17933 |
Sam3TrackerModel,
|
| 17934 |
AutoProcessor,
|
| 17935 |
RawImage,
|
| 17936 |
+
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 17937 |
|
| 17938 |
env.allowLocalModels = true;
|
| 17939 |
env.localModelPath = '/models/';
|
|
|
|
| 18074 |
RawImage,
|
| 18075 |
TextStreamer,
|
| 18076 |
InterruptableStoppingCriteria,
|
| 18077 |
+
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 18078 |
|
| 18079 |
env.allowLocalModels = true;
|
| 18080 |
env.localModelPath = '/models/';
|
|
|
|
| 18247 |
AutoTokenizer,
|
| 18248 |
WhisperForConditionalGeneration,
|
| 18249 |
full,
|
| 18250 |
+
} from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm';
|
| 18251 |
|
| 18252 |
env.allowLocalModels = true;
|
| 18253 |
env.localModelPath = '/models/';
|
|
|
|
| 18726 |
// would race the 'load' postMessage from the main thread — it can arrive
|
| 18727 |
// before the module-body handler is registered and get dropped. Kick off
|
| 18728 |
// the import eagerly and have the message handler await it.
|
| 18729 |
+
let env, AutoTokenizer, AutoModelForCausalLM, AutoProcessor, Gemma4ForConditionalGeneration, Qwen3_5ForConditionalGeneration, load_image, TextStreamer, InterruptableStoppingCriteria, Tensor;
|
| 18730 |
let stopping_criteria;
|
| 18731 |
|
| 18732 |
+
const __modReady = import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2/+esm').then((m) => {
|
| 18733 |
env = m.env;
|
| 18734 |
AutoTokenizer = m.AutoTokenizer;
|
| 18735 |
AutoModelForCausalLM = m.AutoModelForCausalLM;
|
|
|
|
| 18739 |
load_image = m.load_image;
|
| 18740 |
TextStreamer = m.TextStreamer;
|
| 18741 |
InterruptableStoppingCriteria = m.InterruptableStoppingCriteria;
|
| 18742 |
+
Tensor = m.Tensor;
|
| 18743 |
env.allowLocalModels = true;
|
| 18744 |
env.localModelPath = '/models/';
|
| 18745 |
env.allowRemoteModels = true;
|
|
|
|
| 18759 |
self.postMessage({ type: 'progress', data: p });
|
| 18760 |
}
|
| 18761 |
|
| 18762 |
+
// LiquidAI's LFM3 ONNX export names its last-position input logits_to_keep (shape [1]); transformers.js 4.3.2 feeds
|
| 18763 |
+
// only num_logits_to_keep and rejects the run as "Missing the following inputs: logits_to_keep". Hide the input from
|
| 18764 |
+
// transformers.js's check and add it at the session's run, set to 1: generate() reads only the last position's logits.
|
| 18765 |
+
// Checked in Chrome on this Mac, 2026-10-28: a 20-token and a 1,176-token prompt both answer correctly.
|
| 18766 |
+
function feedLogitsToKeep(m) {
|
| 18767 |
+
const sess = m && m.sessions && m.sessions.model;
|
| 18768 |
+
if (!sess || !sess.inputNames.includes('logits_to_keep')) return;
|
| 18769 |
+
const names = sess.inputNames.filter((n) => n !== 'logits_to_keep');
|
| 18770 |
+
const one = new Tensor('int64', [1n], [1]).ort_tensor;
|
| 18771 |
+
const run = sess.run.bind(sess);
|
| 18772 |
+
Object.defineProperty(sess, 'inputNames', { value: names });
|
| 18773 |
+
sess.run = (feeds, opts) => run({ ...feeds, logits_to_keep: one }, opts);
|
| 18774 |
+
}
|
| 18775 |
+
|
| 18776 |
async function loadCausal(modelId, dtype) {
|
| 18777 |
processor = null; tokenizer = null; model = null;
|
| 18778 |
|
|
|
|
| 18785 |
device: 'webgpu',
|
| 18786 |
progress_callback: progressCallback,
|
| 18787 |
});
|
| 18788 |
+
feedLogitsToKeep(model);
|
| 18789 |
|
| 18790 |
// Warmup: compile WebGPU shaders with a single token
|
| 18791 |
self.postMessage({ type: 'warmup' });
|
|
|
|
| 18808 |
? Qwen3_5ForConditionalGeneration
|
| 18809 |
: Gemma4ForConditionalGeneration;
|
| 18810 |
if (!ConditionalGenerationModel) {
|
| 18811 |
+
throw new Error('Transformers.js 4.3.2 does not export ' + modelClass);
|
| 18812 |
}
|
| 18813 |
model = await ConditionalGenerationModel.from_pretrained(modelId, {
|
| 18814 |
dtype: dtype,
|
|
|
|
| 18825 |
self.postMessage({ type: 'ready' });
|
| 18826 |
}
|
| 18827 |
|
| 18828 |
+
async function generateCausal(chatMessages, id, genConfig, enableThinking) {
|
| 18829 |
stopping_criteria.reset();
|
| 18830 |
+
// Templates that think by default (LFM3) read enable_thinking; the others ignore it.
|
| 18831 |
+
const thinking = enableThinking === true;
|
| 18832 |
|
| 18833 |
try {
|
| 18834 |
let inputs;
|
|
|
|
| 18836 |
inputs = tokenizer.apply_chat_template(chatMessages, {
|
| 18837 |
add_generation_prompt: true,
|
| 18838 |
return_dict: true,
|
| 18839 |
+
enable_thinking: thinking,
|
| 18840 |
});
|
| 18841 |
} catch (tplErr) {
|
| 18842 |
// The pinned transformers.js jinja can't parse some real templates — e.g.
|
|
|
|
| 18859 |
inputs = tokenizer.apply_chat_template(chatMessages, {
|
| 18860 |
add_generation_prompt: true,
|
| 18861 |
return_dict: true,
|
| 18862 |
+
enable_thinking: thinking,
|
| 18863 |
chat_template: raw,
|
| 18864 |
});
|
| 18865 |
salvaged = true;
|
|
|
|
| 18882 |
}
|
| 18883 |
}
|
| 18884 |
|
| 18885 |
+
// A thinking template ends the prompt on an open <think> (LFM3), so the reply starts inside the thought: open
|
| 18886 |
+
// LocalMind's <|think|> marker first and swap the model's </think> for <|/think|>. With thinking off LFM3 still
|
| 18887 |
+
// opens <think> itself on some prompts (Liquid's card says so; seen on a 1,176-token prompt), so that becomes
|
| 18888 |
+
// <|think|> too. Both tags are one token there, so each arrives whole in one streamer chunk.
|
| 18889 |
+
const promptText = thinking ? tokenizer.decode(inputs.input_ids.tolist()[0].slice(-4).map(Number)) : '';
|
| 18890 |
+
let inThink = thinking && promptText.trimEnd().endsWith('<think>');
|
| 18891 |
+
if (inThink) self.postMessage({ type: 'token', token: '<|think|>', id });
|
| 18892 |
const streamer = new TextStreamer(tokenizer, {
|
| 18893 |
skip_prompt: true,
|
| 18894 |
skip_special_tokens: true,
|
| 18895 |
callback_function: (text) => {
|
| 18896 |
+
if (!inThink && text.indexOf('<think>') !== -1) {
|
| 18897 |
+
text = text.split('<think>').join('<|think|>');
|
| 18898 |
+
inThink = true;
|
| 18899 |
+
}
|
| 18900 |
+
if (inThink && text.indexOf('</think>') !== -1) {
|
| 18901 |
+
text = text.split('</think>').join('<|/think|>');
|
| 18902 |
+
inThink = false;
|
| 18903 |
+
}
|
| 18904 |
self.postMessage({ type: 'token', token: text, id });
|
| 18905 |
},
|
| 18906 |
});
|
|
|
|
| 19029 |
if (loadedType === 'multimodal') {
|
| 19030 |
await generateMultimodal(messages, id, attData, enableThinking, generationConfig);
|
| 19031 |
} else {
|
| 19032 |
+
await generateCausal(messages, id, generationConfig, enableThinking);
|
| 19033 |
}
|
| 19034 |
} else if (type === 'stop') {
|
| 19035 |
stopping_criteria.interrupt();
|