Functions | |
template<typename Real > | |
void | RegularizeL1 (CuMatrixBase< Real > *weight, CuMatrixBase< Real > *gradient, Real l1_penalty, Real learning_rate) |
RegularizeL1 is a gradient step with l1 regularization added to the gradient. More... | |
template<typename Real > | |
void | Randomize (const CuMatrixBase< Real > &src, const CuArray< int32 > ©_from_idx, CuMatrixBase< Real > *tgt) |
Copies a permutation of src into tgt. More... | |
template<typename Real > | |
void | Splice (const CuMatrixBase< Real > &src, const CuArray< int32 > &frame_offsets, CuMatrixBase< Real > *tgt) |
Splice concatenates frames of src as specified in frame_offsets into tgt. More... | |
template<typename Real > | |
void | Copy (const CuMatrixBase< Real > &src, const CuArray< int32 > ©_from_indices, CuMatrixBase< Real > *tgt) |
Copies elements from src into tgt as given by copy_from_indices. More... | |
template<typename Real > | |
void | EnsureNonzero (const CuMatrixBase< Real > &src, Real epsilon, CuMatrixBase< Real > *dest) |
This function requires that src and dest have the same dimension and epsilon > 0. More... | |
template void | RegularizeL1 (CuMatrixBase< float > *weight, CuMatrixBase< float > *grad, float l1, float lr) |
template void | RegularizeL1 (CuMatrixBase< double > *weight, CuMatrixBase< double > *grad, double l1, double lr) |
template void | Splice (const CuMatrixBase< float > &src, const CuArray< int32 > &frame_offsets, CuMatrixBase< float > *tgt) |
template void | Splice (const CuMatrixBase< double > &src, const CuArray< int32 > &frame_offsets, CuMatrixBase< double > *tgt) |
template void | Copy (const CuMatrixBase< float > &src, const CuArray< int32 > ©_from_indices, CuMatrixBase< float > *tgt) |
template void | Copy (const CuMatrixBase< double > &src, const CuArray< int32 > ©_from_indices, CuMatrixBase< double > *tgt) |
template void | Randomize (const CuMatrixBase< float > &src, const CuArray< int32 > ©_from_idx, CuMatrixBase< float > *tgt) |
template void | Randomize (const CuMatrixBase< double > &src, const CuArray< int32 > ©_from_idx, CuMatrixBase< double > *tgt) |
template<typename Real > | |
void | NormalizePerRow (const CuMatrixBase< Real > &in, const Real target_rms, const bool add_log_stddev, CuMatrixBase< Real > *out) |
Normalize nonlinearity modifies the vector of activations by scaling it so that the root-mean-square equals 1.0. More... | |
template void | NormalizePerRow (const CuMatrixBase< float > &in, const float target_rms, const bool add_log_stddev, CuMatrixBase< float > *out) |
template void | NormalizePerRow (const CuMatrixBase< double > &in, const double target_rms, const bool add_log_stddev, CuMatrixBase< double > *out) |
template<typename Real > | |
void | DiffNormalizePerRow (const CuMatrixBase< Real > &in_value, const CuMatrixBase< Real > &out_deriv, const Real target_rms, const bool add_log_stddev, CuMatrixBase< Real > *in_deriv) |
template void | DiffNormalizePerRow (const CuMatrixBase< float > &in_value, const CuMatrixBase< float > &out_deriv, const float target_rms, const bool add_log_stddev, CuMatrixBase< float > *in_deriv) |
template void | DiffNormalizePerRow (const CuMatrixBase< double > &in_value, const CuMatrixBase< double > &out_deriv, const double target_rms, const bool add_log_stddev, CuMatrixBase< double > *in_deriv) |
template<typename Real > | |
static Real | ScalarSigmoid (Real a) |
template<typename Real > | |
static Real | ScalarTanh (Real a) |
template<typename Real > | |
void | CpuComputeLstmNonlinearity (const MatrixBase< Real > &input_mat, const MatrixBase< Real > ¶ms_mat, MatrixBase< Real > *output) |
template<typename Real > | |
void | ComputeLstmNonlinearity (const CuMatrixBase< Real > &input, const CuMatrixBase< Real > ¶ms, CuMatrixBase< Real > *output) |
this is a special-purpose function used by class LstmNonlinearityComponent, to do its forward propagation. More... | |
template void | CpuComputeLstmNonlinearity (const MatrixBase< float > &input_mat, const MatrixBase< float > ¶ms_mat, MatrixBase< float > *output) |
template void | CpuComputeLstmNonlinearity (const MatrixBase< double > &input_mat, const MatrixBase< double > ¶ms_mat, MatrixBase< double > *output) |
template void | ComputeLstmNonlinearity (const CuMatrixBase< float > &input, const CuMatrixBase< float > ¶ms, CuMatrixBase< float > *output) |
template void | ComputeLstmNonlinearity (const CuMatrixBase< double > &input, const CuMatrixBase< double > ¶ms, CuMatrixBase< double > *output) |
template<typename Real > | |
void | CpuBackpropLstmNonlinearity (const MatrixBase< Real > &input, const MatrixBase< Real > ¶ms, const MatrixBase< Real > &output_deriv, const MatrixBase< double > &deriv_sum_in, const VectorBase< Real > &self_repair_config, double count_in, MatrixBase< Real > *input_deriv, MatrixBase< Real > *params_deriv, MatrixBase< double > *value_sum_out, MatrixBase< double > *deriv_sum_out, MatrixBase< Real > *self_repair_sum_out) |
template<typename Real > | |
void | BackpropLstmNonlinearity (const CuMatrixBase< Real > &input, const CuMatrixBase< Real > ¶ms, const CuMatrixBase< Real > &output_deriv, const CuMatrixBase< double > &deriv_sum_in, const CuVectorBase< Real > &self_repair_config, double count_in, CuMatrixBase< Real > *input_deriv, CuMatrixBase< Real > *params_deriv, CuMatrixBase< double > *value_sum_out, CuMatrixBase< double > *deriv_sum_out, CuMatrixBase< Real > *self_repair_sum_out) |
This function does the 'backward' pass corresponding to the function ComputeLstmNonlinearity. More... | |
template<typename Real > | |
void | EnsureNonzero (const CuVectorBase< Real > &src, Real epsilon, CuVectorBase< Real > *dest) |
Vector version of EnsureNonzero, see matrix version for documentation. More... | |
template void | EnsureNonzero (const CuMatrixBase< float > &src, float epsilon, CuMatrixBase< float > *dest) |
template void | EnsureNonzero (const CuMatrixBase< double > &src, double epsilon, CuMatrixBase< double > *dest) |
template void | EnsureNonzero (const CuVectorBase< float > &src, float epsilon, CuVectorBase< float > *dest) |
template void | EnsureNonzero (const CuVectorBase< double > &src, double epsilon, CuVectorBase< double > *dest) |
template void | CpuBackpropLstmNonlinearity (const MatrixBase< float > &input, const MatrixBase< float > ¶ms, const MatrixBase< float > &output_deriv, const MatrixBase< double > &deriv_sum_in, const VectorBase< float > &self_repair_config, double count_in, MatrixBase< float > *input_deriv, MatrixBase< float > *params_deriv, MatrixBase< double > *value_sum_out, MatrixBase< double > *deriv_sum_out, MatrixBase< float > *self_repair_sum_out) |
template void | CpuBackpropLstmNonlinearity (const MatrixBase< double > &input, const MatrixBase< double > ¶ms, const MatrixBase< double > &output_deriv, const MatrixBase< double > &deriv_sum_in, const VectorBase< double > &self_repair_config, double count_in, MatrixBase< double > *input_deriv, MatrixBase< double > *params_deriv, MatrixBase< double > *value_sum_out, MatrixBase< double > *deriv_sum_out, MatrixBase< double > *self_repair_sum_out) |
template void | BackpropLstmNonlinearity (const CuMatrixBase< float > &input, const CuMatrixBase< float > ¶ms, const CuMatrixBase< float > &output_deriv, const CuMatrixBase< double > &deriv_sum_in, const CuVectorBase< float > &self_repair_config, double count_in, CuMatrixBase< float > *input_deriv, CuMatrixBase< float > *params_deriv, CuMatrixBase< double > *value_sum_out, CuMatrixBase< double > *deriv_sum_out, CuMatrixBase< float > *self_repair_sum_out) |
template void | BackpropLstmNonlinearity (const CuMatrixBase< double > &input, const CuMatrixBase< double > ¶ms, const CuMatrixBase< double > &output_deriv, const CuMatrixBase< double > &deriv_sum_in, const CuVectorBase< double > &self_repair_config, double count_in, CuMatrixBase< double > *input_deriv, CuMatrixBase< double > *params_deriv, CuMatrixBase< double > *value_sum_out, CuMatrixBase< double > *deriv_sum_out, CuMatrixBase< double > *self_repair_sum_out) |
void BackpropLstmNonlinearity | ( | const CuMatrixBase< Real > & | input, |
const CuMatrixBase< Real > & | params, | ||
const CuMatrixBase< Real > & | output_deriv, | ||
const CuMatrixBase< double > & | deriv_sum_in, | ||
const CuVectorBase< Real > & | self_repair_config, | ||
double | count_in, | ||
CuMatrixBase< Real > * | input_deriv, | ||
CuMatrixBase< Real > * | params_deriv, | ||
CuMatrixBase< double > * | value_sum_out, | ||
CuMatrixBase< double > * | deriv_sum_out, | ||
CuMatrixBase< Real > * | self_repair_sum_out | ||
) |
This function does the 'backward' pass corresponding to the function ComputeLstmNonlinearity.
It's a little more complicated than you might expect because of the 'self-repair' mechanism that we use to prevent the sigmoid and tanh nonlinearities oversaturating, and because of the average-activation and average-derivative stats that we store for these nonlinearites (these stats are used both to control the self-repair mechanism, and for diagnostic purposes).
Because the forward pass computes various intermediate values that are not output, this function actually has to do the same computations as the forward pass before it actually does the backprop.
[in] | input | The same as in ComputeLstmNonlinearity(). A matrix, of dimension N by 5C (i.e. its num-cols must be a multiple of 5). The column-space is interpreted as 5 consecutive blocks, each of dimension C, which we name: (i_part, f_part, c_part, o_part, c_{t-1}). This function will also accept input of dimension N by 5C + 3, and the three final elements will be interpreted as scaling factors on i_t, f_t and o_t (useful as per-frame dropout masks). |
[in] | params | The same as in ComputeLstmNonlinearity(). A matrix, of dimension 3 by C, with rows containing the three diagonal parameter matrices used in LSTMs, namely w_{ic}, w_{fc} and w_{oc}. |
[in] | output_deriv | A matrix, of dimension N by 2C, containing the derivative of the objective function we're backpropagating, w.r.t. the quantities c_t and m_t (in two blocks of column-dimension C). |
[in] | deriv_sum_in | This is used in the self-repair code to identify oversaturated nonlinearities. It is a matrix, of dimension 5 by C, corresponding to the totals of the derivatives of the 5 sigmoid and tanh nonlinearities, in they order they appear in the equations in the documentation of ComputeLstmNonlinearity() Rspectively, they appear in the equations for (i_t, f_t, c_t, o_t, m_t). This will be divided by 'count_in' to get the average derivative value so far, for each of the nonlinearities. |
[in] | self_repair_config | A vector of dimension 10, containing the configuration of the self-repair to be used for the 5 nonlinearities. The first 5 elements are the self_repair_lower_threshold values (typically 0.05 for sigmoid and 0.2 for tanh), and the next 5 elements are the corresponding self-repair-scales (typically 10^-5). |
[in] | count_in | The data-count that corresponds to the stats in 'deriv_sum_in' at entry to the function. This function should tolerate the count being zero (in that case, it is free to do the self-repair or not, as this should only happen on the 1st minibatch of each training job). |
[out] | input_deriv | May be NULL; if not, this function writes, to this location, the backpropagated derivative of the objective function w.r.t. the 'input' matrix. This matrix should have the same dimension as 'input'. In addition to the regular backpropagated derivative, the output will include small values relating to 'self-repair'. If the input is of column-dimension 5C + 3 (i.e. we are using dropout masks), the derivatives w.r.t. the dropout masks will not be set; they will retain their value prior to this function call. |
[out] | params_deriv | May be NULL; if not, this is where this function *writes* [not adds] the backpropagated derivative of the objective function w.r.t. 'params'; it should have the same dimension as 'params' (3 by C). (This matrix will then be processed by the natural gradient code and added to the appropriate copy of the parameter matrix, outside this function). |
[out] | value_sum_out | Must be NULL if params_deriv is NULL; if not, a matrix of dimension 5 by C. This function *adds* to this location the total value of each of the sigmoid/tanh nonlinearities that it computes (this is for diagnostic purposes). |
[out] | deriv_sum_out | Must be NULL if params_deriv is NULL; if not, a matrix of dimension 5 by C; this function *adds* to this location the total of the derivative of each of the sigmoid/tanh nonlinearities that it computes (this is for diagnostic purposes and to control the self-repair). This function should tolerate the case when 'deriv_sum_out' points to the same data as 'deriv_sum_in'. |
[out] | self_repair_sum_out | Must be NULL if params_deriv is NULL; if not, a matrix of dimension 5 by C; this function *writes* to this location the sum of the number of times the self-repair code was activated (integer values 0 <= k <= N). This will be processed outside this function into self-repair stats for diagnostics. |
Definition at line 768 of file cu-math.cc.
References CpuBackpropLstmNonlinearity(), CU1DBLOCK, CuVectorBase< Real >::Data(), CuMatrixBase< Real >::Data(), CuVectorBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::Mat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), kaldi::SameDim(), CuMatrixBase< Real >::Stride(), and CuVectorBase< Real >::Vec().
Referenced by LstmNonlinearityComponent::Backprop(), EnsureNonzero(), kaldi::UnitTestBackpropLstmNonlinearity(), and kaldi::UnitTestLstmNonlinearity().
template void kaldi::cu::BackpropLstmNonlinearity | ( | const CuMatrixBase< float > & | input, |
const CuMatrixBase< float > & | params, | ||
const CuMatrixBase< float > & | output_deriv, | ||
const CuMatrixBase< double > & | deriv_sum_in, | ||
const CuVectorBase< float > & | self_repair_config, | ||
double | count_in, | ||
CuMatrixBase< float > * | input_deriv, | ||
CuMatrixBase< float > * | params_deriv, | ||
CuMatrixBase< double > * | value_sum_out, | ||
CuMatrixBase< double > * | deriv_sum_out, | ||
CuMatrixBase< float > * | self_repair_sum_out | ||
) |
template void kaldi::cu::BackpropLstmNonlinearity | ( | const CuMatrixBase< double > & | input, |
const CuMatrixBase< double > & | params, | ||
const CuMatrixBase< double > & | output_deriv, | ||
const CuMatrixBase< double > & | deriv_sum_in, | ||
const CuVectorBase< double > & | self_repair_config, | ||
double | count_in, | ||
CuMatrixBase< double > * | input_deriv, | ||
CuMatrixBase< double > * | params_deriv, | ||
CuMatrixBase< double > * | value_sum_out, | ||
CuMatrixBase< double > * | deriv_sum_out, | ||
CuMatrixBase< double > * | self_repair_sum_out | ||
) |
void ComputeLstmNonlinearity | ( | const CuMatrixBase< Real > & | input, |
const CuMatrixBase< Real > & | params, | ||
CuMatrixBase< Real > * | output | ||
) |
this is a special-purpose function used by class LstmNonlinearityComponent, to do its forward propagation.
It computes the core part of the LSTM nonlinearity. Refer to class LstmNonlinearityComponent in ../nnet3/nnet-simple-component.h for more context.
[in] | input | A matrix, of dimension N by 5C (i.e. its num-cols must be a multiple of 5). The column-space is interpreted as 5 consecutive blocks, each of dimension C, which we name: (i_part, f_part, c_part, o_part, c_{t-1}). This function will also accept input of dimension N by 5C + 3, and the three final elements will be used as scaling factors on i_t, f_t and o_t (useful as per-frame dropout masks). |
[in] | params | A matrix, of dimension 3 by C, with rows containing the three diagonal parameter matrices used in LSTMs, namely w_{ic}, w_{fc} and w_{oc}. |
[out] | output | A matrix, of dimension N by 2C. The quantities c_t and m_t respectively are put there (in two blocks of column-dimension C), according to the following equations: |
i_t = Sigmoid(i_part + w_{ic}*c_{t-1}) f_t = Sigmoid(f_part + w_{fc}*c_{t-1}) c_t = f_t*c_{t-1} + i_t * Tanh(c_part) o_t = Sigmoid(o_part + w_{oc}*c_t) m_t = o_t * Tanh(c_t)
Note on dropout: if the dropout mask is provided, let the mask values be i_t_mask, f_t_mask and o_t_mask (for each matrix row, these are scalars while i_t, f_t and o_t are of dimension C, because this is 'per-frame' dropout as described in http://www.danielpovey.com/files/2017_interspeech_dropout.pdf). Then the modification to the equations above consists of replacing 'i_t' with 'i_t_mask * i_t' in the RHS of the equations above, and the same type of change for f_t and o_t.
Definition at line 489 of file cu-math.cc.
References CpuComputeLstmNonlinearity(), CU1DBLOCK, CuMatrixBase< Real >::Data(), KALDI_ASSERT, CuMatrixBase< Real >::Mat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuMatrixBase< Real >::Stride().
Referenced by LstmNonlinearityComponent::Propagate(), kaldi::UnitTestCuMathComputeLstmNonlinearity(), and kaldi::UnitTestLstmNonlinearity().
template void kaldi::cu::ComputeLstmNonlinearity | ( | const CuMatrixBase< float > & | input, |
const CuMatrixBase< float > & | params, | ||
CuMatrixBase< float > * | output | ||
) |
template void kaldi::cu::ComputeLstmNonlinearity | ( | const CuMatrixBase< double > & | input, |
const CuMatrixBase< double > & | params, | ||
CuMatrixBase< double > * | output | ||
) |
void Copy | ( | const CuMatrixBase< Real > & | src, |
const CuArray< int32 > & | copy_from_indices, | ||
CuMatrixBase< Real > * | tgt | ||
) |
Copies elements from src into tgt as given by copy_from_indices.
The matrices src and tgt must have the same dimensions and the dimension of copy_from_indices must equal the number of columns in the src matrix. As a result, tgt(i, j) == src(i, copy_from_indices[j]). Also see CuMatrix::CopyCols(), which is more general.
Definition at line 173 of file cu-math.cc.
References CU2DBLOCK, CuArrayBase< T >::Data(), CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::Mat(), CuMatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and CuMatrixBase< Real >::NumRows().
Referenced by Component::BackpropNeedsOutput(), AffineComponent::BackpropNeedsOutput(), SpliceComponent::BackpropNeedsOutput(), SpliceMaxComponent::BackpropNeedsOutput(), BlockAffineComponent::BackpropNeedsOutput(), SumGroupComponent::BackpropNeedsOutput(), DctComponent::BackpropNeedsOutput(), FixedLinearComponent::BackpropNeedsOutput(), FixedAffineComponent::BackpropNeedsOutput(), FixedScaleComponent::BackpropNeedsOutput(), FixedBiasComponent::BackpropNeedsOutput(), DropoutComponent::BackpropNeedsOutput(), Convolutional1dComponent::BackpropNeedsOutput(), SwitchingForwardingDescriptor::Copy(), EnsureNonzero(), AppendTransform::Estimate(), SimpleMeanTransform::Estimate(), FmllrTransform::Estimate(), PermuteComponent::OutputDim(), CopyComponent::PropagateFnc(), DifferentiableTransform::SetNumClasses(), kaldi::TestClusterUtilsVector(), AffineComponentPreconditioned::Type(), AffineComponentPreconditionedOnline::Type(), BlockAffineComponentPreconditioned::Type(), and kaldi::UnitTestCuMathCopy().
template void kaldi::cu::Copy | ( | const CuMatrixBase< float > & | src, |
const CuArray< int32 > & | copy_from_indices, | ||
CuMatrixBase< float > * | tgt | ||
) |
template void kaldi::cu::Copy | ( | const CuMatrixBase< double > & | src, |
const CuArray< int32 > & | copy_from_indices, | ||
CuMatrixBase< double > * | tgt | ||
) |
void CpuBackpropLstmNonlinearity | ( | const MatrixBase< Real > & | input, |
const MatrixBase< Real > & | params, | ||
const MatrixBase< Real > & | output_deriv, | ||
const MatrixBase< double > & | deriv_sum_in, | ||
const VectorBase< Real > & | self_repair_config, | ||
double | count_in, | ||
MatrixBase< Real > * | input_deriv, | ||
MatrixBase< Real > * | params_deriv, | ||
MatrixBase< double > * | value_sum_out, | ||
MatrixBase< double > * | deriv_sum_out, | ||
MatrixBase< Real > * | self_repair_sum_out | ||
) |
Definition at line 543 of file cu-math.cc.
References count, VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), kaldi::SameDim(), ScalarSigmoid(), and ScalarTanh().
Referenced by BackpropLstmNonlinearity(), EnsureNonzero(), and kaldi::UnitTestBackpropLstmNonlinearity().
template void kaldi::cu::CpuBackpropLstmNonlinearity | ( | const MatrixBase< float > & | input, |
const MatrixBase< float > & | params, | ||
const MatrixBase< float > & | output_deriv, | ||
const MatrixBase< double > & | deriv_sum_in, | ||
const VectorBase< float > & | self_repair_config, | ||
double | count_in, | ||
MatrixBase< float > * | input_deriv, | ||
MatrixBase< float > * | params_deriv, | ||
MatrixBase< double > * | value_sum_out, | ||
MatrixBase< double > * | deriv_sum_out, | ||
MatrixBase< float > * | self_repair_sum_out | ||
) |
template void kaldi::cu::CpuBackpropLstmNonlinearity | ( | const MatrixBase< double > & | input, |
const MatrixBase< double > & | params, | ||
const MatrixBase< double > & | output_deriv, | ||
const MatrixBase< double > & | deriv_sum_in, | ||
const VectorBase< double > & | self_repair_config, | ||
double | count_in, | ||
MatrixBase< double > * | input_deriv, | ||
MatrixBase< double > * | params_deriv, | ||
MatrixBase< double > * | value_sum_out, | ||
MatrixBase< double > * | deriv_sum_out, | ||
MatrixBase< double > * | self_repair_sum_out | ||
) |
void CpuComputeLstmNonlinearity | ( | const MatrixBase< Real > & | input_mat, |
const MatrixBase< Real > & | params_mat, | ||
MatrixBase< Real > * | output | ||
) |
Definition at line 445 of file cu-math.cc.
References MatrixBase< Real >::Data(), KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::RowData(), ScalarSigmoid(), ScalarTanh(), and MatrixBase< Real >::Stride().
Referenced by ComputeLstmNonlinearity(), and kaldi::UnitTestCuMathComputeLstmNonlinearity().
template void kaldi::cu::CpuComputeLstmNonlinearity | ( | const MatrixBase< float > & | input_mat, |
const MatrixBase< float > & | params_mat, | ||
MatrixBase< float > * | output | ||
) |
template void kaldi::cu::CpuComputeLstmNonlinearity | ( | const MatrixBase< double > & | input_mat, |
const MatrixBase< double > & | params_mat, | ||
MatrixBase< double > * | output | ||
) |
void DiffNormalizePerRow | ( | const CuMatrixBase< Real > & | in_value, |
const CuMatrixBase< Real > & | out_deriv, | ||
const Real | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< Real > * | in_deriv | ||
) |
Definition at line 349 of file cu-math.cc.
References CuVectorBase< Real >::AddDiagMat2(), CuVectorBase< Real >::AddDiagMatMat(), CuMatrixBase< Real >::AddDiagVecMat(), CuVectorBase< Real >::ApplyFloor(), CU1DBLOCK, CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), kaldi::kNoTrans, kaldi::kTrans, kaldi::kUndefined, CuMatrixBase< Real >::MulRowsVec(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuMatrixBase< Real >::Stride().
Referenced by NormalizeComponent::Backprop(), and kaldi::UnitTestCuDiffNormalizePerRow().
template void kaldi::cu::DiffNormalizePerRow | ( | const CuMatrixBase< float > & | in_value, |
const CuMatrixBase< float > & | out_deriv, | ||
const float | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< float > * | in_deriv | ||
) |
template void kaldi::cu::DiffNormalizePerRow | ( | const CuMatrixBase< double > & | in_value, |
const CuMatrixBase< double > & | out_deriv, | ||
const double | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< double > * | in_deriv | ||
) |
void EnsureNonzero | ( | const CuMatrixBase< Real > & | src, |
Real | epsilon, | ||
CuMatrixBase< Real > * | dest | ||
) |
This function requires that src and dest have the same dimension and epsilon > 0.
It copies src to dest while ensuring that the values are bounded away from zero by at least epsilon:
Definition at line 209 of file cu-math.cc.
References Copy(), CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), Randomize(), RegularizeL1(), CuMatrixBase< Real >::RowData(), kaldi::SameDim(), Splice(), and CuMatrixBase< Real >::Stride().
Referenced by ScaleAndOffsetComponent::BackpropInternal(), EnsureNonzero(), ScaleAndOffsetComponent::PropagateInternal(), and kaldi::UnitTestEnsureNonzero().
void EnsureNonzero | ( | const CuVectorBase< Real > & | src, |
Real | epsilon, | ||
CuVectorBase< Real > * | dest | ||
) |
Vector version of EnsureNonzero, see matrix version for documentation.
Definition at line 915 of file cu-math.cc.
References BackpropLstmNonlinearity(), CpuBackpropLstmNonlinearity(), CuVectorBase< Real >::Data(), CuVectorBase< Real >::Dim(), EnsureNonzero(), and KALDI_ASSERT.
template void kaldi::cu::EnsureNonzero | ( | const CuMatrixBase< float > & | src, |
float | epsilon, | ||
CuMatrixBase< float > * | dest | ||
) |
template void kaldi::cu::EnsureNonzero | ( | const CuMatrixBase< double > & | src, |
double | epsilon, | ||
CuMatrixBase< double > * | dest | ||
) |
template void kaldi::cu::EnsureNonzero | ( | const CuVectorBase< float > & | src, |
float | epsilon, | ||
CuVectorBase< float > * | dest | ||
) |
template void kaldi::cu::EnsureNonzero | ( | const CuVectorBase< double > & | src, |
double | epsilon, | ||
CuVectorBase< double > * | dest | ||
) |
void NormalizePerRow | ( | const CuMatrixBase< Real > & | in, |
const Real | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< Real > * | out | ||
) |
Normalize nonlinearity modifies the vector of activations by scaling it so that the root-mean-square equals 1.0.
The output y_i = scale * x_i, and we want to RMS value of the y_i to equal target_rms, so y^t y = D * target_rms^2 (if y is one row of the input). we need to have scale = 1.0 / sqrt(x^t x / (D * target_rms^2)). there is also flooring involved, to avoid division-by-zero problems. It's important for the backprop, that the floor's square root is exactly representable as float. If add_log_stddev_ is true, log(max(epsi, sqrt(x^t x / D))) is an extra dimension of the output.
Definition at line 280 of file cu-math.cc.
References CuMatrixBase< Real >::CopyColFromVec(), CuMatrixBase< Real >::CopyFromMat(), CU1DBLOCK, CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, kaldi::kNoTrans, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), kaldi::SameDim(), and CuMatrixBase< Real >::Stride().
Referenced by NormalizeComponent::Propagate(), kaldi::UnitTestCuMathNormalizePerRow(), and kaldi::UnitTestCuMathNormalizePerRow_v2().
template void kaldi::cu::NormalizePerRow | ( | const CuMatrixBase< float > & | in, |
const float | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< float > * | out | ||
) |
template void kaldi::cu::NormalizePerRow | ( | const CuMatrixBase< double > & | in, |
const double | target_rms, | ||
const bool | add_log_stddev, | ||
CuMatrixBase< double > * | out | ||
) |
void Randomize | ( | const CuMatrixBase< Real > & | src, |
const CuArray< int32 > & | copy_from_idx, | ||
CuMatrixBase< Real > * | tgt | ||
) |
Copies a permutation of src into tgt.
The row permutation is specified in copy_from_idx such that src.Row(copy_from_idx[r]) == tgt.Row(r). The dimensions of copy_from_idx must be equivalent to the number of rows in tgt and src and all elements in the vector must be in [0, src.numRows()-1].
Definition at line 80 of file cu-math.cc.
References CuArrayBase< T >::Data(), CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), CuMatrixBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, CuMatrixBase< Real >::Mat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), and MatrixDim_::rows.
Referenced by EnsureNonzero(), MatrixRandomizer::NumFrames(), VectorRandomizer::NumFrames(), StdVectorRandomizer< T >::NumFrames(), MatrixRandomizer::Randomize(), and kaldi::UnitTestCuMathRandomize().
template void kaldi::cu::Randomize | ( | const CuMatrixBase< float > & | src, |
const CuArray< int32 > & | copy_from_idx, | ||
CuMatrixBase< float > * | tgt | ||
) |
template void kaldi::cu::Randomize | ( | const CuMatrixBase< double > & | src, |
const CuArray< int32 > & | copy_from_idx, | ||
CuMatrixBase< double > * | tgt | ||
) |
void RegularizeL1 | ( | CuMatrixBase< Real > * | weight, |
CuMatrixBase< Real > * | gradient, | ||
Real | l1_penalty, | ||
Real | learning_rate | ||
) |
RegularizeL1 is a gradient step with l1 regularization added to the gradient.
We don't let the value cross over zero from positive to negative or vice versa, in a single step. If an element tries to cross zero and is stopped, we zero the gradient. (Dan: not sure why).
Definition at line 37 of file cu-math.cc.
References CU2DBLOCK, CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::Mat(), MatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), CuMatrixBase< Real >::NumRows(), kaldi::SameDim(), and CuMatrixBase< Real >::Stride().
Referenced by EnsureNonzero(), LinearTransform::Update(), and AffineTransform::Update().
template void kaldi::cu::RegularizeL1 | ( | CuMatrixBase< float > * | weight, |
CuMatrixBase< float > * | grad, | ||
float | l1, | ||
float | lr | ||
) |
template void kaldi::cu::RegularizeL1 | ( | CuMatrixBase< double > * | weight, |
CuMatrixBase< double > * | grad, | ||
double | l1, | ||
double | lr | ||
) |
|
inlinestatic |
Definition at line 424 of file cu-math.cc.
References kaldi::Exp().
Referenced by CpuBackpropLstmNonlinearity(), and CpuComputeLstmNonlinearity().
|
inlinestatic |
Definition at line 434 of file cu-math.cc.
References kaldi::Exp().
Referenced by CpuBackpropLstmNonlinearity(), and CpuComputeLstmNonlinearity().
void Splice | ( | const CuMatrixBase< Real > & | src, |
const CuArray< int32 > & | frame_offsets, | ||
CuMatrixBase< Real > * | tgt | ||
) |
Splice concatenates frames of src as specified in frame_offsets into tgt.
The dimensions of tgt must be equivalent to the number of rows in src and it must be that tgt.NumColumns == src.NumColumns * frame_offsets.Dim(). As a result, tgt(i, k*n_cols + j) == src(i + frame_offsets[k], j) for the general case where i in [0..src.NumRows()-1], k in [0..frame_offsets.Dim()-1], j in [0..src.NumRows()-1] and n_cols = src.NumColumns(). If i + frame_offsets[k] is greater than the number of rows in src or less than 0 than the right side of the equation is replaced by src(src.NumRows()-1, j) or src(0, j) respectively, to avoid an index out of bounds.
Definition at line 132 of file cu-math.cc.
References CU2DBLOCK, CuArrayBase< T >::Data(), CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::Mat(), MatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), CuMatrixBase< Real >::NumRows(), and MatrixBase< Real >::RowData().
Referenced by EnsureNonzero(), Component::NewComponentOfType(), Splice::PropagateFnc(), and kaldi::UnitTestCuMathSplice().
template void kaldi::cu::Splice | ( | const CuMatrixBase< float > & | src, |
const CuArray< int32 > & | frame_offsets, | ||
CuMatrixBase< float > * | tgt | ||
) |
template void kaldi::cu::Splice | ( | const CuMatrixBase< double > & | src, |
const CuArray< int32 > & | frame_offsets, | ||
CuMatrixBase< double > * | tgt | ||
) |