Skip to content

Commit 622ce75

Browse files
For gru() and lstm(), calculate gate descriptor, validate activations with it
1 parent 7a2ef03 commit 622ce75

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

index.bs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,13 @@ partial interface MLGraphBuilder {
30873087
1. If its [=MLOperand/rank=] is not 3, then [=exception/throw=] a {{TypeError}}.
30883088
1. If |options|.{{MLGruOptions/activations}} [=map/exists=] and its [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}.
30893089
1. If |steps| is not equal to |input|'s [=MLOperand/shape=][0], then [=exception/throw=] a {{TypeError}}.
3090+
1. Let |batchSize| be |input|'s [=MLOperand/shape=][1].
3091+
1. Let |numDirections| be 2 if |options|.{{MLGruOptions/direction}} is {{MLRecurrentNetworkDirection/"both"}}, or 1 otherwise.
3092+
1. If |options|.{{MLGruOptions/activations}} [=map/exists=]:
3093+
1. Let |gateDescriptor| be a new {{MLOperandDescriptor}}.
3094+
1. Set |gateDescriptor|.{{MLOperandDescriptor/dimensions}} to « |batchSize|, |hiddenSize| ».
3095+
1. Set |gateDescriptor|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
3096+
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLGruOptions/activations}} with |gateDescriptor| returns false, then [=exception/throw=] a {{TypeError}}.
30903097
1. *Calculate the output shape:*
30913098
1. Let |desc0| be a new {{MLOperandDescriptor}}.
30923099
1. Set |desc0|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |numDirections|, |batchSize|, |hiddenSize| ».
@@ -3095,7 +3102,6 @@ partial interface MLGraphBuilder {
30953102
1. Let |desc1| be a new {{MLOperandDescriptor}}.
30963103
1. Set |desc1|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
30973104
1. Set |desc1|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |steps|, |numDirections|, |batchSize|, |hiddenSize| ».
3098-
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLGruOptions/activations}} with |desc0| returns false, then [=exception/throw=] a {{TypeError}}.
30993105
1. *Make graph connections:*
31003106
1. Let |operator| be an [=operator=] for "gru", given |weight|, |recurrentWeight|, |steps|, |hiddenSize| and |options| as parameters.
31013107
1. Let |output0| be the result of [=creating an MLOperand=] given [=this=] and |desc0|.
@@ -3110,7 +3116,7 @@ partial interface MLGraphBuilder {
31103116
1. If |options|.{{MLGruOptions/bias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
31113117
1. If |options|.{{MLGruOptions/recurrentBias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
31123118
1. If |options|.{{MLGruOptions/initialHiddenState}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
3113-
1. Add |options|.{{MLGruOptions/activations}} to |operator|'s [=operator/activation functions=].
3119+
1. If |options|.{{MLGruOptions/activations}} [=map/exists=], then add it to |operator|'s [=operator/activation functions=].
31143120
1. Set |operator|'s [=operator/output=] to |output|.
31153121
1. Return |output|.
31163122
</details>
@@ -3258,15 +3264,15 @@ partial interface MLGraphBuilder {
32583264
1. Let |desc| be a new {{MLOperandDescriptor}}.
32593265
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |input|'s [=MLOperand/shape=][0], |hiddenSize| ».
32603266
1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
3261-
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLGruCellOptions/activations}} with |desc| returns false, then [=exception/throw=] a {{TypeError}}.
3267+
1. If |options|.{{MLGruCellOptions/activations}} [=map/exists=], and running the [=MLActivation/validation steps=] of any [=list/item=] in it with |desc| returns false, then [=exception/throw=] a {{TypeError}}.
32623268
1. *Make graph connections:*
32633269
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
32643270
1. Let |operator| be an [=operator=] for "gruCell", given |weight|, |recurrentWeight|, |hiddenState|, |hiddenSize| and |options| as parameters.
32653271
1. Set |output|.{{MLOperand/[[operator]]}} to |operator|.
32663272
1. Set |operator|'s [=operator/inputs=] to |input|, |weight|, |recurrentWeight|, and |hiddenState|.
32673273
1. If |options|.{{MLGruCellOptions/bias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
32683274
1. If |options|.{{MLGruCellOptions/recurrentBias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
3269-
1. Add |options|.{{MLGruCellOptions/activations}} to |operator|'s [=operator/activation functions=].
3275+
1. If |options|.{{MLGruCellOptions/activations}} [=map/exists=], then add it to |operator|'s [=operator/activation functions=].
32703276
1. Set |operator|'s [=operator/output=] to |output|.
32713277
1. Return |output|.
32723278
</details>
@@ -3969,7 +3975,7 @@ partial interface MLGraphBuilder {
39693975
</summary>
39703976
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |weight|, |recurrentWeight|, |options|.{{MLLstmOptions/bias}} (if it [=map/exists=]), |options|.{{MLLstmOptions/recurrentBias}} (if it [=map/exists=]), |options|.{{MLLstmOptions/peepholeWeight}} (if it [=map/exists=]), |options|.{{MLLstmOptions/initialHiddenState}} (if it [=map/exists=]), and |options|.{{MLLstmOptions/initialCellState}} (if it [=map/exists=]) returns false, then [=exception/throw=] a {{TypeError}}.
39713977
1. If |options|.{{MLLstmOptions/activations}} [=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and any [=list/item=] in it returns false, then [=exception/throw=] a {{TypeError}}.
3972-
1. Let |numDirections| be 1 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"forward"}}, or otherwise let it be 2.
3978+
1. Let |numDirections| be 2 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"both"}}, or 1 otherwise.
39733979
1. If the [=MLOperand/rank=] of any of |input|, |weight| or |recurrentWeight| is not 3, then [=exception/throw=] a {{TypeError}}.
39743980
1. If |input|'s [=MLOperand/shape=][0] is not equal to |steps|, then [=exception/throw=] a {{TypeError}}.
39753981
1. Let |batchSize| be |input|'s [=MLOperand/shape=][1].
@@ -3997,6 +4003,10 @@ partial interface MLGraphBuilder {
39974003
1. If its [=MLOperand/shape=][2] is not |hiddenSize|, then [=exception/throw=] a {{TypeError}}.
39984004
1. If |options|.{{MLLstmOptions/activations}} [=map/exists=]:
39994005
1. If its [=list/size=] is not 3, then [=exception/throw=] a {{TypeError}}.
4006+
1. Let |gateDescriptor| be a new {{MLOperandDescriptor}}.
4007+
1. Set |gateDescriptor|.{{MLOperandDescriptor/dimensions}} to [=/list=] « |batchSize|, |hiddenSize| ».
4008+
1. Set |gateDescriptor|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
4009+
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLLstmOptions/activations}} [=map/exists=] with |gateDescriptor| returns false, then [=exception/throw=] a {{TypeError}}.
40004010
1. *Calculate the output shape:*
40014011
1. Let |desc| be a new {{MLOperandDescriptor}}.
40024012
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |numDirections|, |batchSize|, |hiddenSize| ».
@@ -4005,7 +4015,6 @@ partial interface MLGraphBuilder {
40054015
1. Let |desc2| be a new {{MLOperandDescriptor}}.
40064016
1. Set |desc2|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
40074017
1. Set |desc2|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |steps|, |numDirections|, |batchSize|, |hiddenSize| ».
4008-
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLLstmOptions/activations}} with |desc| returns false, then [=exception/throw=] a {{TypeError}}.
40094018
1. *Make graph connections:*
40104019
1. Let |operator| be an [=operator=] for the LSTM operation, given |weight|, |recurrentWeight|, |steps|, |hiddenSize| and |options|.
40114020
1. Let |output0| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
@@ -4023,7 +4032,7 @@ partial interface MLGraphBuilder {
40234032
1. If |options|.{{MLLstmOptions/peepholeWeight}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
40244033
1. If |options|.{{MLLstmOptions/initialHiddenState}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
40254034
1. If |options|.{{MLLstmOptions/initialCellState}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
4026-
1. Add |options|.{{MLLstmOptions/activations}} to |operator|'s [=operator/activation functions=].
4035+
1. If |options|.{{MLLstmOptions/activations}} [=map/exists=], then add it to |operator|'s [=operator/activation functions=].
40274036
1. Set |operator|'s [=operator/output=] to |output|.
40284037
1. Return |output|.
40294038
</details>
@@ -4194,7 +4203,7 @@ partial interface MLGraphBuilder {
41944203
1. Let |desc| be a new {{MLOperandDescriptor}}.
41954204
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |batchSize|, |hiddenSize| ».
41964205
1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=].
4197-
1. If running the [=MLActivation/validation steps=] of any [=list/item=] in |options|.{{MLLstmCellOptions/activations}} with |desc| returns false, then [=exception/throw=] a {{TypeError}}.
4206+
1. If |options|.{{MLLstmCellOptions/activations}} [=map/exists=], and running the [=MLActivation/validation steps=] of any [=list/item=] in it with |desc| returns false, then [=exception/throw=] a {{TypeError}}.
41984207
1. *Make graph connections:*
41994208
1. Let |output0| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
42004209
1. Let |output1| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
@@ -4205,7 +4214,7 @@ partial interface MLGraphBuilder {
42054214
1. If |options|.{{MLLstmCellOptions/bias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
42064215
1. If |options|.{{MLLstmCellOptions/recurrentBias}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
42074216
1. If |options|.{{MLLstmCellOptions/peepholeWeight}} [=map/exists=], then add it to |operator|'s [=operator/inputs=].
4208-
1. Add |options|.{{MLLstmCellOptions/activations}} to |operator|'s [=operator/activation functions=].
4217+
1. If |options|.{{MLLstmCellOptions/activations}} [=map/exists=], then add it to |operator|'s [=operator/activation functions=].
42094218
1. Set |operator|'s [=operator/output=] to |output|.
42104219
1. Return |output|.
42114220
</details>

0 commit comments

Comments
 (0)