Fix LayerNorm Implementation

This commit is contained in:
Saksham Bansal
2019-06-18 02:50:41 +07:00
parent 9995041ff7
commit 33bce014a5
2 changed files with 4 additions and 2 deletions
@@ -184,6 +184,9 @@ class LayerNorm
//! Locally-stored normalized input.
OutputDataType normalized;
//! Locally-stored input with 0 mean.
OutputDataType inputMean;
}; // class LayerNorm
} // namespace ann
@@ -63,7 +63,7 @@ void LayerNorm<InputDataType, OutputDataType>::Forward(
// Normalize the input.
output = input.each_row() - mean;
inputMean = output;
output.each_row() /= arma::sqrt(variance + eps);
// Reused in the backward and gradient step.
@@ -79,7 +79,6 @@ template<typename eT>
void LayerNorm<InputDataType, OutputDataType>::Backward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& gy, arma::Mat<eT>&& g)
{
const arma::mat inputMean = input.each_row() - mean;
const arma::mat stdInv = 1.0 / arma::sqrt(variance + eps);
// dl / dxhat