From e0537f09fba5b52c40c540341d69ff18e4179323 Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Wed, 8 May 2019 16:57:56 +0100 Subject: [PATCH] Fix LSTM documentation The documentation said that cell-to-input weights are required to be present when input-to-input weights, recurrent-to-input weights and input gate bias are present. This was incorrect since this weights can be omitted if peephole connections are not used even if all the other tensors are present. Another bug that is fixed in this change is that for output #0 the docs said "of shape [batch_size, num_units * 4] with CIFG, or [batch_size, num_units * 3] without CIFG" when in fact it is the opposite, i.e. "of shape [batch_size, num_units * 3] with CIFG, or [batch_size, num_units * 4] without CIFG." Existing CTS/VTS tests expect behaviour described in the fixed documentation. Existing CPU implementation is also compliant with the fixed documentation. Fix: 111842951 Test: mma Change-Id: Id011783e33672ae65dc6fe3784cb26feb832acf9 --- current.txt | 4 ++-- neuralnetworks/1.0/types.hal | 25 +++++++++++++------------ neuralnetworks/1.2/types.hal | 21 +++++++++++---------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/current.txt b/current.txt index 30839471c9..c51d38f79f 100644 --- a/current.txt +++ b/current.txt @@ -401,7 +401,7 @@ f7d7cb747dc01a9fdb2d39a80003b4d8df9be733d65f5842198802eb6209db69 android.hardwar 65a021fa89085b62fc96b2b6d3bef2f9103cf4d63379c68bc154fd9eef672852 android.hardware.health@1.0::types b7ecf29927055ec422ec44bf776223f07d79ad9f92ccf9becf167e62c2607e7a android.hardware.keymaster@4.0::IKeymasterDevice 574e8f1499436fb4075894dcae0b36682427956ecb114f17f1fe22d116a83c6b android.hardware.neuralnetworks@1.0::IPreparedModel -e75759b40a1c5f97b463b30aab91954012c9ea9e454dde308db853a56796e5a6 android.hardware.neuralnetworks@1.0::types +1e3576c07006d82ba5bc6ddbf87c101414d361c41afe7a82713750844c488725 android.hardware.neuralnetworks@1.0::types eb754b58c93e5591613208b4c972811288b0fa16a82430d602f107c91a908b22 android.hardware.neuralnetworks@1.1::types 1d4a5776614c08b5d794a5ec5ab04697260cbd4b3441d5935cd53ee71d19da02 android.hardware.radio@1.0::IRadioResponse ed9da80ec0c96991fd03f0a46107815d0e50f764656e49dba4980fa5c31d5bc3 android.hardware.radio@1.0::types @@ -515,7 +515,7 @@ b83317b66721241887d2770b5ae95fd5af1e77c5daa7530ecb08fae8892f2b43 android.hardwar 92714960d1a53fc2ec557302b41c7cc93d2636d8364a44bd0f85be0c92927ff8 android.hardware.neuralnetworks@1.2::IExecutionCallback 36e1064c869965dee533c537cefbe87e54db8bd8cd45be7e0e93e00e8a43863a android.hardware.neuralnetworks@1.2::IPreparedModel e1c734d1545e1a4ae749ff1dd9704a8e594c59aea7c8363159dc258e93e0df3b android.hardware.neuralnetworks@1.2::IPreparedModelCallback -e3b6176e3bf235c4e0e4e451b0166e396c7ee176cfe167c9147c3d46d7b34f0c android.hardware.neuralnetworks@1.2::types +d18bba0b6c8d2d1da3cfb52b14f556d2e04eb91551d97ee60a3524cf993a3e0e android.hardware.neuralnetworks@1.2::types cf7a4ba516a638f9b82a249c91fb603042c2d9ca43fd5aad9cf6c0401ed2a5d7 android.hardware.nfc@1.2::INfc abf98c2ae08bf765db54edc8068e36d52eb558cff6706b6fd7c18c65a1f3fc18 android.hardware.nfc@1.2::types 4cb252dc6372a874aef666b92a6e9529915aa187521a700f0789065c3c702ead android.hardware.power.stats@1.0::IPowerStats diff --git a/neuralnetworks/1.0/types.hal b/neuralnetworks/1.0/types.hal index b0a1c1aec2..02db063e18 100644 --- a/neuralnetworks/1.0/types.hal +++ b/neuralnetworks/1.0/types.hal @@ -858,20 +858,21 @@ enum OperationType : int32_t { * elements of the input matrices. * * The operation has the following independently optional inputs: + * * The cell-to-input weights (\f$W_{ci}\f$), cell-to-forget weights + * (\f$W_{cf}\f$) and cell-to-output weights (\f$W_{co}\f$) either all + * have values or neither of them have values (i.e., all set to null). If + * they have values, the peephole optimization is used. * * The input-to-input weights (\f$W_{xi}\f$), recurrent-to-input weights - * (\f$W_{hi}\f$), cell-to-input (\f$W_{ci}\f$) weights, and input gate - * bias (\f$b_i\f$) either all have values, or none of them have values - * (i.e., all set to null). If they have no values, coupling of input and - * forget gates (CIFG) is used, in which case the input gate (\f$i_t\f$) - * is calculated using the following equation instead. + * (\f$W_{hi}\f$) and input gate bias (\f$b_i\f$) either all have values, + * or none of them have values. If they have no values, coupling of input + * and forget gates (CIFG) is used, in which case the input gate + * (\f$i_t\f$) is calculated using the following equation instead. * \f{eqnarray*}{ * i_t = 1 - f_t * \f} - * * The cell-to-forget weights (\f$W_{cf}\f$) and cell-to-output weights - * (\f$W_{co}\f$) either both have values or neither of them have values. - * If they have values, the peephole optimization is used. Additionally, - * if CIFG is not used, cell-to-input weights (\f$W_{ci}\f$) is also - * required to have values for peephole optimization. + * In case peephole optimization is used and CIFG is not used + * cell-to-input (\f$W_{ci}\f$) weights must be present. Otherwise, the + * cell-to-input weights must have no value. * * The projection weights (\f$W_{proj}\f$) is required only for the * recurrent projection layer, and should otherwise have no value. * * The projection bias (\f$b_{proj}\f$) may (but not required to) have a @@ -984,8 +985,8 @@ enum OperationType : int32_t { * Outputs: * * 0: The scratch buffer. * A 2-D tensor of {@link OperandType::TENSOR_FLOAT32}, of shape - * [batch_size, num_units * 4] with CIFG, or - * [batch_size, num_units * 3] without CIFG. + * [batch_size, num_units * 3] with CIFG, or + * [batch_size, num_units * 4] without CIFG. * * 1: The output state (out) (\f$h_t\f$). * A 2-D tensor of {@link OperandType::TENSOR_FLOAT32}, of shape * [batch_size, output_size]. diff --git a/neuralnetworks/1.2/types.hal b/neuralnetworks/1.2/types.hal index c2e8f22052..f368ce2cea 100644 --- a/neuralnetworks/1.2/types.hal +++ b/neuralnetworks/1.2/types.hal @@ -1177,20 +1177,21 @@ enum OperationType : int32_t { * https://arxiv.org/pdf/1607.06450.pdf * * The operation has the following independently optional inputs: + * * The cell-to-input weights (\f$W_{ci}\f$), cell-to-forget weights + * (\f$W_{cf}\f$) and cell-to-output weights (\f$W_{co}\f$) either all + * have values or neither of them have values (i.e., all set to null). If + * they have values, the peephole optimization is used. * * The input-to-input weights (\f$W_{xi}\f$), recurrent-to-input weights - * (\f$W_{hi}\f$), cell-to-input (\f$W_{ci}\f$) weights, and input gate - * bias (\f$b_i\f$) either all have values, or none of them have values - * (i.e., all set to null). If they have no values, coupling of input and - * forget gates (CIFG) is used, in which case the input gate (\f$i_t\f$) - * is calculated using the following equation instead. + * (\f$W_{hi}\f$) and input gate bias (\f$b_i\f$) either all have values, + * or none of them have values. If they have no values, coupling of input + * and forget gates (CIFG) is used, in which case the input gate + * (\f$i_t\f$) is calculated using the following equation instead. * \f{eqnarray*}{ * i_t = 1 - f_t * \f} - * * The cell-to-forget weights (\f$W_{cf}\f$) and cell-to-output weights - * (\f$W_{co}\f$) either both have values or neither of them have values. - * If they have values, the peephole optimization is used. Additionally, - * if CIFG is not used, cell-to-input weights (\f$W_{ci}\f$) is also - * required to have values for peephole optimization. + * In case peephole optimization is used and CIFG is not used + * cell-to-input (\f$W_{ci}\f$) weights must be present. Otherwise, the + * cell-to-input weights must have no value. * * The projection weights (\f$W_{proj}\f$) is required only for the * recurrent projection layer, and should otherwise have no value. * * The projection bias (\f$b_{proj}\f$) may (but not required to) have a