From 22e4af8968d9368be73671e17a01acaa393fda0f Mon Sep 17 00:00:00 2001
From: Andrew Brown
Date: Wed, 31 Jul 2024 15:17:36 -0700
Subject: [PATCH] Return errors as records, not resources
This change migrates the `error` type to return as a record instead of a
resource. The previous logic behind #64, IIRC, is that users that may
not wish to copy the potentially-large `data` string across the
canonical ABI would not have to--they could call the `data` method on
the resource if they really needed it.
Technical complexity during implementation is making me reconsider this
decision. While implementing this in Wasmtime, I realized that after an
error happens, the current "error as resource" scheme results in a
multi-step failure algorithm:
- construct the internal host error
- register the host error in the resource table--this may fail!
- return the host error as a resource
This complexity does not mean necessarily that the spec _must_ be
changed; I believe there is a way to "make it work." But if users end up
troubleshooting a resource failure that happens during a wasi-nn
failure, we risk making things a bit too complex for them. And, if
indeed the original argument for using resources was avoiding
performance overhead, there is a case to be made that in failure modes
performance is not the most critical for users.
I'll open this seeking feedback, not to merge immediately.
---
ml.md | 54 ++++++++++++++++---------------------------------
wit/wasi-nn.wit | 13 ++++++------
2 files changed, 23 insertions(+), 44 deletions(-)
diff --git a/ml.md b/ml.md
index bce656f..c1cd24f 100644
--- a/ml.md
+++ b/ml.md
@@ -135,38 +135,18 @@ e.g., cannot access a hardware feature requested
The operation failed for an unspecified reason.
-
resource error
-
-Functions
-[constructor]error: func
-Params
-
-Return values
-
-[method]error.code: func
-Return the error code.
-Params
-
-Return values
-
-[method]error.data: func
-Errors can propagated with backend specific status through a string value.
-Params
+record error
+Record Fields
-Return values
-
Import interface wasi:nn/inference@0.2.0-rc-2024-06-25
An inference "session" is encapsulated by a graph-execution-context. This structure binds a
@@ -197,7 +177,7 @@ e.g., cannot access a hardware feature requested
Return values
[method]graph-execution-context.compute: func
Compute the inference on the given inputs.
@@ -210,7 +190,7 @@ https://github.com/WebAssembly/wasi-nn/issues/43.
Return values
[method]graph-execution-context.get-output: func
Extract the outputs after inference.
@@ -221,7 +201,7 @@ https://github.com/WebAssembly/wasi-nn/issues/43.
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
@@ -274,7 +254,7 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).
Return values
load: func
Load a graph from an opaque sequence of bytes to use for inference.
@@ -286,7 +266,7 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).
Return values
load-by-name: func
Load a graph by name.
@@ -299,5 +279,5 @@ range from simple to complex (e.g., URLs?) and caching mechanisms of various kin
Return values
diff --git a/wit/wasi-nn.wit b/wit/wasi-nn.wit
index 872e8cd..593d6f9 100644
--- a/wit/wasi-nn.wit
+++ b/wit/wasi-nn.wit
@@ -156,13 +156,12 @@ interface errors {
unknown
}
- resource error {
- constructor(code: error-code, data: string);
+ record error {
+ /// The error code identifies the general reason the operation failed.
+ code: error-code,
- /// Return the error code.
- code: func() -> error-code;
-
- /// Errors can propagated with backend specific status through a string value.
- data: func() -> string;
+ /// The data field propagates the backend failure context as a string for easier
+ /// troubleshooting.
+ data: string,
}
}