abhimittal commited on
Commit
58a287c
·
verified ·
1 Parent(s): 0d67885

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. live.html +16 -6
live.html CHANGED
@@ -79,7 +79,7 @@ the rejection sampling below is the actual algorithm on actual model logits.
79
  <a href="index.html">← back to the interactive explainer</a></p>
80
 
81
  <div class="card">
82
- <button id="loadBtn">Load models (~70 MB, cached after first visit)</button>
83
  <span id="status"></span>
84
  <div id="loadWarn" class="warn"></div>
85
  </div>
@@ -123,9 +123,19 @@ a 70B cloud cross-check) you can run locally with <code>python app.py</code>.</p
123
  </main>
124
 
125
  <script type="module">
126
- import { AutoTokenizer, AutoModelForCausalLM, Tensor }
127
  from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.5.2";
128
 
 
 
 
 
 
 
 
 
 
 
129
  const $ = id => document.getElementById(id);
130
  const esc = s => s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
131
  const vis = t => t.trim() === "" ? t.replace(/ /g,"·") || "·" : t;
@@ -187,18 +197,18 @@ $("loadBtn").onclick = async () => {
187
  tok = await AutoTokenizer.from_pretrained("Xenova/distilgpt2");
188
  status("loading draft (distilgpt2)…");
189
  draft = await AutoModelForCausalLM.from_pretrained("Xenova/distilgpt2",
190
- { dtype: "q8", device, progress_callback: progress });
191
  status("loading target (gpt2)…");
192
  target = await AutoModelForCausalLM.from_pretrained("Xenova/gpt2",
193
- { dtype: "q8", device, progress_callback: progress });
194
  } catch (e) {
195
  if (device === "webgpu"){ // some GPUs fail on q8 — retry on wasm
196
  $("loadWarn").textContent = "WebGPU load failed, retrying on WASM…";
197
  device = "wasm";
198
  draft = await AutoModelForCausalLM.from_pretrained("Xenova/distilgpt2",
199
- { dtype: "q8", device, progress_callback: progress });
200
  target = await AutoModelForCausalLM.from_pretrained("Xenova/gpt2",
201
- { dtype: "q8", device, progress_callback: progress });
202
  } else { status("load failed: " + e.message); $("loadBtn").disabled = false; return; }
203
  }
204
  status(`ready · running on ${device}`);
 
79
  <a href="index.html">← back to the interactive explainer</a></p>
80
 
81
  <div class="card">
82
+ <button id="loadBtn">Load models (~215 MB, cached after first visit)</button>
83
  <span id="status"></span>
84
  <div id="loadWarn" class="warn"></div>
85
  </div>
 
123
  </main>
124
 
125
  <script type="module">
126
+ import { AutoTokenizer, AutoModelForCausalLM, Tensor, env }
127
  from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.5.2";
128
 
129
+ // ?local=1 → serve models from ./models/ (offline mirrors, CI testing)
130
+ if (new URLSearchParams(location.search).get("local")) {
131
+ env.allowRemoteModels = false;
132
+ env.allowLocalModels = true;
133
+ env.localModelPath = "./models/";
134
+ }
135
+ // pin the small legacy quantized files — plain {dtype:"q8"} resolves to the
136
+ // much larger model_quantized.onnx (237 MB) on these repos
137
+ const MODEL_OPTS = { model_file_name: "decoder_model_merged", dtype: "q8" };
138
+
139
  const $ = id => document.getElementById(id);
140
  const esc = s => s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
141
  const vis = t => t.trim() === "" ? t.replace(/ /g,"·") || "·" : t;
 
197
  tok = await AutoTokenizer.from_pretrained("Xenova/distilgpt2");
198
  status("loading draft (distilgpt2)…");
199
  draft = await AutoModelForCausalLM.from_pretrained("Xenova/distilgpt2",
200
+ { ...MODEL_OPTS, device, progress_callback: progress });
201
  status("loading target (gpt2)…");
202
  target = await AutoModelForCausalLM.from_pretrained("Xenova/gpt2",
203
+ { ...MODEL_OPTS, device, progress_callback: progress });
204
  } catch (e) {
205
  if (device === "webgpu"){ // some GPUs fail on q8 — retry on wasm
206
  $("loadWarn").textContent = "WebGPU load failed, retrying on WASM…";
207
  device = "wasm";
208
  draft = await AutoModelForCausalLM.from_pretrained("Xenova/distilgpt2",
209
+ { ...MODEL_OPTS, device, progress_callback: progress });
210
  target = await AutoModelForCausalLM.from_pretrained("Xenova/gpt2",
211
+ { ...MODEL_OPTS, device, progress_callback: progress });
212
  } else { status("load failed: " + e.message); $("loadBtn").disabled = false; return; }
213
  }
214
  status(`ready · running on ${device}`);