Skip to content

Commit 4acfb1e

Browse files
authored
Update local deployment scripts and related fix (#102)
This PR separates local deployment config from global deployment config, fixes related deployment scripts, and updates the publicly available wasm/weights links.
1 parent 383bc52 commit 4acfb1e

8 files changed

+43
-62
lines changed

scripts/build_site.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ if [ -z ${MLC_LLM_HOME_SET} ]; then
1212
fi
1313

1414
rm -rf site/dist
15-
mkdir -p site/dist site/_inlcudes
15+
mkdir -p site/dist site/_includes
1616

1717
echo "Copy local configurations.."
18-
cp $1 site/global_config.json
18+
cp $1 site/llm-chat-config.json
1919
echo "Copy files..."
2020
cp web/llm_chat.html site/_includes
2121
cp web/llm_chat.js site/dist/
@@ -25,15 +25,4 @@ cp dist/tvmjs_runtime.wasi.js site/dist
2525
cp dist/tvmjs.bundle.js site/dist
2626
cp -r dist/tokenizers-cpp site/dist
2727

28-
if [ -d "$MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/params" ]; then
29-
mkdir -p site/dist/vicuna-v1-7b-q4f32_0
30-
cp -rf $MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/tokenizer.model site/dist/vicuna-v1-7b-q4f32_0/
31-
cp -rf $MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/vicuna-v1-7b-q4f32_0-webgpu.wasm site/dist/vicuna-v1-7b-q4f32_0/
32-
fi
33-
if [ -d "$MLC_LLM_HOME/dist/wizardlm-7b/params" ]; then
34-
mkdir -p site/dist/wizardlm-7b
35-
cp -rf $MLC_LLM_HOME/dist/wizardlm-7b/tokenizer.model site/dist/wizardlm-7b/
36-
cp -rf $MLC_LLM_HOME/dist/wizardlm-7b/wizardlm-7b-webgpu.wasm site/dist/wizardlm-7b/
37-
fi
38-
3928
cd site && jekyll b && cd ..

scripts/local_deploy_site.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@ if [ -z ${MLC_LLM_HOME_SET} ]; then
77
export MLC_LLM_HOME="${MLC_LLM_HOME:-mlc-llm}"
88
fi
99

10-
scripts/build_site.sh web/global_config.json
10+
scripts/build_site.sh web/local-config.json
1111

1212
echo "symlink parameter location to site.."
1313

1414
if [ -d "$MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/params" ]; then
15-
rm -rf site/_site/dist/vicuna-v1-7b-q4f32_0-params
15+
rm -rf site/_site/dist/vicuna-v1-7b-q4f32_0
16+
mkdir -p site/_site/dist/vicuna-v1-7b-q4f32_0
1617
ln -s $MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/params site/_site/dist/vicuna-v1-7b-q4f32_0/params
17-
ls site/_site/dist/vicuna-v1-7b-q4f32_0
18+
cp -rf $MLC_LLM_HOME/dist/vicuna-v1-7b-q4f32_0/vicuna-v1-7b-q4f32_0-webgpu.wasm site/_site/dist/vicuna-v1-7b-q4f32_0/
19+
fi
20+
if [ -d "$MLC_LLM_HOME/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/params" ]; then
21+
rm -rf site/_site/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0
22+
mkdir -p site/_site/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0
23+
ln -s $MLC_LLM_HOME/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/params site/_site/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/params
24+
cp -rf $MLC_LLM_HOME/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/RedPajama-INCITE-Chat-3B-v1-q4f32_0-webgpu.wasm site/_site/dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/
1825
fi
1926
if [ -d "$MLC_LLM_HOME/dist/wizardlm-7b/params" ]; then
20-
rm -rf site/_site/dist/wizardlm-7b-params
21-
ln -s $MLC_LLM_HOME/dist/wizardlm-7b/params site/_site/dist/wizardlm-7b-params
27+
rm -rf site/_site/dist/wizardlm-7b
28+
mkdir -p site/_site/dist/wizardlm-7b
29+
ln -s $MLC_LLM_HOME/dist/wizardlm-7b/params site/_site/dist/wizardlm-7b/params
30+
cp -rf $MLC_LLM_HOME/dist/wizardlm-7b/wizardlm-7b-webgpu.wasm site/_site/dist/wizardlm-7b/
2231
fi
2332

24-
25-
2633
cd site && jekyll serve --skip-initial-build --host localhost --baseurl /web-llm --port 8888

site/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dist
22
llm-chat-config.json
3-
global_config.json
43
_includes/stable_diffusion.html
54
_site

web/gh-page-config.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{
2-
"kvConfig": {
3-
"numLayers": 64,
4-
"shape": [32, 32, 128],
5-
"dtype": "float32"
2+
"url_dict": {
3+
"vicuna-v1-7b-q4f32_0": "https://huggingface.co/mlc-ai/mlc-chat-vicuna-v1-7b-q4f32_0/resolve/main/mlc-chat-config.json",
4+
"RedPajama-INCITE-Chat-3B-v1-q4f32_0": "https://huggingface.co/mlc-ai/mlc-chat-RedPajama-INCITE-Chat-3B-v1-q4f32_0/resolve/main/mlc-chat-config.json"
65
},
7-
"wasmUrl": "dist/vicuna-7b-v1/vicuna-7b-v1_webgpu.wasm",
8-
"cacheUrl": "https://huggingface.co/mlc-ai/web-lm/resolve/main/vicuna-7b-v1/",
9-
"tokenizer": "dist/vicuna-7b-v1/tokenizer.model",
10-
"maxGenLength": 1024,
11-
"meanGenLength": 256,
12-
"maxWindowLength": 2048
13-
}
6+
"model_lib_map": {
7+
"vicuna-v1-7b-q4f32_0": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/wasm/vicuna-v1-7b-q4f32_0-webgpu.wasm",
8+
"RedPajama-INCITE-Chat-3B-v1-q4f32_0": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/wasm/RedPajama-INCITE-Chat-3B-v1-q4f32_0-webgpu.wasm"
9+
}
10+
}

web/global_config.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

web/llm_chat.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Conversation {
8888
const role = item[0];
8989
const message = item[1];
9090
if (message !== undefined && message != "") {
91-
ret.push(message + this.seps[i % this.seps.length]+"\n");
91+
ret.push(message + this.seps[i % this.seps.length] + "\n");
9292
} else {
9393
ret.push(role + ":");
9494
}
@@ -118,7 +118,7 @@ class Conversation {
118118
}
119119

120120
function getConversation(conv_template) {
121-
if (conv_template == "vicuna-v1.1") {
121+
if (conv_template == "vicuna_v1.1") {
122122
return new Conversation({
123123
system: "A chat between a curious user and an artificial intelligence assistant. " +
124124
"The assistant gives helpful, detailed, and polite answers to the user's questions.",
@@ -145,12 +145,12 @@ function getConversation(conv_template) {
145145
roles: ["<human>", "<bot>"],
146146
messages: [],
147147
offset: 0,
148-
seps: ["",""],
148+
seps: ["", ""],
149149
separator_style: "RedPajamaChat",
150150
add_bos: false,
151151
})
152152
} else {
153-
throw Error("Unknown conv template "+ conv_template);
153+
throw Error("Unknown conv template " + conv_template);
154154
}
155155
};
156156

@@ -580,8 +580,8 @@ class LLMChatInstance {
580580
this.uiChat = document.getElementById("chatui-chat");
581581
this.uiChatInput = document.getElementById("chatui-input");
582582
this.uiChatInfoLabel = document.getElementById("chatui-info-label");
583-
var global_config = await (await fetch("global_config.json")).json();
584-
583+
var global_config = await (await fetch("llm-chat-config.json")).json();
584+
585585
var model_config_url = undefined;
586586
if (global_config.url_dict[this.model] === undefined) {
587587
model_config_url = this.model;
@@ -591,7 +591,6 @@ class LLMChatInstance {
591591
this.config = await (
592592
await fetch(model_config_url)
593593
).json();
594-
this.logger(this.config)
595594
this.config.wasmUrl = global_config.model_lib_map[this.config.model_lib]
596595
var last_slash = model_config_url.lastIndexOf("/");
597596
var base_url = model_config_url.substring(0, last_slash + 1);
@@ -603,6 +602,9 @@ class LLMChatInstance {
603602
}
604603

605604
async findTokenizerPath(base_url) {
605+
if (!base_url.startsWith("http")) {
606+
base_url = new URL(base_url, document.URL).href;
607+
}
606608
const tokenizer_model_path = new URL("tokenizer.model", base_url);
607609
var tokenizer_model = await fetch(tokenizer_model_path);
608610
if (tokenizer_model.ok) {
@@ -780,7 +782,7 @@ function handle_model_change() {
780782
function onChange() {
781783
localLLMChatIntance.reboot();
782784
localLLMChatIntance.model = e.value;
783-
localLLMChatIntance.logger("model changed to " +e.value)
785+
localLLMChatIntance.logger("model changed to " + e.value)
784786
}
785787
e.onchange = onChange;
786788
}

web/local-config.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{
2-
"kvConfig": {
3-
"numLayers": 64,
4-
"shape": [32, 32, 128],
5-
"dtype": "float32"
2+
"url_dict": {
3+
"vicuna-v1-7b-q4f32_0": "dist/vicuna-v1-7b-q4f32_0/params/mlc-chat-config.json",
4+
"RedPajama-INCITE-Chat-3B-v1-q4f32_0": "dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/params/mlc-chat-config.json"
65
},
7-
"wasmUrl": "dist/vicuna-7b-v1/vicuna-7b-v1_webgpu.wasm",
8-
"cacheUrl": "vicuna-7b-v1-params/",
9-
"tokenizer": "dist/vicuna-7b-v1/tokenizer.model",
10-
"maxGenLength": 1024,
11-
"meanGenLength": 256,
12-
"maxWindowLength": 2048
13-
}
6+
"model_lib_map": {
7+
"vicuna-v1-7b-q4f32_0": "dist/vicuna-v1-7b-q4f32_0/vicuna-v1-7b-q4f32_0-webgpu.wasm",
8+
"RedPajama-INCITE-Chat-3B-v1-q4f32_0": "dist/RedPajama-INCITE-Chat-3B-v1-q4f32_0/RedPajama-INCITE-Chat-3B-v1-q4f32_0-webgpu.wasm"
9+
}
10+
}

0 commit comments

Comments
 (0)