wasi-nn: refactor to allow preview2 access#6821
wasi-nn: refactor to allow preview2 access#6821abrown merged 10 commits intobytecodealliance:mainfrom
preview2 access#6821Conversation
de9a31b to
00dfc5e
Compare
This change refactors the `wasmtime-wasi-nn` crate to allow access from both `preview1` and `preview2` ABIs. Though the `wasi-nn` specification has included a WIT description for some time, here we use some in-tree files until WebAssembly/wasi-nn#38 is landed. The `preview2` code is not exercised anywhere yet: ideally this would be wired up once component model `resource`s are fully implemented in Wasmtime. prtest:full
prtest:full
This is based on @pchickey's [comments] on ABI naming. [comments]: https://bytecodealliance.zulipchat.com/#narrow/stream/266558-wasi-nn/topic/wasi-nn.20.2B.20preview2/near/383368292
|
One part of this is that it defines a hierarchy of types and then provides conversion of WIT and WITX-generated types into this hierarchy of types. That's reasonable for this crate since the set of types is quite small, but for something like Also one thing to consider is that this has Also as a final thing, it looks like the implementation bodies of WIT and WITX are duplicated? Would it be possible for one to delegate to the other? |
Yeah, I would prefer that. Is it fine if
I saw this over in
They are duplicated in essence but not all the details are the same; e.g., anywhere we need a slice in |
|
@alexcrichton: one more thought about your comments is that perhaps some of these improvements could be done as a separate PR. There is clearly more work that needs to be done here (e.g., replace all these temporary WIT files with their upstream versions, implement named models, etc.) so perhaps some of the refactorings you suggest could fit into some of those PRs. |
pchickey
left a comment
There was a problem hiding this comment.
Adding the representation that is a duplicate of the wasmtime-wit-bindgen generated types creates a lot of noise in this implementation. Wasmtime is going to have the component-model feature enabled in its use in the cli as soon as #6836 lands (should be very soon, just some minor conflicts), at which point you can make wasi-nn available to components as well.
I'd rather see this PR land with just the wit-bindgen generated types instead of the duplicates, rather than iterate on that later.
This removes the crate-specific types in order to use the WIT-generated types throughout the crate. The main effect of this is that the crate no longer optionally includes `wasmtime` with the `component-model` feature--now that is required.
pchickey
left a comment
There was a problem hiding this comment.
This looks a lot better, thanks!
| .as_slice()? | ||
| .expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)"); | ||
| let xml = &builders[0]; | ||
| let weights = &builders[1]; |
There was a problem hiding this comment.
if the goal of this list of lists is just to pass in a list<u8> for xml and a list<u8> for weights, then can we just make it two arguments that are each list<u8>?
There was a problem hiding this comment.
well, other backends will have different numbers of list<u8> to be passed in so the spec has to account for that; the Backend trait mirrors that so that other backends can be implemented.
There was a problem hiding this comment.
I think eventually we should use named parameters here as well, but @abrown is correct that different frameworks take a different number of options and some even take an execution plan for a model.
* wasi-nn: refactor to allow `preview2` access This change refactors the `wasmtime-wasi-nn` crate to allow access from both `preview1` and `preview2` ABIs. Though the `wasi-nn` specification has included a WIT description for some time, here we use some in-tree files until WebAssembly/wasi-nn#38 is landed. The `preview2` code is not exercised anywhere yet: ideally this would be wired up once component model `resource`s are fully implemented in Wasmtime. prtest:full * wasi-nn: use `preview1` linkage prtest:full * review: rename `preview*` to `wit*` This is based on @pchickey's [comments] on ABI naming. [comments]: https://bytecodealliance.zulipchat.com/#narrow/stream/266558-wasi-nn/topic/wasi-nn.20.2B.20preview2/near/383368292 * review: update README * fix: remove broken doc links * fix: replace typo `wit` with `gen` * review: use `wit` types everywhere This removes the crate-specific types in order to use the WIT-generated types throughout the crate. The main effect of this is that the crate no longer optionally includes `wasmtime` with the `component-model` feature--now that is required. * review: move `BackendKind` conversion into `witx.rs` * review: remove `<'a>` * review: use `tracing` crate instead of `eprintln!`
This change refactors the
wasmtime-wasi-nncrate to allow access from bothpreview1andpreview2ABIs. Though thewasi-nnspecification has included a WIT description for some time, here we use some in-tree files until WebAssembly/wasi-nn#38 is landed. Thepreview2code is not exercised anywhere yet: ideally this would be wired up once component modelresources are fully implemented in Wasmtime.