[WASM] How to compile a model to wasm

Hi there,

I am wondering what is the correct procedure to compile a keras/mxnet model to wasm executable(on cpu)?

I tried to compile it using the following command:

    target_device = "llvm -mcpu=core"
    target_host = "llvm -target=wasm32-unknown-unknown-wasm -system-lib"

    with relay.build_config(opt_level=3):
        graph, lib, params = relay.build(
            func, target="llvm", target_host=target_host, params=params)

But it throws an error at the end saying " AttributeError: Invalid config option, cannot recognize ‘target’. Candidates are: "

Any insight here?

Many thanks in advance!

try to change target to mtriple

1 Like

Yes, right now “-target” is deprecated and its semantic is merged into “-mtriple”

1 Like

Thanks! After compiling it to wasm successfully, I am trying to run the wasm binary under node. However, I got the following errors:

LinkError: WebAssembly.Instance(): Import #10 module="env" function="main" error: function import requires a callable

Suggesting a missing of main function.

My build script follows this script. I notice that it accesses a main under mod. How can I pass this main to wasm runtime?

There are some updaes that we need to support the latest emcc, https://github.com/apache/incubator-tvm/pull/6751 should help