leonwanghui commented on Issue #2208:
Hi @abrown, I think it's a great idea to add neural network module in WASI and Wasmtime, and I'm also interested in expanding other inference frameworks into wasi-nn backend plugin. Could u give some guidelines to develop a new backend plugin? Thanks!
abrown commented on Issue #2208:
Could u give some guidelines to develop a new backend plugin? Thanks!
I think the process currently looks like this (at a very high level):
- create a specification (e.g. [wasi-nn]) and present it to the the WASI subgroup (see their [meetings]); you might even want to discuss the idea in the subgroup before creating the specification in case others have had similar ideas
- use the specification to generate a Rust trait using
wiggle
as in [witx.rs], implement the generated trait as in [impl.rs], and then create a way to link in the module [lib.rs]. You will need a way to contain the module state as well: [ctx.rs].- The next part is still TBD since wasi-nn is the first attempt to add a WASI module that is not wasi-common: you probably need a way to conditionally compile the module if it is something like wasi-nn that users will want to opt in to and, once this is figured out, the Wasmtime linker should be modified in several places to include the new functionality (see an example [here]).
[wasi-nn]: https://github.com/WebAssembly/wasi-nn/blob/master/phases/ephemeral/witx/wasi_ephemeral_nn.witx
[meetings]: https://github.com/WebAssembly/WASI/tree/master/meetings
[witx.rs]: https://github.com/bytecodealliance/wasmtime/pull/2208/files#diff-7abb5603a8f446a51587db17dac65700R6-R10
[impl.rs]: https://github.com/bytecodealliance/wasmtime/pull/2208/files#diff-fd07edcd1266d1aaf710f2a69417536dR1
[lib.rs]: https://github.com/bytecodealliance/wasmtime/pull/2208/files#diff-47c18b15fc3a3e243ac2c78b6015c1adR9
[ctx.rs]: https://github.com/bytecodealliance/wasmtime/pull/2208/files#diff-c6a6bf4e536c9922b150db4d6591dc23R108
[here]: https://github.com/bytecodealliance/wasmtime/pull/2208/files#diff-8b7c97769c6a414d67e8b9a22992a91bR28-R29Hopefully that covers the basics but as you might guess there are details that could bear more documentation.
abrown commented on Issue #2208:
Tagging a few people as reviewers to solicit some early feedback on this approach to adding optional WASI modules to Wasmtime.
alexcrichton commented on Issue #2208:
That way, wasi-nn would be in control of when it sees Wasmtime API changes. That would also avoid the 95 MB file in the Wasmtime repo. Thoughts?
Belatedly, but this sounds good to me!
github-actions[bot] commented on Issue #2208:
Subscribe to Label Action
cc @kubkon
<details>
This issue or pull request has been labeled: "cranelift", "wasi"Thus the following users have been cc'd because of the following labels:
- kubkon: wasi
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
abrown commented on Issue #2208:
@pchickey, @sunfishcode, @alexcrichton: I think this is ready for an official review (pending any crazy CI failures... I think I've seen the majority of them already). What you will see with the current state of this PR is two commits:
- one to add the wasi-nn module hidden behind a Cargo feature; when enabled, the
Linker
will be informed of the new function names--this is the approach we discussed in the last Wasmtime meeting- another to add a script,
ci/run-wasi-nn-example.sh
, that will build and run an example using wasi-nn without any of the large test fixtures (these have been moved to a Gist and are retrieved by the script)
alexcrichton commented on Issue #2208:
Seems reasonable to me, but are you thinking we should land all the support in this repository? I may have misunderstood but it sounded like we were shooting instead for landing this as a separate repository with integration hooks provided here.
alexcrichton commented on Issue #2208:
@sunfishcode and @abrown what do y'all think of making a wasmtime-nn (or similar) repository in the bytecodealliance org to house this integration?
Last updated: Dec 23 2024 at 12:05 UTC