mlc-ai / web-llm

High-performance In-browser LLM Inference Engine
https://webllm.mlc.ai
Apache License 2.0
13.51k stars 870 forks source link

tvm/runtime/c_runtime_api.h' file not found #263

Closed nico-martin closed 5 months ago

nico-martin commented 9 months ago

Hi there, I am trying to build web-llm locally on my Windows machine. But it fails to build the dependencies.

+ npm --version
9.8.1
+ TVM_HOME_SET=
+ [[ -z '' ]]
+ [[ ! -d 3rdparty/tvm-unity ]]
+ export TVM_HOME=3rdparty/tvm-unity
+ TVM_HOME=3rdparty/tvm-unity
+ cd 3rdparty/tvm-unity/web
+ make
emcc -I/Path/web-llm/3rdparty/tvm-unity -I/Path/web-llm/3rdparty/tvm-unity/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/dlpack/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/dmlc-core/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/compiler-rt -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/picojson -O3 -std=c++17 -Wno-ignored-attributes -fwasm-exceptions -c -MM -MT dist/wasm/wasm_runtime.bc emcc/wasm_runtime.cc >dist/wasm/wasm_runtime.d
emcc -I/Path/web-llm/3rdparty/tvm-unity -I/Path/web-llm/3rdparty/tvm-unity/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/dlpack/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/dmlc-core/include -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/compiler-rt -I/Path/web-llm/3rdparty/tvm-unity/3rdparty/picojson -O3 -std=c++17 -Wno-ignored-attributes -fwasm-exceptions -emit-llvm -c -o dist/wasm/wasm_runtime.bc emcc/wasm_runtime.cc
emcc/wasm_runtime.cc:32:10: fatal error: 'tvm/runtime/c_runtime_api.h' file not found
   32 | #include <tvm/runtime/c_runtime_api.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:38: dist/wasm/wasm_runtime.bc] Error 1

First, does anyone have an idea how to fix this?

Second, is there a reason that we have to build those dependencies on each machine that wants to build web-llm? Wouldn't it be possible to ship the prebuilt 3rdparty Scripts within the git repo?

CharlieFRuan commented 9 months ago

Hi @tlopex, I have the impression that you are on a Windows machine; have you run into this issue before?

nico-martin commented 9 months ago

I digged deeper and tried to build 3rdparty/tvm-unity/web manually, which fails: image But the IDE can resolve it. So I renamed tvmjs_runtime_wasi.d.ts to tvmjs_runtime_wasi.ts. Which allowed me to build the lib. But running the .\scripts\prep_deps.sh would still produce the same error.

So I published 3rdparty/tvm-unity/web on npm (https://www.npmjs.com/package/@nico-martin/tvmjs ) to install it the "normal way". This way I was able to install @nico-martin/tvmjs and I was finally able to build web-llm.

Wouldn't it make sense to publish 3rdparty/tvm-unity/web on npm so everyone could use this version instead of building it themselfs?

nico-martin commented 9 months ago

@CharlieFRuan is there a reason you did not implemented it in a way like this? https://github.com/nico-martin/web-llm/tree/build-problem-windows

tlopex commented 9 months ago

@CharlieFRuan Sorry for late reply. I haven't encountered this problem before. @nico-martin Have you tried to rebuild it again? Sometimes installing again can solve the issue.

nico-martin commented 9 months ago

Yes, I tried it multiple times, deleted everything, but no luck..

CharlieFRuan commented 9 months ago

@tlopex Thanks for sharing!

@nico-martin I guess the main reason prep_deps.sh fails is the make under tvm-unity/web fails, and I am still confused about why that fails on your device; failing make is probably why you needed to rename tvmjs_runtime_wasi.d.ts.

Glad you figured it out your own. And this is a good idea, we'll make tvmjs an npm package soon. Thanks for the suggestion!