Skip to content

Commit 03e3b00

Browse files
committed
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.
1 parent 917bf47 commit 03e3b00

File tree

2 files changed

+17
-43
lines changed

2 files changed

+17
-43
lines changed

ml.md

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,49 +179,29 @@ e.g., cannot access a hardware feature requested
179179
#### <a name="tensor"></a>`type tensor`
180180
[`tensor`](#tensor)
181181
<p>
182-
#### <a name="tensor_data"></a>`type tensor-data`
183-
[`tensor-data`](#tensor_data)
184-
<p>
185-
#### <a name="graph_execution_context"></a>`resource graph-execution-context`
182+
#### <a name="named_tensor"></a>`tuple named-tensor`
183+
<p>Identify a tensor by name; this is necessary to associate tensors to
184+
graph inputs and outputs.</p>
185+
<h5>Tuple Fields</h5>
186+
<ul>
187+
<li><a name="named_tensor.0"></a><code>0</code>: <code>string</code></li>
188+
<li><a name="named_tensor.1"></a><code>1</code>: own&lt;<a href="#tensor"><a href="#tensor"><code>tensor</code></a></a>&gt;</li>
189+
</ul>
190+
<h4><a name="graph_execution_context"></a><code>resource graph-execution-context</code></h4>
186191
<p>Bind a <a href="#graph"><code>graph</code></a> to the input and output tensors for an inference.</p>
187192
<h2>TODO: this may no longer be necessary in WIT
188193
(https://github.com/WebAssembly/wasi-nn/issues/43)</h2>
189194
<h3>Functions</h3>
190-
<h4><a name="method_graph_execution_context_set_input"></a><code>[method]graph-execution-context.set-input: func</code></h4>
191-
<p>Define the inputs to use for inference.</p>
192-
<h5>Params</h5>
193-
<ul>
194-
<li><a name="method_graph_execution_context_set_input.self"></a><code>self</code>: borrow&lt;<a href="#graph_execution_context"><a href="#graph_execution_context"><code>graph-execution-context</code></a></a>&gt;</li>
195-
<li><a name="method_graph_execution_context_set_input.name"></a><code>name</code>: <code>string</code></li>
196-
<li><a name="method_graph_execution_context_set_input.tensor"></a><a href="#tensor"><code>tensor</code></a>: own&lt;<a href="#tensor"><a href="#tensor"><code>tensor</code></a></a>&gt;</li>
197-
</ul>
198-
<h5>Return values</h5>
199-
<ul>
200-
<li><a name="method_graph_execution_context_set_input.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
201-
</ul>
202195
<h4><a name="method_graph_execution_context_compute"></a><code>[method]graph-execution-context.compute: func</code></h4>
203196
<p>Compute the inference on the given inputs.</p>
204-
<p>Note the expected sequence of calls: <code>set-input</code>, <code>compute</code>, <code>get-output</code>. TODO: this
205-
expectation could be removed as a part of
206-
https://github.com/WebAssembly/wasi-nn/issues/43.</p>
207197
<h5>Params</h5>
208198
<ul>
209199
<li><a name="method_graph_execution_context_compute.self"></a><code>self</code>: borrow&lt;<a href="#graph_execution_context"><a href="#graph_execution_context"><code>graph-execution-context</code></a></a>&gt;</li>
200+
<li><a name="method_graph_execution_context_compute.inputs"></a><code>inputs</code>: list&lt;<a href="#named_tensor"><a href="#named_tensor"><code>named-tensor</code></a></a>&gt;</li>
210201
</ul>
211202
<h5>Return values</h5>
212203
<ul>
213-
<li><a name="method_graph_execution_context_compute.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
214-
</ul>
215-
<h4><a name="method_graph_execution_context_get_output"></a><code>[method]graph-execution-context.get-output: func</code></h4>
216-
<p>Extract the outputs after inference.</p>
217-
<h5>Params</h5>
218-
<ul>
219-
<li><a name="method_graph_execution_context_get_output.self"></a><code>self</code>: borrow&lt;<a href="#graph_execution_context"><a href="#graph_execution_context"><code>graph-execution-context</code></a></a>&gt;</li>
220-
<li><a name="method_graph_execution_context_get_output.name"></a><code>name</code>: <code>string</code></li>
221-
</ul>
222-
<h5>Return values</h5>
223-
<ul>
224-
<li><a name="method_graph_execution_context_get_output.0"></a> result&lt;own&lt;<a href="#tensor"><a href="#tensor"><code>tensor</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
204+
<li><a name="method_graph_execution_context_compute.0"></a> result&lt;list&lt;<a href="#named_tensor"><a href="#named_tensor"><code>named-tensor</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
225205
</ul>
226206
<h2><a name="wasi_nn_graph_0_2_0_rc_2024_06_25"></a>Import interface wasi:nn/graph@0.2.0-rc-2024-06-25</h2>
227207
<p>A <a href="#graph"><code>graph</code></a> is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML

wit/wasi-nn.wit

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,19 @@ interface graph {
110110
/// `graph` to input tensors before `compute`-ing an inference:
111111
interface inference {
112112
use errors.{error};
113-
use tensor.{tensor, tensor-data};
113+
use tensor.{tensor};
114+
115+
/// Identify a tensor by name; this is necessary to associate tensors to
116+
/// graph inputs and outputs.
117+
type named-tensor = tuple<string, tensor>;
114118

115119
/// Bind a `graph` to the input and output tensors for an inference.
116120
///
117121
/// TODO: this may no longer be necessary in WIT
118122
/// (https://github.com/WebAssembly/wasi-nn/issues/43)
119123
resource graph-execution-context {
120-
/// Define the inputs to use for inference.
121-
set-input: func(name: string, tensor: tensor) -> result<_, error>;
122-
123124
/// Compute the inference on the given inputs.
124-
///
125-
/// Note the expected sequence of calls: `set-input`, `compute`, `get-output`. TODO: this
126-
/// expectation could be removed as a part of
127-
/// https://github.com/WebAssembly/wasi-nn/issues/43.
128-
compute: func() -> result<_, error>;
129-
130-
/// Extract the outputs after inference.
131-
get-output: func(name: string) -> result<tensor, error>;
125+
compute: func(inputs: list<named-tensor>) -> result<list<named-tensor>, error>;
132126
}
133127
}
134128

0 commit comments

Comments
 (0)