From 03e3b002ebf86de5a8d43ce22060cdd17e50d3a2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 13 Aug 2024 15:14:52 -0700 Subject: [PATCH] Remove `set-input`, `get-output` As discussed in #43, there is no requirement to set up tensors prior to calling `compute` as well as retrieving them separately afterwards. As of #59, passing around tensors is cheap (they're resources now), so there is no data copy necessary if we adopt this PR. This change proposes removing the `set-input` and `get-output` functions, moving all of the tensor-passing to `compute`. Closes #43. --- ml.md | 42 +++++++++++------------------------------- wit/wasi-nn.wit | 18 ++++++------------ 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/ml.md b/ml.md index bce656f..6aa242d 100644 --- a/ml.md +++ b/ml.md @@ -179,49 +179,29 @@ e.g., cannot access a hardware feature requested #### `type tensor` [`tensor`](#tensor)

-#### `type tensor-data` -[`tensor-data`](#tensor_data) -

-#### `resource graph-execution-context` +#### `tuple named-tensor` +

Identify a tensor by name; this is necessary to associate tensors to +graph inputs and outputs.

+
Tuple Fields
+ +

resource graph-execution-context

Bind a graph to the input and output tensors for an inference.

TODO: this may no longer be necessary in WIT (https://github.com/WebAssembly/wasi-nn/issues/43)

Functions

-

[method]graph-execution-context.set-input: func

-

Define the inputs to use for inference.

-
Params
- -
Return values
-

[method]graph-execution-context.compute: func

Compute the inference on the given inputs.

-

Note the expected sequence of calls: set-input, compute, get-output. TODO: this -expectation could be removed as a part of -https://github.com/WebAssembly/wasi-nn/issues/43.

Params
Return values
-

[method]graph-execution-context.get-output: func

-

Extract the outputs after inference.

-
Params
- -
Return values
-

Import interface wasi:nn/graph@0.2.0-rc-2024-06-25

A graph is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML diff --git a/wit/wasi-nn.wit b/wit/wasi-nn.wit index 872e8cd..e3580dd 100644 --- a/wit/wasi-nn.wit +++ b/wit/wasi-nn.wit @@ -110,25 +110,19 @@ interface graph { /// `graph` to input tensors before `compute`-ing an inference: interface inference { use errors.{error}; - use tensor.{tensor, tensor-data}; + use tensor.{tensor}; + + /// Identify a tensor by name; this is necessary to associate tensors to + /// graph inputs and outputs. + type named-tensor = tuple; /// Bind a `graph` to the input and output tensors for an inference. /// /// TODO: this may no longer be necessary in WIT /// (https://github.com/WebAssembly/wasi-nn/issues/43) resource graph-execution-context { - /// Define the inputs to use for inference. - set-input: func(name: string, tensor: tensor) -> result<_, error>; - /// Compute the inference on the given inputs. - /// - /// Note the expected sequence of calls: `set-input`, `compute`, `get-output`. TODO: this - /// expectation could be removed as a part of - /// https://github.com/WebAssembly/wasi-nn/issues/43. - compute: func() -> result<_, error>; - - /// Extract the outputs after inference. - get-output: func(name: string) -> result; + compute: func(inputs: list) -> result, error>; } }