force model cache (#751)
This commit is contained in:
parent
a4f40f3dc8
commit
16bf44f6e9
|
@ -38,11 +38,11 @@
|
||||||
},
|
},
|
||||||
stories42M: {
|
stories42M: {
|
||||||
url: "stories42M.bin",
|
url: "stories42M.bin",
|
||||||
seq_len: 256,
|
seq_len: 1024,
|
||||||
},
|
},
|
||||||
stories110M: {
|
stories110M: {
|
||||||
url: "stories110M.bin",
|
url: "stories110M.bin",
|
||||||
seq_len: 256,
|
seq_len: 1024,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,9 +124,17 @@
|
||||||
const prompt = document.querySelector("#prompt");
|
const prompt = document.querySelector("#prompt");
|
||||||
const clearBtn = document.querySelector("#clear-btn");
|
const clearBtn = document.querySelector("#clear-btn");
|
||||||
const runBtn = document.querySelector("#run");
|
const runBtn = document.querySelector("#run");
|
||||||
|
const modelSelect = document.querySelector("#model");
|
||||||
let runController = new AbortController();
|
let runController = new AbortController();
|
||||||
let isRunning = false;
|
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) => {
|
form.addEventListener("submit", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import init, { Model } from "./build/m.js";
|
import init, { Model } from "./build/m.js";
|
||||||
|
|
||||||
async function fetchArrayBuffer(url) {
|
async function fetchArrayBuffer(url) {
|
||||||
const res = await fetch(url, {
|
const cacheName = "llama2c-candle-cache";
|
||||||
cache: "force-cache",
|
const cache = await caches.open(cacheName);
|
||||||
});
|
const cachedResponse = await cache.match(url);
|
||||||
const data = await res.arrayBuffer();
|
if (cachedResponse) {
|
||||||
|
const data = await cachedResponse.arrayBuffer();
|
||||||
return new Uint8Array(data);
|
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 {
|
class Llama2C {
|
||||||
static instance = {};
|
static instance = {};
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
import init, { Decoder } from "./build/m.js";
|
import init, { Decoder } from "./build/m.js";
|
||||||
|
|
||||||
async function fetchArrayBuffer(url) {
|
async function fetchArrayBuffer(url) {
|
||||||
const res = await fetch(url, {
|
const cacheName = "whisper-candle-cache";
|
||||||
cache: "force-cache",
|
const cache = await caches.open(cacheName);
|
||||||
headers: {
|
const cachedResponse = await cache.match(url);
|
||||||
"Cache-Control": "public, max-age=31536000",
|
if (cachedResponse) {
|
||||||
},
|
const data = await cachedResponse.arrayBuffer();
|
||||||
});
|
|
||||||
const data = await res.arrayBuffer();
|
|
||||||
return new Uint8Array(data);
|
return new Uint8Array(data);
|
||||||
|
}
|
||||||
|
const res = await fetch(url, { cache: "force-cache" });
|
||||||
|
cache.put(url, res.clone());
|
||||||
|
return new Uint8Array(await res.arrayBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
class Whisper {
|
class Whisper {
|
||||||
static instance = {};
|
static instance = {};
|
||||||
// Retrieve the Whisper model. When called for the first time,
|
// Retrieve the Whisper model. When called for the first time,
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
//load the candle yolo wasm module
|
//load the candle yolo wasm module
|
||||||
import init, { Model, ModelPose } from "./build/m.js";
|
import init, { Model, ModelPose } from "./build/m.js";
|
||||||
|
|
||||||
|
async function fetchArrayBuffer(url) {
|
||||||
|
const cacheName = "yolo-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 Yolo {
|
class Yolo {
|
||||||
static instance = {};
|
static instance = {};
|
||||||
// Retrieve the YOLO model. When called for the first time,
|
// Retrieve the YOLO model. When called for the first time,
|
||||||
|
@ -11,9 +24,7 @@ class Yolo {
|
||||||
await init();
|
await init();
|
||||||
|
|
||||||
self.postMessage({ status: `loading model ${modelID}:${modelSize}` });
|
self.postMessage({ status: `loading model ${modelID}:${modelSize}` });
|
||||||
const modelRes = await fetch(modelURL);
|
const weightsArrayU8 = await fetchArrayBuffer(modelURL);
|
||||||
const yoloArrayBuffer = await modelRes.arrayBuffer();
|
|
||||||
const weightsArrayU8 = new Uint8Array(yoloArrayBuffer);
|
|
||||||
if (/pose/.test(modelID)) {
|
if (/pose/.test(modelID)) {
|
||||||
// if pose model, use ModelPose
|
// if pose model, use ModelPose
|
||||||
this.instance[modelID] = new ModelPose(weightsArrayU8, modelSize);
|
this.instance[modelID] = new ModelPose(weightsArrayU8, modelSize);
|
||||||
|
|
Loading…
Reference in New Issue