Skip to content

Commit

Permalink
Update WIT syntax with semicolons (#57)
Browse files Browse the repository at this point in the history
* Update WIT syntax with semicolons

In preparation for when it's eventually required

* Add another semicolon

* Regenerate ml.md
  • Loading branch information
alexcrichton authored Oct 6, 2023
1 parent 747d8df commit e2310b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: WebAssembly/wit-abi-up-to-date@v13
with:
wit-abi-tag: wit-abi-0.11.0
- uses: WebAssembly/wit-abi-up-to-date@v16
30 changes: 15 additions & 15 deletions ml.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Then, the user passes <em>tensor</em> inputs to the <em>graph</em>, computes the
<p>All inputs and outputs to an ML inference are represented as <a href="#tensor"><code>tensor</code></a>s.</p>
<hr />
<h3>Types</h3>
<h4><a name="tensor_dimensions"><code>type tensor-dimensions</code></a></h4>
<p><a href="#tensor_dimensions"><a href="#tensor_dimensions"><code>tensor-dimensions</code></a></a></p>
<p>The dimensions of a tensor.
<p>The array length matches the tensor rank and each element in the array describes the size of
each dimension</p>
<h4><a name="tensor_type"><code>enum tensor-type</code></a></h4>
<p>The type of the elements in a tensor.</p>
<h5>Enum Cases</h5>
Expand All @@ -32,11 +37,6 @@ Then, the user passes <em>tensor</em> inputs to the <em>graph</em>, computes the
<li><a name="tensor_type.i32"><code>I32</code></a></li>
<li><a name="tensor_type.i64"><code>I64</code></a></li>
</ul>
<h4><a name="tensor_dimensions"><code>type tensor-dimensions</code></a></h4>
<p><a href="#tensor_dimensions"><a href="#tensor_dimensions"><code>tensor-dimensions</code></a></a></p>
<p>The dimensions of a tensor.
<p>The array length matches the tensor rank and each element in the array describes the size of
each dimension</p>
<h4><a name="tensor_data"><code>type tensor-data</code></a></h4>
<p><a href="#tensor_data"><a href="#tensor_data"><code>tensor-data</code></a></a></p>
<p>The tensor data.
Expand Down Expand Up @@ -78,7 +78,11 @@ framework (e.g., TensorFlow):</p>
#### <a name="tensor">`type tensor`</a>
[`tensor`](#tensor)
<p>
#### <a name="graph_encoding">`enum graph-encoding`</a>
#### <a name="graph">`type graph`</a>
`u32`
<p>An execution graph for performing inference (i.e., a model).
<p>TODO: replace with <code>resource</code> (https://github.com/WebAssembly/wasi-nn/issues/47).</p>
<h4><a name="graph_encoding"><code>enum graph-encoding</code></a></h4>
<p>Describes the encoding of the graph. This allows the API to be implemented by various
backends that encode (i.e., serialize) their graph IR with different formats.</p>
<h5>Enum Cases</h5>
Expand All @@ -90,15 +94,6 @@ backends that encode (i.e., serialize) their graph IR with different formats.</p
<li><a name="graph_encoding.tensorflowlite"><code>tensorflowlite</code></a></li>
<li><a name="graph_encoding.autodetect"><code>autodetect</code></a></li>
</ul>
<h4><a name="graph_builder"><code>type graph-builder</code></a></h4>
<p><a href="#graph_builder"><a href="#graph_builder"><code>graph-builder</code></a></a></p>
<p>The graph initialization data.
<p>This gets bundled up into an array of buffers because implementing backends may encode their
graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
<h4><a name="graph"><code>type graph</code></a></h4>
<p><code>u32</code></p>
<p>An execution graph for performing inference (i.e., a model).
<p>TODO: replace with <code>resource</code> (https://github.com/WebAssembly/wasi-nn/issues/47).</p>
<h4><a name="execution_target"><code>enum execution-target</code></a></h4>
<p>Define where the graph should be executed.</p>
<h5>Enum Cases</h5>
Expand All @@ -107,6 +102,11 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
<li><a name="execution_target.gpu"><code>gpu</code></a></li>
<li><a name="execution_target.tpu"><code>tpu</code></a></li>
</ul>
<h4><a name="graph_builder"><code>type graph-builder</code></a></h4>
<p><a href="#graph_builder"><a href="#graph_builder"><code>graph-builder</code></a></a></p>
<p>The graph initialization data.
<p>This gets bundled up into an array of buffers because implementing backends may encode their
graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
<hr />
<h3>Functions</h3>
<h4><a name="load"><code>load: func</code></a></h4>
Expand Down
42 changes: 21 additions & 21 deletions wit/wasi-nn.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:nn
package wasi:nn;

/// `wasi-nn` is a WASI API for performing machine learning (ML) inference. The API is not (yet)
/// capable of performing ML training. WebAssembly programs that want to use a host's ML
Expand All @@ -9,10 +9,10 @@ package wasi:nn
///
/// This example world shows how to use these primitives together.
world ml {
import tensor
import graph
import inference
import errors
import tensor;
import graph;
import inference;
import errors;
}

/// All inputs and outputs to an ML inference are represented as `tensor`s.
Expand All @@ -21,7 +21,7 @@ interface tensor {
///
/// The array length matches the tensor rank and each element in the array describes the size of
/// each dimension
type tensor-dimensions = list<u32>
type tensor-dimensions = list<u32>;

/// The type of the elements in a tensor.
enum tensor-type {
Expand All @@ -41,7 +41,7 @@ interface tensor {
/// in the type (e.g., a 2x2 tensor with 4-byte f32 elements would have a data array of length
/// 16). Naturally, this representation requires some knowledge of how to lay out data in
/// memory--e.g., using row-major ordering--and could perhaps be improved.
type tensor-data = list<u8>
type tensor-data = list<u8>;

record tensor {
// Describe the size of the tensor (e.g., 2x2x2x2 -> [2, 2, 2, 2]). To represent a tensor
Expand All @@ -59,13 +59,13 @@ interface tensor {
/// A `graph` is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML
/// framework (e.g., TensorFlow):
interface graph {
use errors.{error}
use tensor.{tensor}
use errors.{error};
use tensor.{tensor};

/// An execution graph for performing inference (i.e., a model).
///
/// TODO: replace with `resource` (https://github.com/WebAssembly/wasi-nn/issues/47).
type graph = u32
type graph = u32;

/// Describes the encoding of the graph. This allows the API to be implemented by various
/// backends that encode (i.e., serialize) their graph IR with different formats.
Expand All @@ -89,45 +89,45 @@ interface graph {
///
/// This gets bundled up into an array of buffers because implementing backends may encode their
/// graph IR in parts (e.g., OpenVINO stores its IR and weights separately).
type graph-builder = list<u8>
type graph-builder = list<u8>;

/// Load a `graph` from an opaque sequence of bytes to use for inference.
load: func(builder: list<graph-builder>, encoding: graph-encoding, target: execution-target) -> result<graph, error>
load: func(builder: list<graph-builder>, encoding: graph-encoding, target: execution-target) -> result<graph, error>;

/// Load a `graph` by name.
///
/// How the host expects the names to be passed and how it stores the graphs for retrieval via
/// this function is **implementation-specific**. This allows hosts to choose name schemes that
/// range from simple to complex (e.g., URLs?) and caching mechanisms of various kinds.
load-by-name: func(name: string) -> result<graph, error>
load-by-name: func(name: string) -> result<graph, error>;
}

/// An inference "session" is encapsulated by a `graph-execution-context`. This structure binds a
/// `graph` to input tensors before `compute`-ing an inference:
interface inference {
use errors.{error}
use tensor.{tensor, tensor-data}
use graph.{graph}
use errors.{error};
use tensor.{tensor, tensor-data};
use graph.{graph};

/// Bind a `graph` to the input and output tensors for an inference.
///
/// TODO: this is no longer necessary in WIT (https://github.com/WebAssembly/wasi-nn/issues/43)
type graph-execution-context = u32
type graph-execution-context = u32;

/// Create an execution instance of a loaded graph.
init-execution-context: func(graph: graph) -> result<graph-execution-context, error>
init-execution-context: func(graph: graph) -> result<graph-execution-context, error>;

/// Define the inputs to use for inference.
set-input: func(ctx: graph-execution-context, index: u32, tensor: tensor) -> result<_, error>
set-input: func(ctx: graph-execution-context, index: u32, 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(ctx: graph-execution-context) -> result<_, error>
compute: func(ctx: graph-execution-context) -> result<_, error>;

/// Extract the outputs after inference.
get-output: func(ctx: graph-execution-context, index: u32) -> result<tensor-data, error>
get-output: func(ctx: graph-execution-context, index: u32) -> result<tensor-data, error>;
}

/// TODO: create function-specific errors (https://github.com/WebAssembly/wasi-nn/issues/42)
Expand Down

0 comments on commit e2310b8

Please sign in to comment.