Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align algorithms defined so far #405

Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
54d57b4
Corrected peepholeWeight shape and fixed pseudo sample code error for…
BruceDai May 8, 2023
cc34577
Remove extra parameter from 'create MLOperand' invocation (#394)
zolkis Jun 20, 2023
9b52017
Merge branch 'main' of https://github.com/webmachinelearning/webnn in…
zolkis Jun 20, 2023
a6178e9
Add the batch normalization algorithm
zolkis Jan 24, 2023
013250e
Add the concat algorithm
zolkis Mar 22, 2023
ef88d7c
Add steps for 'rank', 'validate MLOperand'. Fix the concat() steps
zolkis May 25, 2023
236bec6
concat: remove style from title
zolkis Jun 6, 2023
780d1a9
concat: remove note styling from argument description
zolkis Jun 6, 2023
98268b1
Add the clamp() algorithm
zolkis Feb 15, 2023
02e977b
Add the 'copy MLOperand' and 'create MLActivation' steps
zolkis May 25, 2023
5faf170
clamp(): improve platform related steps
zolkis Jun 2, 2023
1c89402
Add stylistic definitions for hiding algorithms, stylistic boxes
zolkis Jun 19, 2023
4a26973
Adapt the existing main version to new style, without indenting exist…
zolkis Jun 19, 2023
75925de
Indent algorithms and fix make errors
zolkis Jun 19, 2023
d5dd4f9
Merge branch 'zk-conventions-integration' of https://github.com/zolki…
zolkis Jun 20, 2023
8fac5ca
Align the algorithms for input, constant, clamp, concat, batch norm etc
zolkis Jun 20, 2023
30ba12e
Adress review comments on aligning the algorithms for input, constant…
zolkis Jun 21, 2023
963c9a0
ALign steps for creating platform objects for operands
zolkis Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 45 additions & 29 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,10 @@ The {{MLActivation}} objects (including the ones passed as input to methods) are
1. Set |activation|.{{MLActivation/[[builder]]}} to |builder|.
1. Set |activation|.{{MLActivation/[[name]]}} to |name|.
1. If |options| is an [=object=], set |activation|.{{MLActivation/[[options]]}} to |options|.
1. Make a request to the underlying platform to bind the [=implementation-defined=] platform operator for |name| to |activation|.{{MLActivation/[[operator]]}}.
1. If that fails, throw a "{{TypeError}}" and abort these steps.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operator |opImpl| defined for |name| to |activation|.{{MLActivation/[[operator]]}}, given |options|.
zolkis marked this conversation as resolved.
Show resolved Hide resolved
1. Store a reference of |opImpl| in |activation|.{{MLActivation/[[operator]]}}.
1. Return |activation|.
</div>
</details>
Expand Down Expand Up @@ -1583,8 +1585,11 @@ Create a named {{MLOperand}} based on a descriptor, that can be used as an input
1. Let |operand| be the result of invoking the <a>create MLOperand</a> steps with [=this=] and |descriptor|.
1. If that throws, re-throw the exception and stop.
1. Set |operand|.{{MLOperand/[[name]]}} to |name|.
1. Make a request to the underlying platform to register |operand| as an input and store a reference to the corresponding [=implementation-defined=] platform object in |operand|.{{MLOperand/[[operand]]}}.
1. If that fails, throw an "{{OperationError}}" {{DOMException}} and abort these steps.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform input operand |operandImpl| as an input given |operand|.
zolkis marked this conversation as resolved.
Show resolved Hide resolved
1. Register |operand| as an input.
1. Store a reference to |operandImpl| in |operand|.{{MLOperand/[[operand]]}}.
1. Return |operand|.
</div>
</details>
Expand Down Expand Up @@ -1617,8 +1622,11 @@ Create a constant {{MLOperand}} that can be used in {{MLGraphBuilder}} methods.
1. Let |operand| be the result of invoking the <a>create MLOperand</a> steps with [=this=] and |descriptor|.
1. If that throws, re-throw the exception and stop.
1. Let |bytes| be the result of invoking [[=get a copy of the bytes held by the buffer source=]] given |bufferView|.
1. Make a request to the underlying platform to register |operand| as a tensor constant with |bytes| as value and store a reference to the corresponding [=implementation-defined=] object to |operand|.{{MLOperand/[[operand]]}}.
1. If that fails, throw an "{{OperationError}}" {{DOMException}} and stop.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operand |constant| for this method, given |operand|.
zolkis marked this conversation as resolved.
Show resolved Hide resolved
1. Register |operand| as a tensor constant with |bytes| as value.
1. Store a reference of |constant| in |operand|.{{MLOperand/[[operand]]}}.
1. Return |operand|.
</div>
</details>
Expand Down Expand Up @@ -1649,10 +1657,12 @@ Create a constant {{MLOperand}} that can be used in {{MLGraphBuilder}} methods.
<div class="note">
In the case of a scalar constant, |descriptor|.{{MLOperandDescriptor/dimensions}} is ignored.
</div>
1. Let |operand| be the result of invoking the <a>create MLOperand</a> steps with [=this=] and |descriptor|.
1. If that throws, re-throw the exception and stop.
1. Make a request to the underlying platform to register |operand| as a scalar constant with |value| as value and store a reference of the [=implementation-defined=] platform object for the corresponding (scalar or tensor constant) operand to |operand|.{{MLOperand/[[operand]]}}.
1. If that throws, re-throw the error and stop.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Let |operand| be the result of invoking the <a>create MLOperand</a> steps with [=this=] and |descriptor|.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operand |constant|, given |operand|.
1. Register |operand| as a scalar constant with |value| as value.
1. Store a reference of |constant| in |operand|.{{MLOperand/[[operand]]}}.
1. Return |operand|.
</div>
</details>
Expand Down Expand Up @@ -1725,10 +1735,13 @@ partial interface MLGraphBuilder {
1. If |input| is a 4-D tensor of the *"nchw"* layout, set |options|.axis to 1.
1. If |input| is a 4-D tensor of the *"nhwc"* layout, set |options|.axis to 3.
1. Let |result| be an {{MLOperand}} representing the results. It may use the same underlying data as |input|.
1. Issue a request to the underlying platform to initialize the batch normalization, passing the arguments |input|, |mean|, |variance| and |options| and given |result| to store the results and |options|. Wait for completion.
<div class="informalsteps">
1. If |options|.activation [=map/exists=], implementations MAY use it to optimize the operation flow.
</div>
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to initialize the batch normalization:
1. Create an [=implementation-defined=] platform operator |batchNormImpl| for this method, given |input|, |mean|, |variance| and |options|.
1. Register |result| as output to |batchNormImpl|.
<div class="informalsteps">
1. If |options|.activation [=map/exists=], implementations MAY use it to optimize the operation flow.
zolkis marked this conversation as resolved.
Show resolved Hide resolved
</div>
1. Return |result|.
</div>
</details>
Expand Down Expand Up @@ -1827,12 +1840,14 @@ partial interface MLGraphBuilder {
1. Let |result| be the result of invoking the <a>copy MLOperand</a> steps given |operand|.
1. If that throws an error, re-throw the error and abort these steps.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to create an [=implementation-defined=] platform operand |operandImpl| given |result|.{{MLOperand/[[descriptor]]}}.
1. Store a reference to |operandImpl| in |result|.{{MLOperand/[[operand]]}}.
1. Make a request to the underlying platform to create an [=implementation-defined=] platform operator |operatorImpl| for clamp with |options|.{{MLClampOptions/minValue}} and |options|.{{MLClampOptions/minValue}}.
1. Register the |operand|.{{MLOperand/[[operand]]}} as an input to |operatorImpl|.
1. Register the |result|.{{MLOperand/[[operand]]}} as output to |operatorImpl|.
1. Store a reference to |operatorImpl| in |result|.{{MLOperand/[[operator]]}}.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operand |operandImpl| given |result|.{{MLOperand/[[descriptor]]}}.
1. Store a reference to |operandImpl| in |result|.{{MLOperand/[[operand]]}}.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operator |clampImpl| for this method, given |options|.{{MLClampOptions/minValue}} and |options|.{{MLClampOptions/minValue}}.
1. Register |operand|.{{MLOperand/[[operand]]}} as input to |clampImpl|.
1. Register |result|.{{MLOperand/[[operand]]}} as output to |clampImpl|.
1. Store a reference to |clampImpl| in |result|.{{MLOperand/[[operator]]}}.
1. Return |result|.
</div>
</details>
Expand All @@ -1856,9 +1871,6 @@ partial interface MLGraphBuilder {
1. If running the <a>check clamp options</a> steps with |options| returns `false`, then throw a "{{TypeError}}" {{DOMException}} and abort these steps.
1. Let |op| be the result of invoking the <a>create MLActivation</a> steps with `"clamp"` and |options|.
1. If that throws an error, re-throw the error and abort these steps.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to connect |op| with the [=implementation-defined=] platform operator for clamp |operatorImpl|.
1. Store a reference to |operatorImpl| in |op|.{{MLActivation/[[operator]]}}.
1. Return |op|.
</div>
</details>
Expand Down Expand Up @@ -1912,8 +1924,12 @@ partial interface MLGraphBuilder {
1. If |dim| is equal to |axis|, add to |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] the value of |inputs|[|index|].{{MLOperandDescriptor/dimensions}}[|dim|].
1. Let |output| be the result of invoking the <a>create MLOperand</a> steps given [=this=] and |desc|.
1. If that throws an error, re-throw the error and stop.
1. Make a request to the underlying platform to create an operator for this method with |inputs| connected as input and |output| connected as output and store a reference to the [=implementation-defined=] platform object to |output|.{{MLOperand/[[operand]]}}.
1. If that fails, throw a "{{DataError}}" {{DOMException}} and stop.
1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop.
1. Make a request to the underlying platform to:
1. Create an [=implementation-defined=] platform operator |concat| for this method, given |inputs| and |axis|.
1. Register |inputs|.{{MLOperand/[[operand]]}} as an input to |concat|.
zolkis marked this conversation as resolved.
Show resolved Hide resolved
1. Register |output|.{{MLOperand/[[operand]]}} as output to |concat|.
1. Store a reference of |concat| in |output|.{{MLOperand/[[operator]]}}.
1. Return |output|.
</div>
</details>
Expand Down Expand Up @@ -2712,7 +2728,7 @@ partial interface MLGraphBuilder {
- *options*: an optional {{MLGruOptions}}. The optional parameters of the operation.
- *bias*: an {{MLOperand}}. The 2-D input bias tensor of shape [num_directions, 4 * hidden_size]. The ordering of the bias vectors in the second dimension of the tensor shape is specified according to the *options.layout* argument.
- *recurrentBias*: an {{MLOperand}}. The 2-D recurrent bias tensor of shape [num_directions, 4 * hidden_size]. The ordering of the bias vectors in the second dimension of the tensor shape is specified according to the *options.layout* argument.
- *peepholeWeight*: an {{MLOperand}}. The 2-D weight tensor for peepholes of shape [num_directions, 4 * hidden_size]. The pack ordering of the weight vectors is for the *input (i)*, *output (o)*, and *forget (f)* gate respectively.
- *peepholeWeight*: an {{MLOperand}}. The 2-D weight tensor for peepholes of shape [num_directions, 3 * hidden_size]. The pack ordering of the weight vectors is for the *input (i)*, *output (o)*, and *forget (f)* gate respectively.
- *initialHiddenState*: an {{MLOperand}}. The 3-D initial hidden state tensor of shape [num_directions, batch_size, hidden_size]. When not specified, it's assumed to be a tensor filled with zero.
- *initialCellState*: an {{MLOperand}}. The 3-D initial hidden state tensor of shape [num_directions, batch_size, hidden_size]. When not specified, it's assumed to be a tensor filled with zero.
- *returnSequence*: a {{boolean}} indicating whether to also return the entire sequence with every output from each time step in it in addition to the output of the last time step. Default to false.
Expand Down Expand Up @@ -2755,7 +2771,7 @@ partial interface MLGraphBuilder {
currentRecurrentBias.push(options.recurrentBias ?
(builder.squeeze(builder.slice(options.recurrentBias, [dir, 0], [1, 4 * hidden_size]), { axes: [0] })) : null);
currentPeepholeWeight.push(options.peepholeWeight ?
(builder.squeeze(builder.slice(options.peepholeWeight, [dir, 0], [1, 4 * hidden_size]), { axes: [0] })) : null);
(builder.squeeze(builder.slice(options.peepholeWeight, [dir, 0], [1, 3 * hidden_size]), { axes: [0] })) : null);
}

for (let step = 0; step < steps; ++step) {
Expand All @@ -2782,8 +2798,8 @@ partial interface MLGraphBuilder {
let output = builder.reshape(results[0], [1, null, hiddenSize]);
let cell = builder.reshape(results[1], [1, null, hiddenSize]);

nextHidden = (nextHidden ? builder.concat([nextHidden, result], 0) : output);
nextCell = (nextCell ? builder.concat([nextCell, result], 0) : cell);
nextHidden = (nextHidden ? builder.concat([nextHidden, output], 0) : output);
nextCell = (nextCell ? builder.concat([nextCell, cell], 0) : cell);
}

hiddenState = nextHidden;
Expand Down