From 0970115398d82f01e7421057c47afdef9478543c Mon Sep 17 00:00:00 2001 From: Chai Chaoweeraprasit Date: Sun, 27 Sep 2020 20:52:29 -0700 Subject: [PATCH] Add int8/uint8 operand types. Make createModel a sync method. Rename Operands, Inputs and Outputs to NamedOperands, NamedInputs, and NamedOutputs. Update URL links of the first-wave operators doc. --- index.bs | 27 ++++----- index.html | 82 +++++++++++++-------------- op_compatibility/first_wave_models.md | 26 ++++----- 3 files changed, 66 insertions(+), 69 deletions(-) diff --git a/index.bs b/index.bs index 0af94818..55c87069 100644 --- a/index.bs +++ b/index.bs @@ -203,7 +203,9 @@ enum OperandType { "float32", "float16", "int32", - "uint32" + "uint32", + "int8", + "uint8" }; dictionary OperandDescriptor { @@ -236,7 +238,7 @@ interface NeuralNetworkContext { The {{ModelBuilder}} interface defines a set of operations as identified by the [[#usecases]] that can be composed into a computational graph. It also represents the intermediate state of a graph building session. @@ -1047,11 +1049,11 @@ dictionary Output { sequence dimensions; }; -typedef record Inputs; -typedef record Outputs; +typedef record NamedInputs; +typedef record NamedOutputs; interface Compilation { - Promise compute(Inputs inputs, optional Outputs outputs); + Promise compute(NamedInputs inputs, optional NamedOutputs outputs); }; @@ -1110,7 +1112,7 @@ const intermediateOutput2 = builder.add(constant2, input2); const output = builder.mul(intermediateOutput1, intermediateOutput2); // Create the model by identifying the outputs. -const model = await builder.createModel({name: 'output', operand: output}); +const model = builder.createModel({'output', output}); @@ -1130,16 +1132,11 @@ The following code executes the compiled model. const inputBuffer1 = new Float32Array(TENSOR_SIZE).fill(1); const inputBuffer2 = new Float32Array(TENSOR_SIZE).fill(1); -// Associate the input buffers to the input operands. -Inputs inputs; -inputs['input1'] = { buffer: inputBuffer1 }; -inputs['input2'] = { buffer: inputBuffer2 }; - // Asynchronously execute the compiled model with the specified inputs. -let result = await compilation.compute(inputs); +let outputs = await compilation.compute({'input1': {buffer: inputBuffer1}, 'input2': {buffer: inputBuffer2}}); -// The computed result in the output operand. -console.log(result.output.buffer); +// The computed result in the output operand's buffer. +console.log(outputs.output.buffer); diff --git a/index.html b/index.html index c2129ab0..44d87d62 100644 --- a/index.html +++ b/index.html @@ -2135,7 +2135,9 @@

"float32", "float16", "int32", - "uint32" + "uint32", + "int8", + "uint8" }; dictionary OperandDescriptor { @@ -2158,7 +2160,7 @@

3.6. ModelBuilder

The ModelBuilder interface defines a set of operations as identified by the § 2 Use cases that can be composed into a computational graph. It also represents the intermediate state of a graph building session.

-
typedef record<DOMString, Operand> Operands;
+
typedef record<DOMString, Operand> NamedOperands;
 
 interface ModelBuilder {
   // Create an operand that represents a model input.
@@ -2171,7 +2173,7 @@ 

Operand constant(double value, optional OperandType type = "float32"); // Create a model that encapsulates the composition of operands by identifying the output operands. - Promise<Model> createModel(Operands outputs); + Model createModel(NamedOperands outputs); };

3.6.1. batchNormalization

@@ -3019,7 +3021,7 @@

}; interface Model { - Promise<Compilation> compile(optional CompilationOptions options = {}); + Promise<Compilation> compile(optional CompilationOptions options = {}); };

3.8. Compilation

@@ -3034,11 +3036,11 @@

sequence<long> dimensions; }; -typedef record<DOMString, Input> Inputs; -typedef record<DOMString, Output> Outputs; +typedef record<DOMString, Input> NamedInputs; +typedef record<DOMString, Output> NamedOutputs; interface Compilation { - Promise<Outputs> compute(Inputs inputs, optional Outputs outputs); + Promise<NamedOutputs> compute(NamedInputs inputs, optional NamedOutputs outputs); };

4. Examples

@@ -3047,8 +3049,8 @@

4.
const nn = navigator.ml.getNeuralNetworkContext();
 
-
- The following code builds a graph as: +
+ The following code builds a graph as:
constant1 ---+
              +--- Add ---> intermediateOutput1 ---+
 input1    ---+                                    |
@@ -3090,7 +3092,7 @@ 

4. const output = builder.mul(intermediateOutput1, intermediateOutput2); // Create the model by identifying the outputs. -const model = await builder.createModel({name: 'output', operand: output}); +const model = builder.createModel({'output', output});

@@ -3100,22 +3102,17 @@

4. const compilation = await model.compile({ powerPreference: 'low-power' });

-
- The following code executes the compiled model. +
+ The following code executes the compiled model.
// Setup the input buffers with value 1.
 const inputBuffer1 = new Float32Array(TENSOR_SIZE).fill(1);
 const inputBuffer2 = new Float32Array(TENSOR_SIZE).fill(1);
 
-// Associate the input buffers to the input operands
-Inputs inputs;
-inputs['input1'] = { buffer: inputBuffer1 };
-inputs['input2'] = { buffer: inputBuffer2 };
-
 // Asynchronously execute the compiled model with the specified inputs.
-let result = await compilation.compute(inputs);
+let outputs = await compilation.compute({'input1': {buffer: inputBuffer1}, 'input2': {buffer: inputBuffer2}});
 
-// The computed result in the output operand.
-console.log(result.output.buffer);
+// The computed result in the output operand’s buffer.
+console.log(outputs.output.buffer);
 

5. Acknowledgements

@@ -3355,8 +3352,8 @@

"high-performance", in §3.7
  • Input, in §3.8
  • input(name, desc), in §3.6 -
  • Inputs, in §3.8
  • "int32", in §3.3 +
  • "int8", in §3.3
  • l2Pool2d(input), in §3.6.11
  • l2Pool2d(input, windowDimensions), in §3.6.11
  • l2Pool2d(input, windowDimensions, padding), in §3.6.11 @@ -3381,6 +3378,9 @@

    Model, in §3.7
  • ModelBuilder, in §3.6
  • mul(a, b), in §3.6.4 +
  • NamedInputs, in §3.8 +
  • NamedOperands, in §3.6 +
  • NamedOutputs, in §3.8
  • "nchw", in §3.3
  • neg(x), in §3.6.5
  • NeuralNetworkContext, in §3.5 @@ -3388,10 +3388,8 @@

    Operand, in §3.4
  • OperandDescriptor, in §3.3
  • OperandLayout, in §3.3 -
  • Operands, in §3.6
  • OperandType, in §3.3
  • Output, in §3.8 -
  • Outputs, in §3.8
  • PowerPreference, in §3.7
  • powerPreference, in §3.7
  • RecurrentNetworkActivation, in §3.6.7 @@ -3448,6 +3446,7 @@

    transpose(input, permutation), in §3.6.18
  • type, in §3.3
  • "uint32", in §3.3 +
  • "uint8", in §3.3
  • "zrn", in §3.6.7 -