99 if (!m_Param.m_CifgEnabled)
111 if (m_Param.m_ProjectionEnabled)
119 if (m_Param.m_PeepholeEnabled)
127 if (m_Param.m_LayerNormEnabled)
139 return std::move(layer);
144 BOOST_ASSERT(inputShapes.size() == 3);
147 unsigned int batchSize = inputShapes[0][0];
148 unsigned int outputSize = inputShapes[1][1];
149 unsigned int numUnits = inputShapes[2][1];
151 std::vector<TensorShape> outShapes;
153 outShapes.push_back(
TensorShape({batchSize, outputSize}));
154 outShapes.push_back(
TensorShape({batchSize, numUnits}));
155 outShapes.push_back(
TensorShape({batchSize, outputSize}));
170 BOOST_ASSERT(inferredShapes.size() == 4);
174 "LstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null.");
176 "LstmLayer: m_BasicParameters.m_InputToCellWeights should not be null.");
178 "LstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null.");
180 "LstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null.");
182 "LstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null.");
184 "LstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null.");
186 "LstmLayer: m_BasicParameters.m_ForgetGateBias should not be null.");
188 "LstmLayer: m_BasicParameters.m_CellBias should not be null.");
190 "LstmLayer: m_BasicParameters.m_OutputGateBias should not be null.");
195 "LstmLayer: m_CifgParameters.m_InputToInputWeights should not be null.");
197 "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null.");
199 "LstmLayer: m_CifgParameters.m_InputGateBias should not be null.");
201 ConditionalThrowIfNotEqual<LayerValidationException>(
202 "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
209 "LstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled.");
211 "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value when CIFG is enabled.");
213 "LstmLayer: m_CifgParameters.m_CellToInputWeights should not have a value when CIFG is enabled.");
215 "LstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled.");
217 ConditionalThrowIfNotEqual<LayerValidationException>(
218 "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
226 "LstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null.");
232 "LstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null.");
234 "LstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null.");
237 ConditionalThrowIfNotEqual<LayerValidationException>(
238 "LstmLayer: TensorShape set on OutputSlot[1] does not match the inferred shape.",
241 ConditionalThrowIfNotEqual<LayerValidationException>(
242 "LstmLayer: TensorShape set on OutputSlot[2] does not match the inferred shape.",
245 ConditionalThrowIfNotEqual<LayerValidationException>(
246 "LstmLayer: TensorShape set on OutputSlot[3] does not match the inferred shape.",
255 "LstmLayer: m_LayerNormParameters.m_inputLayerNormWeights should not be null.");
258 "LstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights should not be null.");
260 "LstmLayer: m_LayerNormParameters.m_cellLayerNormWeights should not be null.");
262 "LstmLayer: m_LayerNormParameters.m_outputLayerNormWeights should not be null.");
307 inputToInputWeightsTensor = inputToInputWeightsTensorCopy;
315 inputToForgetWeightsTensor = inputToForgetWeightsTensorCopy;
323 inputToCellWeightsTensor = inputToCellWeightsTensorCopy;
331 inputToOutputWeightsTensor = inputToOutputWeightsTensorCopy;
340 recurrentToInputWeightsTensor = recurrentToInputWeightsTensorCopy;
349 recurrentToForgetWeightsTensor = recurrentToForgetWeightsTensorCopy;
358 recurrentToCellWeightsTensor = recurrentToCellWeightsTensorCopy;
367 recurrentToOutputWeightsTensor = recurrentToOutputWeightsTensorCopy;
375 cellToInputWeightsTensor = cellToInputWeightsTensorCopy;
383 cellToForgetWeightsTensor = cellToForgetWeightsTensorCopy;
391 cellToOutputWeightsTensor = cellToOutputWeightsTensorCopy;
399 inputGateBiasTensor = inputGateBiasTensorCopy;
407 forgetGateBiasTensor = forgetGateBiasTensorCopy;
415 cellBiasTensor = cellBiasTensorCopy;
423 outputGateBias = outputGateBiasCopy;
431 projectionWeightsTensor = projectionWeightsTensorCopy;
439 projectionBiasTensor = projectionBiasTensorCopy;
447 inputLayerNormTensor = inputLayerNormTensorCopy;
455 forgetLayerNormTensor = forgetLayerNormTensorCopy;
463 cellLayerNormTensor = cellLayerNormTensorCopy;
471 outputLayerNormTensor = outputLayerNormTensorCopy;
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
bool m_ProjectionEnabled
Enable/disable the projection layer.
LstmBasicParameters m_BasicParameters
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
const LstmDescriptor & GetParameters() const
const TensorShape & GetShape() const
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
const ConstCpuTensorHandle * m_RecurrentToForgetWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
const ConstCpuTensorHandle * m_CellToOutputWeights
const ConstCpuTensorHandle * m_InputToCellWeights
const ConstCpuTensorHandle * m_InputToOutputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
virtual void VisitLstmLayer(const IConnectableLayer *layer, const LstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)=0
Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked...
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
const ConstCpuTensorHandle * m_ProjectionBias
virtual std::unique_ptr< IWorkload > CreateLstm(const LstmQueueDescriptor &descriptor, const WorkloadInfo &info) const
const ConstCpuTensorHandle * m_OutputGateBias
const ConstCpuTensorHandle * m_CellToInputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the LSTM type.
const ConstCpuTensorHandle * m_CellLayerNormWeights
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Copyright (c) 2020 ARM Limited.
This layer represents a LSTM operation.
const ConstCpuTensorHandle * m_CellToForgetWeights
const ConstCpuTensorHandle * m_CellBias
const ConstCpuTensorHandle * m_RecurrentToInputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
const ConstCpuTensorHandle * m_InputLayerNormWeights
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer.
const ConstCpuTensorHandle * m_OutputLayerNormWeights
LstmLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
An LstmDescriptor for the LstmLayer.
const ConstCpuTensorHandle * m_ForgetGateBias
const ConstCpuTensorHandle * m_InputToInputWeights
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
bool m_PeepholeEnabled
Enable/disable peephole.
LstmOptLayerNormParameters m_LayerNormParameters
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Layer::ConstantTensors GetConstantTensorsByRef() override
Retrieve the handles to the constant values stored by the layer.
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
LstmOptPeepholeParameters m_PeepholeParameters
LstmOptProjectionParameters m_ProjectionParameters
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
const ConstCpuTensorHandle * m_RecurrentToOutputWeights
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
const ConstCpuTensorHandle * m_ForgetLayerNormWeights
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
const ConstCpuTensorHandle * m_InputGateBias
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
LstmLayer(const LstmDescriptor ¶m, const char *name)
Constructor to create a LstmLayer.
bool m_LayerNormEnabled
Enable/disable layer normalization.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
virtual const TensorInfo & GetTensorInfo() const =0
const ConstCpuTensorHandle * m_RecurrentToCellWeights
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
LstmOptCifgParameters m_CifgParameters
const char * GetName() const override
Returns the name of the layer.
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
const TensorInfo & GetTensorInfo() const override
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
const ConstCpuTensorHandle * m_ProjectionWeights
const ConstCpuTensorHandle * m_InputToForgetWeights