Skip to content

Commit

Permalink
Remove resolve/main from model record input
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieFRuan committed May 30, 2024
1 parent 45f41e6 commit c5adc8c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 90 deletions.
2 changes: 1 addition & 1 deletion examples/function-calling/src/function_calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
model_list: [
{
model:
"https://huggingface.co/mlc-ai/gorilla-openfunctions-v2-q4f16_1-MLC/resolve/main/",
"https://huggingface.co/mlc-ai/gorilla-openfunctions-v2-q4f16_1-MLC",
model_id: "gorilla-openfunctions-v2-q4f16_1",
model_lib:
"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/gorilla-openfunctions-v2/gorilla-openfunctions-v2-q4f16_1.wasm",
Expand Down
2 changes: 1 addition & 1 deletion examples/get-started/src/get_started.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
// const appConfig: webllm.AppConfig = {
// model_list: [
// {
// "model": "https://huggingface.co/mlc-ai/Llama-3-8B-Instruct-q4f32_1-MLC/resolve/main/",
// "model": "https://huggingface.co/mlc-ai/Llama-3-8B-Instruct-q4f32_1-MLC",
// "model_id": "Llama-3-8B-Instruct-q4f32_1-MLC",
// "model_lib": webllm.modelLibURLPrefix + webllm.modelVersion + "/Llama-3-8B-Instruct-q4f32_1-ctx4k_cs1k-webgpu.wasm",
// },
Expand Down
19 changes: 9 additions & 10 deletions src/cache_util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as tvmjs from "tvmjs";
import { AppConfig, ModelRecord, prebuiltAppConfig } from "./config";
import { cleanModelUrl } from "./support";

function findModelRecord(modelId: string, appConfig?: AppConfig): ModelRecord {
const matchedItem = appConfig?.model_list.find(
Expand All @@ -19,7 +20,7 @@ export async function hasModelInCache(
appConfig = prebuiltAppConfig;
}
const modelRecord = findModelRecord(modelId, appConfig);
const modelUrl = modelRecord.model;
const modelUrl = cleanModelUrl(modelRecord.model);
const cacheType = appConfig.useIndexedDBCache ? "indexeddb" : "cache";
return tvmjs.hasNDArrayInCache(modelUrl, "webllm/model", cacheType);
}
Expand Down Expand Up @@ -49,20 +50,17 @@ export async function deleteModelInCache(
appConfig = prebuiltAppConfig;
}
const modelRecord = findModelRecord(modelId, appConfig);
const modelUrl = cleanModelUrl(modelRecord.model);
let modelCache: tvmjs.ArtifactCacheTemplate;
if (appConfig.useIndexedDBCache) {
tvmjs.deleteNDArrayCache(modelRecord.model, "webllm/model", "indexeddb");
tvmjs.deleteNDArrayCache(modelUrl, "webllm/model", "indexeddb");
modelCache = new tvmjs.ArtifactIndexedDBCache("webllm/model");
} else {
tvmjs.deleteNDArrayCache(modelRecord.model, "webllm/model", "cache");
tvmjs.deleteNDArrayCache(modelUrl, "webllm/model", "cache");
modelCache = new tvmjs.ArtifactCache("webllm/model");
}
await modelCache.deleteInCache(
new URL("tokenizer.model", modelRecord.model).href,
);
await modelCache.deleteInCache(
new URL("tokenizer.json", modelRecord.model).href,
);
await modelCache.deleteInCache(new URL("tokenizer.model", modelUrl).href);
await modelCache.deleteInCache(new URL("tokenizer.json", modelUrl).href);
}

export async function deleteChatConfigInCache(
Expand All @@ -80,7 +78,8 @@ export async function deleteChatConfigInCache(
} else {
configCache = new tvmjs.ArtifactCache("webllm/config");
}
const configUrl = new URL("mlc-chat-config.json", modelRecord.model).href;
const modelUrl = cleanModelUrl(modelRecord.model);
const configUrl = new URL("mlc-chat-config.json", modelUrl).href;
await configCache.deleteInCache(configUrl);
}

Expand Down
Loading

0 comments on commit c5adc8c

Please sign in to comment.