Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Support string[] in setPackedFunc() and exceptionally long arrays #16910

Merged
merged 2 commits into from
Apr 21, 2024

Conversation

CharlieFRuan
Copy link
Contributor

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.

src/runtime/container.cc Outdated Show resolved Hide resolved
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
15 checks passed
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
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