Skip to content

Commit 8a57430

Browse files
committed
Local deploy
1 parent 5d42190 commit 8a57430

File tree

9 files changed

+137
-3
lines changed

9 files changed

+137
-3
lines changed

scripts/build_site.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ echo "Copy local configurations.."
1212
cp $1 site/llm-chat-config.json
1313
echo "Copy files..."
1414
cp web/llm_chat.html site/_includes
15-
cp web/llm_chat.js site/dist
15+
cp web/llm_chat.js site/dist/
1616
cp web/llm_chat.css site/dist/
1717

18-
cp dist/tokenizer.model site/dist
1918
cp dist/tvmjs_runtime.wasi.js site/dist
2019
cp dist/tvmjs.bundle.js site/dist
2120
cp -r dist/sentencepiece site/dist
2221

22+
if [ -d "dist/vicuna-7b/params" ]; then
23+
mkdir -p site/dist/vicuna-7b
24+
cp -rf dist/models/vicuna-7b/tokenizer.model site/dist/vicuna-7b/
25+
cp -rf dist/vicuna-7b/vicuna-7b_webgpu.wasm site/dist/vicuna-7b/
26+
fi
27+
2328
cd site && jekyll b && cd ..

scripts/local_deploy_site.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ scripts/build_site.sh web/local-config.json
55

66
echo "symlink parameter location to site.."
77

8-
# ln -s `pwd`/dist/params site/_site/web-sd-shards-v1-5
8+
if [ -d "dist/vicuna-7b/params" ]; then
9+
rm -rf site/_site/vicuna-7b-params
10+
ln -s `pwd`/dist/vicuna-7b/params site/_site/vicuna-7b-params
11+
fi
912
cd site && jekyll serve --skip-initial-build --host localhost --baseurl /web-llm --port 8888

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from distutils.core import setup
2+
from setuptools import find_packages
3+
4+
# Note there is no need to setup when
5+
# running locally in this folder.
6+
7+
setup(
8+
name = "web-lmm",
9+
version = "0.1.0",
10+
license="Apache-2.0",
11+
description = "LMM on browser",
12+
author = "Web LMM contributors",
13+
url = "https://github.com/mlc-ai/web-llm",
14+
keywords = [],
15+
packages = find_packages(),
16+
install_requires = [
17+
"torch",
18+
"transformers"
19+
],
20+
classifiers = [
21+
"Development Status :: 3 - Alpha",
22+
"Intended Audience :: Developers",
23+
"Topic :: Software Development :: Build Tools",
24+
"License :: OSI Approved :: Apache Software License",
25+
"Programming Language :: Python :: 3",
26+
"Programming Language :: Python :: 3.6",
27+
],
28+
)

site/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
llm-chat-config.json
3+
_includes/stable_diffusion.html
4+
_site

site/_config.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
name: "Web LLM"
3+
short_name: "WebLLM"
4+
5+
url: https://mlc.ai/web-llm
6+
7+
exclude: [README.md, serve_local.sh]
8+
9+
plugins:
10+
- jekyll-remote-theme
11+
12+
remote_theme: mlc-ai/jekyll-theme-mlc
13+
14+
15+
# Colorize code snippets with the rogue module if we want to deploy on GH.
16+
highlighter: rouge
17+
18+
markdown: kramdown
19+
20+
# The path structure for blog posts.
21+
permalink: /blog/:year/:month/:day/:title.html
22+
23+
# Number of news stories on the front page.
24+
front_page_news: 8
25+
26+
# Base pathname for links.
27+
base: '/web-llm'
28+
29+
# make pages for the _projects folder
30+
collections:
31+
projects:
32+
output: true
33+
34+
course_title:
35+
36+
# Navigation bar links.
37+
navigation:
38+
- title: Home
39+
link: /
40+
- title: Github
41+
link: https://github.com/mlc-ai/web-llm

site/_includes/head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<meta http-equiv="origin-trial" content="Agx76XA0ITxMPF0Z8rbbcMllwuxsyp9qdtQaXlLqu1JUrdHB6FPonuyIKJ3CsBREUkeioJck4nn3KO0c0kkwqAMAAABJeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0Ojg4ODgiLCJmZWF0dXJlIjoiV2ViR1BVIiwiZXhwaXJ5IjoxNjkxNzExOTk5fQ==">
2+
<meta http-equiv="origin-trial" content="AnmwqQ1dtYDQTYkZ5iMtHdINCaxjE94uWQBKp2yOz1wPTcjSRtOHUGQG+r2BxsEuM0qhxTVnuTjyh31HgTeA8gsAAABZeyJvcmlnaW4iOiJodHRwczovL21sYy5haTo0NDMiLCJmZWF0dXJlIjoiV2ViR1BVIiwiZXhwaXJ5IjoxNjkxNzExOTk5LCJpc1N1YmRvbWFpbiI6dHJ1ZX0=">
3+
<script src="dist/tvmjs_runtime.wasi.js"></script>
4+
<script src="dist/tvmjs.bundle.js"></script>

site/_includes/llm_chat.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script>
2+
var tvmjsGlobalEnv = tvmjsGlobalEnv || {};
3+
</script>
4+
5+
<script type="module">
6+
async function getTokenizer(url) {
7+
const mod = await import("./dist/sentencepiece/index.js");
8+
return await mod.sentencePieceProcessor(url);
9+
}
10+
tvmjsGlobalEnv.sentencePieceProcessor = getTokenizer;
11+
</script>
12+
<script>
13+
function handleChatUIInputEnter(event) {
14+
if (event.keyCode === 13) {
15+
tvmjsGlobalEnv.asyncOnGenerate();
16+
}
17+
}
18+
async function getTokenizer(url) {
19+
const mod = await import("./dist/sentencepiece/index.js");
20+
return await mod.sentencePieceProcessor(url);
21+
}
22+
tvmjsGlobalEnv.sentencePieceProcessor = getTokenizer;
23+
</script>
24+
25+
<script src="dist/llm_chat.js"></script>
26+
<link href="dist/llm_chat.css" rel="stylesheet" type="text/css"/>
27+
<h2>Chat</h2>
28+
29+
<div class="chatui">
30+
<div class="chatui-chat" id="chatui-chat" height="100">
31+
</div>
32+
33+
<div class="chatui-inputarea">
34+
<input id="chatui-input" type="text" class="chatui-input" onkeypress="handleChatUIInputEnter(event)" placeholder="Enter your message...">
35+
<button class="chatui-send-btn" onclick="tvmjsGlobalEnv.asyncOnGenerate()">Send</button>
36+
</div>
37+
</div>

site/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
layout: default
3+
title: Home
4+
notitle: true
5+
---
6+
7+
8+
### Demo
9+
10+
{% include llm_chat.html %}
11+

web/llm_chat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class LLMChatPipeline {
283283

284284
async evaluate() {
285285
// run a canonicla evaluateion fo the flow
286+
this.#clearKVCache();
286287
const testPrompt = "The capital of Canada is";
287288
const ids = await this.tokenizer.encodeIds(testPrompt);
288289
const inputPromptSize = ids.length;

0 commit comments

Comments
 (0)