Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
.DS_Store
.vscode
.claude
.npmrc
/cache
/build
/build-compat
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.npmrc
/docs
/wasm
/examples
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project("wllama")

option(WLLAMA_TEST_BACKEND "Build wllama with test-backend-ops included" OFF)

set(MTMD_VIDEO OFF CACHE BOOL "" FORCE)

set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
Expand All @@ -23,6 +25,7 @@ set(WLLAMA_LINK_OPTIONS
-sMODULARIZE=0
-sINITIAL_MEMORY=128MB
-sMAXIMUM_MEMORY=4096MB
-sSTACK_SIZE=5MB
-sALLOW_MEMORY_GROWTH=1
-sFORCE_FILESYSTEM=1
-sEXPORTED_FUNCTIONS=_main,_wllama_malloc,_wllama_start,_wllama_action,_wllama_exit,_wllama_debug
Expand Down
15 changes: 15 additions & 0 deletions compat/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.npmrc
/docs
/wasm
/examples
/llama.cpp
/models
/build
/build-*
/cache
/compat
/.github
/.vscode
/.claude
a.out.js
a.out.wasm
5 changes: 2 additions & 3 deletions compat/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "@wllama/wllama-compat",
"version": "3.4.1",
"version": "3.5.0",
"description": "Optional package providing compatibility with older browsers for @wllama/wllama",
"main": "index.js",
"type": "module",
"scripts": {
"upload": "npm publish --access public",
"prepublishOnly": "node ../scripts/check_package_size.js"
"upload": "npm publish --access public"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion compat/wasm/wllama.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions cpp/wllama-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,20 @@ std::pair<long, std::vector<char>> common_remote_get_content(const std::string &
throw std::runtime_error("common_remote_get_content is not implemented in wllama");
}

#if 1
common_device_memory_data_vec common_get_device_memory_data(
const char *path_model,
const llama_model_params *mparams,
const llama_context_params *cparams,
std::vector<ggml_backend_dev_t> &devs,
uint32_t &hp_ngl,
uint32_t &hp_n_ctx_train,
uint32_t &hp_n_expert,
ggml_log_level log_level)
{
throw std::runtime_error("common_get_device_memory_data is not implemented in wllama");
}
#else
std::vector<llama_device_memory_data> common_get_device_memory_data(
const char *path_model,
const struct llama_model_params *mparams,
Expand All @@ -1155,3 +1169,4 @@ std::vector<llama_device_memory_data> common_get_device_memory_data(
{
throw std::runtime_error("common_get_device_memory_data is not implemented in wllama");
}
#endif
2 changes: 1 addition & 1 deletion llama.cpp
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wllama/wllama",
"version": "3.4.1",
"version": "3.5.0",
"description": "WebAssembly binding for llama.cpp - Enabling on-browser LLM inference",
"main": "index.js",
"type": "module",
Expand All @@ -18,16 +18,15 @@
"build:tsup": "tsup src/index.ts --format cjs,esm --clean",
"build:minified": "terser esm/index.js -o esm/index.min.js --compress --mangle --source-map",
"build:typedef": "tsc --emitDeclarationOnly --declaration -p tsconfig.build.json",
"build": "npm run clean && npm run build:worker && npm run build:tsup && npm run build:minified && npm run build:typedef",
"postbuild": "./scripts/post_build.sh && npm run docs",
"build": "npm run clean && npm run build:worker && npm run build:tsup && npm run build:minified && npm run build:typedef && ./scripts/post_build.sh && npm run docs",
"docs": "typedoc --tsconfig tsconfig.build.json src/index.ts",
"upload": "npm run format && npm run build && npm publish --access public && (cd compat && npm publish --access public)",
"upload": "npm run format && npm run build && node scripts/check_package_size.js && npm publish --access public && (cd compat && npm publish --access public)",
"format": "prettier --write .",
"test": "vitest",
"test:auto": "AUTO=1 vitest",
"test:firefox": "BROWSER=firefox vitest",
"test:safari": "BROWSER=safari vitest",
"test:wgpu": "WEBGPU=1 vitest",
"prepublishOnly": "node scripts/check_package_size.js"
"test:wgpu": "WEBGPU=1 vitest"
},
"repository": {
"type": "git",
Expand Down
33 changes: 33 additions & 0 deletions scripts/bisect_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Git bisect script for finding the llama.cpp commit that introduced the locale crash.
# Run from wllama root: git bisect run ./scripts/bisect_test.sh
#
# Start (good): aa46bda89b9a8378ae76bb15fc2ce2f571f0983c (wllama master's llama.cpp)
# End (bad): dd4623a74 (current HEAD of submodule)

set -e

WLLAMA_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
cd "$WLLAMA_ROOT"

CONTEXT_H="$WLLAMA_ROOT/cpp/wllama-context.h"
FIT_H="$WLLAMA_ROOT/llama.cpp/common/fit.h"

# Adjust #if 0 / #if 1 around common_get_device_memory_data stub based on
# which signature fit.h declares at the current bisect commit.
if grep -q "common_device_memory_data_vec" "$FIT_H" 2>/dev/null; then
# New signature (after d8a24ccee): enable the common_device_memory_data_vec block
sed -i.bak 's/^#if [01]$/\#if 1/' "$CONTEXT_H"
else
# Old signature (before d8a24ccee): enable the std::vector<llama_device_memory_data> block
sed -i.bak 's/^#if [01]$/\#if 0/' "$CONTEXT_H"
Comment thread
ngxson marked this conversation as resolved.
fi
rm -f "${CONTEXT_H}.bak"

# Build and run tests. Exit 125 = skip (build infra broken at this commit).
rm -rf build

SKIP_COMPAT=1 npm run build:wasm 2>&1 || exit 125
npm run build 2>&1 || exit 125
AUTO=1 npm run test 2>&1
29 changes: 17 additions & 12 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
user: "${D_UID}:${D_GID}"
environment:
- WLLAMA_TEST_BACKEND=${WLLAMA_TEST_BACKEND:-}
- SKIP_COMPAT=${SKIP_COMPAT:-}
volumes:
- ..:/source:Z
entrypoint: /bin/bash
Expand Down Expand Up @@ -49,23 +50,27 @@ services:
cp build/wllama.js src/wasm
cp build/wllama.wasm src/wasm

# build compat package
mkdir -p build-compat
cd build-compat
emcmake cmake .. -DWLLAMA_COMPAT=ON -DLLAMA_WASM_MEM64=OFF -DGGML_WEBGPU=ON -DGGML_WEBGPU_JSPI=OFF -DEMDAWNWEBGPU_DIR="$${EMDAWNWEBGPU_DIR}" $${CMAKE_EXTRA_FLAGS}
emmake make wllama -j
# build compat package (skip if SKIP_COMPAT=1)
if [ -z "${SKIP_COMPAT}" ]; then
mkdir -p build-compat
cd build-compat
emcmake cmake .. -DWLLAMA_COMPAT=ON -DLLAMA_WASM_MEM64=OFF -DGGML_WEBGPU=ON -DGGML_WEBGPU_JSPI=OFF -DEMDAWNWEBGPU_DIR="$${EMDAWNWEBGPU_DIR}" $${CMAKE_EXTRA_FLAGS}
emmake make wllama -j

# go back to root
cd ..
# go back to root
cd ..

# copy output files (compat build)
mkdir -p compat/wasm
cp build-compat/wllama.js compat/wasm
cp build-compat/wllama.wasm compat/wasm
# copy output files (compat build)
mkdir -p compat/wasm
cp build-compat/wllama.js compat/wasm
cp build-compat/wllama.wasm compat/wasm
fi
Comment thread
ngxson marked this conversation as resolved.

# generate source map
node scripts/build_source_map.js

# list files (optional, for verification)
ls -lh build
ls -lh build-compat
if [ -d build-compat ]; then
ls -lh build-compat
fi
6 changes: 3 additions & 3 deletions src/wasm-from-cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Do not edit this file directly

const WasmFromCDN = {
default: 'https://cdn.jsdelivr.net/npm/@wllama/wllama@3.4.1/src/wasm/wllama.wasm',
default: 'https://cdn.jsdelivr.net/npm/@wllama/wllama@3.5.0/src/wasm/wllama.wasm',
};

export const WasmCompatFromCDN = {
worker: 'https://cdn.jsdelivr.net/npm/@wllama/wllama-compat@3.4.1/wasm/wllama.js',
wasm: 'https://cdn.jsdelivr.net/npm/@wllama/wllama-compat@3.4.1/wasm/wllama.wasm',
worker: 'https://cdn.jsdelivr.net/npm/@wllama/wllama-compat@3.5.0/wasm/wllama.js',
wasm: 'https://cdn.jsdelivr.net/npm/@wllama/wllama-compat@3.5.0/wasm/wllama.wasm',
};

export default WasmFromCDN;
4 changes: 2 additions & 2 deletions src/wasm/source-map.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/wasm/wllama.js

Large diffs are not rendered by default.

Binary file modified src/wasm/wllama.wasm
Binary file not shown.
Loading
Loading