Skip to content

Conversation

@CharlieFRuan
Copy link
Member

There are two changes in this PR.

Change 1: Support string[] in setPackedFunc()

Prior to this PR, we cannot pass in string[] from typescript to a TVM PackedFunc and need to convert it to TVMArray<TVMString> (for instance in getParamsFromCacheByName()). This may not be the most convenient if the PackedFunc's caller is not internal to tvmjs. Thus, this PR moves the conversion to setPackedFunc() instead.

Change 2: Support exceptionally long TVM arrays

The second change is dealing with exceptionally long TVM arrays. In cases like passing in a token table, we need to pass in a long string[] (in Llama-3's case, of size 128000), leading to JS error RangeError: Maximum call stack size exceeded since we treat each string element as an argument, shown in this.ctx.arrayMake(...inputs).

This PR sets an empirical call stack limit of 30000 and chunks the array elements in makeTVMArray(), converting each chunk to its own TVMArray. Then we concatenate them with the newly implemented runtime.ArrayConcat that concatenates N TVMArrays.

Tested end-to-end in WebLLM.

Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MasterJH5574 MasterJH5574 merged commit 57316da into apache:main Apr 21, 2024
CharlieFRuan added a commit to mlc-ai/web-llm that referenced this pull request Apr 22, 2024
### Changes
Main changes include:
- Support for JSON schema via #371

### WASM Version
All WASMs are updated to `v0_2_34` reflect the change in MLC's runtime.

### TVMjs
TVMjs compiled at
apache/tvm@57316da
- Main change: apache/tvm#16910

### Note on wasm versioning
We updated all WASMs, as reflected by `modelVersion` in `src/config.ts`
(reflected by the new folder `v0_2_34` in
[binary-mlc-llm-libs](https://github.com/mlc-ai/binary-mlc-llm-libs/tree/main/web-llm-models))
and hence the implicitly updated `webllm.prebuiltAppConfig`. See
mlc-ai/binary-mlc-llm-libs#118 on the commits of
MLC and TVM when compiling these models.

<0.2.34 users can still use WebLLM without breaking as we keep v0_2_30
models, and the links bind to the npm. Users also do not need to clear
cache since `0.2.34` models have a different
atebites-hub pushed a commit to atebites-hub/web-llm that referenced this pull request Oct 4, 2025
…#375)

### Changes
Main changes include:
- Support for JSON schema via mlc-ai#371

### WASM Version
All WASMs are updated to `v0_2_34` reflect the change in MLC's runtime.

### TVMjs
TVMjs compiled at
apache/tvm@57316da
- Main change: apache/tvm#16910

### Note on wasm versioning
We updated all WASMs, as reflected by `modelVersion` in `src/config.ts`
(reflected by the new folder `v0_2_34` in
[binary-mlc-llm-libs](https://github.com/mlc-ai/binary-mlc-llm-libs/tree/main/web-llm-models))
and hence the implicitly updated `webllm.prebuiltAppConfig`. See
mlc-ai/binary-mlc-llm-libs#118 on the commits of
MLC and TVM when compiling these models.

<0.2.34 users can still use WebLLM without breaking as we keep v0_2_30
models, and the links bind to the npm. Users also do not need to clear
cache since `0.2.34` models have a different
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants