From 3710c781ee7df147eb0df602f8e0c98afeda8a42 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 8 Nov 2024 17:25:41 -0800 Subject: [PATCH] Editorial: Eschew vars outside of algorithms Part of https://github.com/webmachinelearning/webnn/issues/783 --- docs/SpecCodingConventions.md | 1 + index.bs | 30 +++++++++++++++--------------- tools/lint.mjs | 7 +++++++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/SpecCodingConventions.md b/docs/SpecCodingConventions.md index 40ca45dc..c26ec9e2 100644 --- a/docs/SpecCodingConventions.md +++ b/docs/SpecCodingConventions.md @@ -95,6 +95,7 @@ Example: * When concisely defining a tensor's layout, use the syntax `*[ ... ]*` (e.g. _"nchw" means the input tensor has the layout *[batches, inputChannels, height, width]*_) * Format explanatory expressions using backticks, e.g. `` `max(0, x) + alpha * (exp(min(0, x)) - 1)` `` * In Web IDL `
` blocks, wrap long lines to avoid horizontal scrollbars. 88 characters seems to be the magic number.
+* Avoid `v` or `|v|` outside of algorithms; Bikeshed interprets these as global variables which can mask errors. Just use `*v*`.
 
 
 ### Algorithms
diff --git a/index.bs b/index.bs
index bebb1f0d..241815ef 100644
--- a/index.bs
+++ b/index.bs
@@ -1767,7 +1767,7 @@ partial dictionary MLOpSupportLimits {
         - axis: The dimension to reduce. The value must be in the range [0, N-1] where N is the [=MLOperand/rank=] of the input tensor.
         - options: an optional {{MLArgMinMaxOptions}}. The optional parameters of the operation.
 
-    **Returns:** an {{MLOperand}}. The N-D tensor of the reduced shape. The values must be of type |options|.{{MLArgMinMaxOptions/outputDataType}} in the range [0, N-1] where N is the size of the input dimension specified by axis.
+    **Returns:** an {{MLOperand}}. The N-D tensor of the reduced shape. The values must be of type *options*.{{MLArgMinMaxOptions/outputDataType}} in the range [0, N-1] where N is the size of the input dimension specified by axis.
 
 
 
@@ -4075,13 +4075,13 @@ partial dictionary MLOpSupportLimits {
 
**Arguments:** - input: an {{MLOperand}}. The input 3-D tensor of shape *[steps, batchSize, inputSize]*. - - weight: an {{MLOperand}}. The 3-D input weight tensor of shape *[numDirections, 3 * hiddenSize, inputSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to |options|.{{MLGruOptions/layout}}. - - recurrentWeight: an {{MLOperand}}. The 3-D recurrent weight tensor of shape *[numDirections, 3 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to |options|.{{MLGruOptions/layout}}. + - weight: an {{MLOperand}}. The 3-D input weight tensor of shape *[numDirections, 3 * hiddenSize, inputSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to *options*.{{MLGruOptions/layout}}. + - recurrentWeight: an {{MLOperand}}. The 3-D recurrent weight tensor of shape *[numDirections, 3 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to *options*.{{MLGruOptions/layout}}. - steps: an {{unsigned long}} scalar. The number of time steps in the recurrent network. The value must be greater than 0. - hiddenSize: an {{unsigned long}} scalar. The value of the third dimension of the cell output tensor shape. It indicates the number of features in the hidden state. - options: an optional {{MLGruOptions}}. The optional parameters of the operation. - **Returns:** [=sequence=]<{{MLOperand}}>. The first element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the cell output from the last time step of the network. Additionally, if |options|.{{MLGruOptions/returnSequence}} is set to true, the second element is the 4-D output tensor of shape *[steps, numDirections, batchSize, hiddenSize]* containing every cell outputs from each time step in the temporal sequence. + **Returns:** [=sequence=]<{{MLOperand}}>. The first element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the cell output from the last time step of the network. Additionally, if *options*.{{MLGruOptions/returnSequence}} is set to true, the second element is the 4-D output tensor of shape *[steps, numDirections, batchSize, hiddenSize]* containing every cell outputs from each time step in the temporal sequence.
@@ -4379,8 +4379,8 @@ partial dictionary MLOpSupportLimits {
**Arguments:** - input: an {{MLOperand}}. The input 2-D tensor of shape *[batchSize, inputSize]*. - - weight: an {{MLOperand}}. The 2-D input weight tensor of shape *[3 * hiddenSize, inputSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options.layout*. - - recurrentWeight: an {{MLOperand}}. The 2-D recurrent weight tensor of shape *[3 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options.layout*. + - weight: an {{MLOperand}}. The 2-D input weight tensor of shape *[3 * hiddenSize, inputSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options*.{{MLGruCellOptions/layout}}. + - recurrentWeight: an {{MLOperand}}. The 2-D recurrent weight tensor of shape *[3 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options*.{{MLGruCellOptions/layout}}. - hiddenState: an {{MLOperand}}. The 2-D input hidden state tensor of shape *[batchSize, hiddenSize]*. - hiddenSize: an {{unsigned long}} scalar. The value of the second dimension of the output tensor shape. It indicates the number of features in the hidden state. - options: an optional {{MLGruCellOptions}}. The optional parameters of the operation. @@ -4816,11 +4816,11 @@ partial dictionary MLOpSupportLimits {
: scale :: - The 1-D tensor of the scaling values whose [=list/size=] is equal to the number of channels, i.e. the size of the feature dimension of the input. For example, for an |input| tensor with {{MLInputOperandLayout/"nchw"}} layout, the [=list/size=] is equal to |input|'s [=MLOperand/shape=][1]. + The 1-D tensor of the scaling values whose [=list/size=] is equal to the number of channels, i.e. the size of the feature dimension of the input. For example, for an *input* tensor with {{MLInputOperandLayout/"nchw"}} layout, the [=list/size=] is equal to *input*'s [=MLOperand/shape=][1]. : bias :: - The 1-D tensor of the bias values whose [=list/size=] is equal to the size of the feature dimension of the input. For example, for an |input| tensor with {{MLInputOperandLayout/"nchw"}} layout, the [=list/size=] is equal to |input|'s [=MLOperand/shape=][1]. + The 1-D tensor of the bias values whose [=list/size=] is equal to the size of the feature dimension of the input. For example, for an *input* tensor with {{MLInputOperandLayout/"nchw"}} layout, the [=list/size=] is equal to *input*'s [=MLOperand/shape=][1]. : epsilon :: @@ -4971,11 +4971,11 @@ partial dictionary MLOpSupportLimits {
: scale :: - The N-D tensor of the scaling values whose shape is determined by the |axes| member in that each value in |axes| indicates the dimension of the input tensor with scaling values. For example, for an |axes| values of [1,2,3], the shape of this tensor is the list of the corresponding sizes of the input dimension 1, 2 and 3. When this member is not present, the scaling value is assumed to be 1. + The N-D tensor of the scaling values whose shape is determined by the {{MLLayerNormalizationOptions/axes}} member in that each value in {{MLLayerNormalizationOptions/axes}} indicates the dimension of the input tensor with scaling values. For example, for an {{MLLayerNormalizationOptions/axes}} values of [1,2,3], the shape of this tensor is the list of the corresponding sizes of the input dimension 1, 2 and 3. When this member is not present, the scaling value is assumed to be 1. : bias :: - The N-D tensor of the bias values whose shape is determined by the |axes| member in that each value in |axes| indicates the dimension of the input tensor with bias values. For example, for an |axes| values of [1,2,3], the shape of this tensor is the list of the corresponding sizes of the input dimension 1, 2 and 3. When this member is not present, the bias value is assumed to be 0. + The N-D tensor of the bias values whose shape is determined by the {{MLLayerNormalizationOptions/axes}} member in that each value in {{MLLayerNormalizationOptions/axes}} indicates the dimension of the input tensor with bias values. For example, for an {{MLLayerNormalizationOptions/axes}} values of [1,2,3], the shape of this tensor is the list of the corresponding sizes of the input dimension 1, 2 and 3. When this member is not present, the bias value is assumed to be 0. : axes :: @@ -5376,13 +5376,13 @@ partial dictionary MLOpSupportLimits {
**Arguments:** - input: an {{MLOperand}}. The input 3-D tensor of shape *[steps, batchSize, inputSize]*. - - weight: an {{MLOperand}}. The 3-D input weight tensor of shape *[numDirections, 4 * hiddenSize, inputSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to the |options|.{{MLLstmOptions/layout}}. - - recurrentWeight: an {{MLOperand}}. The 3-D recurrent weight tensor of shape *[numDirections, 4 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to |options|.{{MLLstmOptions/layout}}. + - weight: an {{MLOperand}}. The 3-D input weight tensor of shape *[numDirections, 4 * hiddenSize, inputSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to *options*.{{MLLstmOptions/layout}}. + - recurrentWeight: an {{MLOperand}}. The 3-D recurrent weight tensor of shape *[numDirections, 4 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the second dimension of the tensor shape is specified according to *options*.{{MLLstmOptions/layout}}. - steps: an {{unsigned long}} scalar. The number of time steps in the recurrent network. The value must be greater than 0. - hiddenSize: an {{unsigned long}} scalar. The value of the third dimension of the cell output tensor shape. It indicates the number of features in the hidden state. - options: an optional {{MLLstmOptions}}. The optional parameters of the operation. - **Returns:** [=sequence=]<{{MLOperand}}>. The first element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the output hidden state from the last time step of the network. The second element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the output cell state from the last time step of the network. Additionally, if |options|.{{MLLstmOptions/returnSequence}} is set to true, the third element is the 4-D output tensor of shape *[steps, numDirections, batchSize, hiddenSize]* containing every output from each time step in the temporal sequence. + **Returns:** [=sequence=]<{{MLOperand}}>. The first element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the output hidden state from the last time step of the network. The second element is a 3-D tensor of shape *[numDirections, batchSize, hiddenSize]*, the output cell state from the last time step of the network. Additionally, if *options*.{{MLLstmOptions/returnSequence}} is set to true, the third element is the 4-D output tensor of shape *[steps, numDirections, batchSize, hiddenSize]* containing every output from each time step in the temporal sequence.
@@ -5735,8 +5735,8 @@ partial dictionary MLOpSupportLimits {
**Arguments:** - input: an {{MLOperand}}. The input 2-D tensor of shape *[batchSize, inputSize]*. - - weight: an {{MLOperand}}. The 2-D input weight tensor of shape *[4 * hiddenSize, inputSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options.layout*. - - recurrentWeight: an {{MLOperand}}. The 2-D recurrent weight tensor of shape *[4 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options.layout*. + - weight: an {{MLOperand}}. The 2-D input weight tensor of shape *[4 * hiddenSize, inputSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options*.{{MLLstmCellOptions/layout}}. + - recurrentWeight: an {{MLOperand}}. The 2-D recurrent weight tensor of shape *[4 * hiddenSize, hiddenSize]*. The ordering of the weight vectors in the first dimension of the tensor shape is specified according to *options*.{{MLLstmCellOptions/layout}}. - hiddenState: an {{MLOperand}}. The 2-D input hidden state tensor of shape *[batchSize, hiddenSize]*. - cellState: an {{MLOperand}}. The 2-D input cell state tensor of shape *[batchSize, hiddenSize]*. - hiddenSize: an {{unsigned long}} scalar. The value of the second dimension of the output tensor shape. It indicates the number of features in the hidden state. diff --git a/tools/lint.mjs b/tools/lint.mjs index 6eedb82f..07d0e506 100755 --- a/tools/lint.mjs +++ b/tools/lint.mjs @@ -251,6 +251,13 @@ for (const algorithm of root.querySelectorAll('.algorithm')) { } } +// Eschew vars outside of algorithms. +const algorithmVars = new Set(root.querySelectorAll('.algorithm var')); +for (const v of root.querySelectorAll('var').filter(v => !algorithmVars.has(v))) { + error(`Variable outside of algorithm: ${v.innerText}`); +} + + // Prevent accidental normative references to other specs. This reports an error // if there is a normative reference to any spec *other* than these ones. This // helps avoid an autolink like [=object=] adding an unexpected reference to