force cache with cache API and fix max seq

#2
by radames - opened
Files changed (2) hide show
  1. index.html +10 -2
  2. llama2cWorker.js +10 -6
index.html CHANGED
@@ -38,11 +38,11 @@
38
  },
39
  stories42M: {
40
  url: "stories42M.bin",
41
- seq_len: 256,
42
  },
43
  stories110M: {
44
  url: "stories110M.bin",
45
- seq_len: 256,
46
  },
47
  };
48
 
@@ -124,9 +124,17 @@
124
  const prompt = document.querySelector("#prompt");
125
  const clearBtn = document.querySelector("#clear-btn");
126
  const runBtn = document.querySelector("#run");
 
127
  let runController = new AbortController();
128
  let isRunning = false;
129
 
 
 
 
 
 
 
 
130
  form.addEventListener("submit", async (e) => {
131
  e.preventDefault();
132
  if (isRunning) {
 
38
  },
39
  stories42M: {
40
  url: "stories42M.bin",
41
+ seq_len: 1024,
42
  },
43
  stories110M: {
44
  url: "stories110M.bin",
45
+ seq_len: 1024,
46
  },
47
  };
48
 
 
124
  const prompt = document.querySelector("#prompt");
125
  const clearBtn = document.querySelector("#clear-btn");
126
  const runBtn = document.querySelector("#run");
127
+ const modelSelect = document.querySelector("#model");
128
  let runController = new AbortController();
129
  let isRunning = false;
130
 
131
+ modelSelect.addEventListener("change", (e) => {
132
+ const model = MODELS[e.target.value];
133
+ document.querySelector("#max-seq").max = model.seq_len;
134
+ document.querySelector("#max-seq").nextElementSibling.value =
135
+ model.seq_len;
136
+ });
137
+
138
  form.addEventListener("submit", async (e) => {
139
  e.preventDefault();
140
  if (isRunning) {
llama2cWorker.js CHANGED
@@ -1,13 +1,17 @@
1
  import init, { Model } from "./build/m.js";
2
 
3
  async function fetchArrayBuffer(url) {
4
- const res = await fetch(url, {
5
- cache: "force-cache",
6
- });
7
- const data = await res.arrayBuffer();
8
- return new Uint8Array(data);
 
 
 
 
 
9
  }
10
-
11
  class Llama2C {
12
  static instance = {};
13
 
 
1
  import init, { Model } from "./build/m.js";
2
 
3
  async function fetchArrayBuffer(url) {
4
+ const cacheName = "llama2c-candle-cache";
5
+ const cache = await caches.open(cacheName);
6
+ const cachedResponse = await cache.match(url);
7
+ if (cachedResponse) {
8
+ const data = await cachedResponse.arrayBuffer();
9
+ return new Uint8Array(data);
10
+ }
11
+ const res = await fetch(url, { cache: "force-cache" });
12
+ cache.put(url, res.clone());
13
+ return new Uint8Array(await res.arrayBuffer());
14
  }
 
15
  class Llama2C {
16
  static instance = {};
17