diff options
author | Radamés Ajna <radamajna@gmail.com> | 2023-09-05 20:53:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 05:53:31 +0200 |
commit | 16bf44f6e9ed89d68260baa7914277fa269dcaee (patch) | |
tree | 07d4752fa7f2a9e1f3248418253ab19baacfac6a /candle-wasm-examples/llama2-c | |
parent | a4f40f3dc881802daa973c8f4f89d133cfa25e2b (diff) | |
download | candle-16bf44f6e9ed89d68260baa7914277fa269dcaee.tar.gz candle-16bf44f6e9ed89d68260baa7914277fa269dcaee.tar.bz2 candle-16bf44f6e9ed89d68260baa7914277fa269dcaee.zip |
force model cache (#751)
Diffstat (limited to 'candle-wasm-examples/llama2-c')
-rw-r--r-- | candle-wasm-examples/llama2-c/lib-example.html | 12 | ||||
-rw-r--r-- | candle-wasm-examples/llama2-c/llama2cWorker.js | 16 |
2 files changed, 20 insertions, 8 deletions
diff --git a/candle-wasm-examples/llama2-c/lib-example.html b/candle-wasm-examples/llama2-c/lib-example.html index 5995f003..b5033c54 100644 --- a/candle-wasm-examples/llama2-c/lib-example.html +++ b/candle-wasm-examples/llama2-c/lib-example.html @@ -38,11 +38,11 @@ }, stories42M: { url: "stories42M.bin", - seq_len: 256, + seq_len: 1024, }, stories110M: { url: "stories110M.bin", - seq_len: 256, + seq_len: 1024, }, }; @@ -124,9 +124,17 @@ const prompt = document.querySelector("#prompt"); const clearBtn = document.querySelector("#clear-btn"); const runBtn = document.querySelector("#run"); + const modelSelect = document.querySelector("#model"); let runController = new AbortController(); let isRunning = false; + modelSelect.addEventListener("change", (e) => { + const model = MODELS[e.target.value]; + document.querySelector("#max-seq").max = model.seq_len; + document.querySelector("#max-seq").nextElementSibling.value = + model.seq_len; + }); + form.addEventListener("submit", async (e) => { e.preventDefault(); if (isRunning) { diff --git a/candle-wasm-examples/llama2-c/llama2cWorker.js b/candle-wasm-examples/llama2-c/llama2cWorker.js index e4229055..abaf3401 100644 --- a/candle-wasm-examples/llama2-c/llama2cWorker.js +++ b/candle-wasm-examples/llama2-c/llama2cWorker.js @@ -1,13 +1,17 @@ import init, { Model } from "./build/m.js"; async function fetchArrayBuffer(url) { - const res = await fetch(url, { - cache: "force-cache", - }); - const data = await res.arrayBuffer(); - return new Uint8Array(data); + const cacheName = "llama2c-candle-cache"; + const cache = await caches.open(cacheName); + const cachedResponse = await cache.match(url); + if (cachedResponse) { + const data = await cachedResponse.arrayBuffer(); + return new Uint8Array(data); + } + const res = await fetch(url, { cache: "force-cache" }); + cache.put(url, res.clone()); + return new Uint8Array(await res.arrayBuffer()); } - class Llama2C { static instance = {}; |