Classes | |
struct | ConvolutionComputation |
This struct represents the structure of a convolution computation. More... | |
struct | ConvolutionComputationIo |
struct | ConvolutionComputationOptions |
This struct contains options for compiling the convolutional computation. More... | |
struct | ConvolutionModel |
This comment explains the basic framework used for everything related to time-height convolution. More... | |
Functions | |
static void | GetRandomConvolutionModel (ConvolutionModel *model) |
static void | GetRandomConvolutionIndexes (const ConvolutionModel &model, std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) |
void | UnitTestTimeHeightConvolutionIo () |
void | TestComputationIo (const ConvolutionComputation &computation) |
void | ZeroBlankRows (const std::vector< Index > &indexes, CuMatrix< BaseFloat > *matrix) |
void | ConvolveForwardSimple (const ConvolutionModel &model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const CuMatrixBase< BaseFloat > &input_cu, const CuMatrixBase< BaseFloat > ¶ms_cu, CuMatrixBase< BaseFloat > *output_cu) |
void | TestRunningComputation (const ConvolutionModel &conv_model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const ConvolutionComputation &computation) |
void | TestDataBackprop (const ConvolutionModel &conv_model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const ConvolutionComputation &computation) |
void | TestParamsBackprop (const ConvolutionModel &conv_model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const ConvolutionComputation &computation) |
void | UnitTestTimeHeightConvolutionCompile () |
void | UnitTestTimeHeightConvolution () |
static void | ReverseColumnMapping (const std::vector< int32 > &columns, int32 input_dim, std::vector< std::vector< int32 > > *backward_columns) |
This function, used in ConvolutionComputation::ComputeDerived(), reverses a mapping that may not be unique. More... | |
static bool | VectorIsContiguous (const std::vector< int32 > &vec) |
static void | ConvolveForwardInternal (const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > ¶ms, CuMatrixBase< BaseFloat > *temp_mat, CuMatrixBase< BaseFloat > *output) |
void | ConvolveForward (const ConvolutionComputation &conv_comp, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > ¶ms, CuMatrixBase< BaseFloat > *output) |
This does the forward computation of convolution. More... | |
static void | ConvolveBackwardDataInternal (const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > ¶ms, const CuMatrixBase< BaseFloat > &output_deriv, CuMatrixBase< BaseFloat > *temp_mat, CuMatrixBase< BaseFloat > *input_deriv) |
void | ConvolveBackwardData (const ConvolutionComputation &conv_comp, const CuMatrixBase< BaseFloat > ¶ms, const CuMatrixBase< BaseFloat > &output_deriv, CuMatrixBase< BaseFloat > *input_deriv) |
This does the part of the backward derivative computation of convolution, that propagates derivatives back to the input data. More... | |
static void | ConvolveBackwardParamsInternal (const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &output_deriv, BaseFloat alpha, CuMatrixBase< BaseFloat > *temp_mat, CuMatrixBase< BaseFloat > *params_deriv) |
void | ConvolveBackwardParams (const ConvolutionComputation &conv_comp, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &output_deriv, BaseFloat alpha, CuMatrixBase< BaseFloat > *params_deriv) |
This does the part of the backward derivative computation of convolution, that computes derivatives w.r.t. More... | |
void | PadModelHeight (const ConvolutionModel &model, ConvolutionModel *model_padded) |
This function takes a model that might require zero padding in the height dimension and outputs a model accepting a possibly-larger input dimension which does not require zero padding. More... | |
static void | ComputeTempMatrixSize (const ConvolutionComputationOptions &opts, ConvolutionComputation *computation) |
This function sets 'temp_rows' and 'temp_cols' in 'computation'. More... | |
void | UnPadModelHeight (const ConvolutionComputationOptions &opts, const ConvolutionModel &model, const ConvolutionModel &model_padded, ConvolutionComputation *computation) |
This function modifies, if necessary, a computation that has been built for the model 'model_padded', so that it can work for the original model 'model'. More... | |
void | PadComputationInputTime (const ConvolutionModel &model, ConvolutionComputationIo *io) |
This function extends the set of input indexes that the computation has, to account for any required zero-padding in the time dimension. More... | |
static int32 | RoundDownToMultipleOf (int32 i, int32 n) |
static void | ShiftAllTimeOffsets (int32 shift, ConvolutionModel *model) |
static int32 | PrepareIoForAppending (ConvolutionComputationIo *io, ConvolutionComputationIo *io_appended) |
void | AppendInputFrames (const ConvolutionModel &model, ConvolutionComputationIo *io, ConvolutionModel *model_appended, ConvolutionComputationIo *io_appended) |
This function takes an input model and I/O specification, and it modifies both of them if necessary to ensure that the output 'io_appended' object has the same input and output time strides (i.e. More... | |
static bool | TimeValueInInput (const ConvolutionComputationIo &io, int32 t) |
void | CheckModelAndIo (const ConvolutionModel &model, const ConvolutionComputationIo &io, bool allow_extra_input=false) |
Check that this model and this I/O request are compatible in terms of required context, etc, and crash if not. More... | |
void | CompileConvolutionComputation (const ConvolutionModel &model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const ConvolutionComputationOptions &opts, ConvolutionComputation *computation, std::vector< Index > *input_indexes_modified, std::vector< Index > *output_indexes_modified) |
This function does the compilation for a convolution computation; it's a wrapper for the functions below, which should not have to be called by the end user. More... | |
static int32 | FindGcdOfDifferences (std::vector< int32 > &vec) |
static void | RegularizeTList (std::vector< int32 > &t_values, int32 *start, int32 *step, int32 *num_values) |
static void | CreateIndexes (const std::vector< std::pair< int32, int32 > > &n_x_pairs, int32 t_start, int32 t_step, int32 num_t_values, int32 reorder_t, std::vector< Index > *indexes) |
Creates a vector of indexes with a regular structure, according to these specifications. More... | |
static void | SetSomeIndexesBlank (const std::vector< Index > &ref_indexes, std::vector< Index > *indexes) |
This function modifies 'indexes' by, for any Indexes which was not present in 'ref_indexes', setting the 't' value to kNoTime. More... | |
void | GetComputationIo (const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, ConvolutionComputationIo *io) |
This function takes lists of input and output indexes to a computation (e.g. More... | |
void | GetIndexesForComputation (const ConvolutionComputationIo &io, const std::vector< Index > &orig_input_indexes, const std::vector< Index > &orig_output_indexes, std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) |
This function computes the reordered and possibly padded indexes corresponding to the computation in 'io'. More... | |
void | MakeComputation (const ConvolutionModel &model, ConvolutionComputationIo &io, const ConvolutionComputationOptions &opts, ConvolutionComputation *computation) |
void AppendInputFrames | ( | const ConvolutionModel & | model, |
ConvolutionComputationIo * | io, | ||
ConvolutionModel * | model_appended, | ||
ConvolutionComputationIo * | io_appended | ||
) |
This function takes an input model and I/O specification, and it modifies both of them if necessary to ensure that the output 'io_appended' object has the same input and output time strides (i.e.
t_stride_in == t_stride_out). This is done by appending the input frames across several time values and viewing them as single frames of larger dimension.
The reason why 'io' is non-const is that it may be necessary to pad the number of input frames to ensure that the number of input frames is divisible by a multiple of t_stride_out / t_stride_in (if we pad the input frames, we pad to the right).
The model in 'model_appended' may have larger height_in, and different values of 'offsets' and derived variables thereof, versus the model in 'model'.
This is stage 3 of compilation.
Definition at line 1203 of file convolution.cc.
References ConvolutionModel::all_time_offsets, ConvolutionModel::Check(), ConvolutionModel::ComputeDerived(), ConvolutionModel::height_in, ConvolutionModel::Offset::height_offset, ConvolutionModel::height_out, ConvolutionModel::height_subsample_out, rnnlm::i, KALDI_ASSERT, ConvolutionModel::num_filters_in, ConvolutionModel::num_filters_out, ConvolutionModel::offsets, PrepareIoForAppending(), ConvolutionModel::required_time_offsets, RoundDownToMultipleOf(), ShiftAllTimeOffsets(), ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputationIo::t_step_in, ConvolutionComputationIo::t_step_out, and ConvolutionModel::Offset::time_offset.
Referenced by CompileConvolutionComputation().
void CheckModelAndIo | ( | const ConvolutionModel & | model, |
const ConvolutionComputationIo & | io, | ||
bool | allow_extra_input = false |
||
) |
Check that this model and this I/O request are compatible in terms of required context, etc, and crash if not.
if allow_extra_input == false, this will crash if the input 'io' object has time values that would never be used because they are before/after the first/last desired time values.
Definition at line 1329 of file convolution.cc.
References ConvolutionModel::all_time_offsets, KALDI_ASSERT, KALDI_ERR, rnnlm::n, ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::num_t_out, kaldi::RandInt(), ConvolutionModel::required_time_offsets, ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputationIo::t_step_in, ConvolutionComputationIo::t_step_out, and TimeValueInInput().
Referenced by CompileConvolutionComputation().
void CompileConvolutionComputation | ( | const ConvolutionModel & | model, |
const std::vector< Index > & | input_indexes, | ||
const std::vector< Index > & | output_indexes, | ||
const ConvolutionComputationOptions & | opts, | ||
ConvolutionComputation * | computation, | ||
std::vector< Index > * | input_indexes_modified, | ||
std::vector< Index > * | output_indexes_modified | ||
) |
This function does the compilation for a convolution computation; it's a wrapper for the functions below, which should not have to be called by the end user.
[in] | model | The convolution model that this computation is for. |
[in] | input_indexes | The list of Indexes available at the input of the computation. |
[in] | output_indexes | The list of Indexes requested to be computed at the output of the computation. It is an error if all dependencies are not satisfied (specifically: for each Index (n,t,x) in 'output_indexes', the Index (n,t+time_offset,x) must be present in 'input_indexes' for each time_offset in model.required_time_offsets. |
[out] | computation | If non-NULL, the compiled computation will be written to this location. |
Definition at line 1367 of file convolution.cc.
References AppendInputFrames(), CheckModelAndIo(), GetComputationIo(), GetIndexesForComputation(), MakeComputation(), PadComputationInputTime(), PadModelHeight(), and UnPadModelHeight().
Referenced by TimeHeightConvolutionComponent::PrecomputeIndexes(), TimeHeightConvolutionComponent::ReorderIndexes(), and UnitTestTimeHeightConvolutionCompile().
|
static |
This function sets 'temp_rows' and 'temp_cols' in 'computation'.
Definition at line 956 of file convolution.cc.
References ConvolutionComputation::height_in, ConvolutionComputation::ConvolutionStep::height_map, rnnlm::i, KALDI_WARN, ConvolutionComputationOptions::max_memory_mb, ConvolutionComputation::num_filters_in, ConvolutionComputation::num_images, ConvolutionComputation::num_t_out, ConvolutionComputation::steps, ConvolutionComputation::temp_cols, ConvolutionComputation::temp_rows, and VectorIsContiguous().
Referenced by MakeComputation(), and UnPadModelHeight().
void ConvolveBackwardData | ( | const ConvolutionComputation & | conv_comp, |
const CuMatrixBase< BaseFloat > & | params, | ||
const CuMatrixBase< BaseFloat > & | output_deriv, | ||
CuMatrixBase< BaseFloat > * | input_deriv | ||
) |
This does the part of the backward derivative computation of convolution, that propagates derivatives back to the input data.
See also ConvolveBackwardParams(), which is for the parameter derivative.
[in] | conv_comp | A struct that describes the convolution computation (should be the same as in the corresponding forward pass). |
[in] | params | The parameters used in the forward convolution. This should be of dimension num_filters_out by (X * num_filters_in), where X is the total number of pixels in the patches, which equals model.offsets.size() in the model for which the computation was compiled. E.g. for a regular 3x3 kernel, X would be 9. |
[in] | output_deriv | The derivative of the objective function w.r.t. the output of the convolution. Should be of dimension conv_comp.num_t_out * conv_comp.num_images by conv_comp.height_out num_filters_out. It must satisfy output_deriv.NumCols() == output_deriv.Stride(). |
[out] | input_deriv | If non-NULL, the backpropagated derivative of the objective function w.r.t. the input will be *added to* this matrix. Should be the same dimension as the input to the original ConvolveForward() call. |
Definition at line 682 of file convolution.cc.
References ConvolveBackwardDataInternal(), CuMatrixBase< Real >::Data(), ConvolutionComputation::height_in, ConvolutionComputation::height_out, KALDI_ASSERT, KALDI_ERR, kaldi::kSetZero, kaldi::kStrideEqualNumCols, ConvolutionComputation::num_filters_in, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, ConvolutionComputation::num_t_in, ConvolutionComputation::num_t_out, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Stride(), ConvolutionComputation::temp_cols, and ConvolutionComputation::temp_rows.
Referenced by TimeHeightConvolutionComponent::Backprop(), and TestDataBackprop().
|
static |
Definition at line 603 of file convolution.cc.
References CuMatrixBase< Real >::AddMatMat(), ConvolutionComputation::ConvolutionStep::backward_columns, ConvolutionComputation::ConvolutionStep::columns, ConvolutionComputation::ConvolutionStep::columns_are_contiguous, CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), ConvolutionComputation::ConvolutionStep::first_column, ConvolutionComputation::height_out, rnnlm::i, ConvolutionComputation::ConvolutionStep::input_time_shift, KALDI_ASSERT, kaldi::kNoTrans, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), ConvolutionComputation::ConvolutionStep::params_start_col, ConvolutionComputation::steps, and CuMatrixBase< Real >::Stride().
Referenced by ConvolveBackwardData().
void ConvolveBackwardParams | ( | const ConvolutionComputation & | conv_comp, |
const CuMatrixBase< BaseFloat > & | input, | ||
const CuMatrixBase< BaseFloat > & | output_deriv, | ||
BaseFloat | alpha, | ||
CuMatrixBase< BaseFloat > * | params_deriv | ||
) |
This does the part of the backward derivative computation of convolution, that computes derivatives w.r.t.
the parameters. See also ConvolveBackwardData(), which computes derivatives w.r.t. the input data.
[in] | conv_comp | A struct that describes the computation that was performed in the forward pass. |
[in] | input | The input to the original forward convolution. This should be of dimension (or should be reshapable to the dimension) conv_comp.num_t_in * conv_comp.num_images by conv_comp.height_in * num_filters_in. [highest-stride indexes come first in these multiplications]. It must satisfy input.NumCols() == input.Stride(). |
[in] | output_deriv | The derivative of the objective function w.r.t. the output of the convolution. Should be of dimension conv_comp.num_t_out * conv_comp.num_images by conv_comp.height_out num_filters_out. It must satisfy output_deriv.NumCols() == output_deriv.Stride(). |
[in] | alpha | This scalar is multiplied into the derivative when we add to params_deriv, i.e. *params_deriv += alpha * derivative. |
[out] | params_deriv | The derivative of the objective function w.r.t the parameters (the 'params' given to the ConvolveForward function) is *added* to this location. This matrix should be of dimension conv_comp.NumRows() by conv_comp.NumCols(). |
Definition at line 840 of file convolution.cc.
References ConvolveBackwardParamsInternal(), CuMatrixBase< Real >::Data(), ConvolutionComputation::height_in, ConvolutionComputation::height_out, KALDI_ASSERT, KALDI_ERR, kaldi::kStrideEqualNumCols, kaldi::kUndefined, ConvolutionComputation::num_filters_in, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, ConvolutionComputation::num_t_in, ConvolutionComputation::num_t_out, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Stride(), ConvolutionComputation::temp_cols, and ConvolutionComputation::temp_rows.
Referenced by TestParamsBackprop(), TimeHeightConvolutionComponent::UpdateNaturalGradient(), and TimeHeightConvolutionComponent::UpdateSimple().
|
static |
Definition at line 763 of file convolution.cc.
References CuMatrixBase< Real >::AddMatMat(), ConvolutionComputation::ConvolutionStep::columns, ConvolutionComputation::ConvolutionStep::columns_are_contiguous, CuMatrixBase< Real >::CopyCols(), CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), ConvolutionComputation::ConvolutionStep::first_column, ConvolutionComputation::height_out, ConvolutionComputation::ConvolutionStep::input_time_shift, KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), ConvolutionComputation::ConvolutionStep::params_start_col, ConvolutionComputation::steps, and CuMatrixBase< Real >::Stride().
Referenced by ConvolveBackwardParams().
void ConvolveForward | ( | const ConvolutionComputation & | conv_comp, |
const CuMatrixBase< BaseFloat > & | input, | ||
const CuMatrixBase< BaseFloat > & | params, | ||
CuMatrixBase< BaseFloat > * | output | ||
) |
This does the forward computation of convolution.
(note: this is convolution without a bias term; you have to handle that separately).
[in] | conv_comp | A struct that describes the computation to be performed. |
[in] | input | The input to the convolution. This should be of dimension (or should be reshapable to the dimension) conv_comp.num_t_in * conv_comp.num_images by conv_comp.height_in * num_filters_in. [highest-stride indexes come first in these multiplications]. It must satisfy input.NumCols() == input.Stride(). |
[in] | params | The parameters of the convolution. This should be of dimension conv_comp.ParamRows() by conv_comp.ParamCols(). |
[out] | output | The output of the convolution (this function adds to* the output). Should be of dimension conv_comp.num_t_out * conv_comp.num_images by conv_comp.height_out * num_filters_out. It must satisfy output.NumCols() == output.Stride(). |
Definition at line 524 of file convolution.cc.
References ConvolveForwardInternal(), CuMatrixBase< Real >::Data(), ConvolutionComputation::height_in, ConvolutionComputation::height_out, KALDI_ASSERT, KALDI_ERR, kaldi::kStrideEqualNumCols, kaldi::kUndefined, ConvolutionComputation::num_filters_in, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, ConvolutionComputation::num_t_in, ConvolutionComputation::num_t_out, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Stride(), ConvolutionComputation::temp_cols, and ConvolutionComputation::temp_rows.
Referenced by TimeHeightConvolutionComponent::Propagate(), TestDataBackprop(), TestParamsBackprop(), and TestRunningComputation().
|
static |
Definition at line 448 of file convolution.cc.
References CuMatrixBase< Real >::AddMatMat(), ConvolutionComputation::ConvolutionStep::columns, ConvolutionComputation::ConvolutionStep::columns_are_contiguous, CuMatrixBase< Real >::CopyCols(), CuMatrixBase< Real >::Data(), CuArrayBase< T >::Dim(), ConvolutionComputation::ConvolutionStep::first_column, ConvolutionComputation::height_out, ConvolutionComputation::ConvolutionStep::input_time_shift, KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), ConvolutionComputation::ConvolutionStep::params_start_col, ConvolutionComputation::steps, and CuMatrixBase< Real >::Stride().
Referenced by ConvolveForward().
void kaldi::nnet3::time_height_convolution::ConvolveForwardSimple | ( | const ConvolutionModel & | model, |
const std::vector< Index > & | input_indexes, | ||
const std::vector< Index > & | output_indexes, | ||
const CuMatrixBase< BaseFloat > & | input_cu, | ||
const CuMatrixBase< BaseFloat > & | params_cu, | ||
CuMatrixBase< BaseFloat > * | output_cu | ||
) |
Definition at line 218 of file convolution-test.cc.
References CuMatrixBase< Real >::CopyFromMat(), ConvolutionModel::height_in, ConvolutionModel::height_out, ConvolutionModel::height_subsample_out, kaldi::nnet3::kNoTime, kaldi::kNoTrans, ConvolutionModel::num_filters_in, ConvolutionModel::num_filters_out, MatrixBase< Real >::NumRows(), ConvolutionModel::offsets, and Index::t.
Referenced by TestRunningComputation().
|
static |
Creates a vector of indexes with a regular structure, according to these specifications.
'n_x_pairs' is the list of (n,x) pairs to include; they will appear in this order.
't_start', 't_step' and 'num_t_values' define the set of 't' values to include (note: t_step >= 0; they will appear in the natural order).
If reorder_t == 1 (the normal case), then the order is simple: 't' has the higher stride, then (n, x). So we'll output first all (n, x) pairs for t_start, then all pairs for t_start + t_step, and so on.
If instead reorder_t > 1, then the order is a little different [note: we expect that num_t_values % reorder_t == 0). Consider, for example, reorder_t == 2. In that case the first block has the first two t values, the second block has the next two t values, and so on. And within each block, the 't' values have the smallest stride (of 1).
Definition at line 1470 of file convolution.cc.
References KALDI_ASSERT, and Index::n.
Referenced by GetIndexesForComputation(), and BlockFactorizedTdnnComponent::NumOutputBlocks().
|
static |
Definition at line 1420 of file convolution.cc.
References kaldi::Gcd(), and rnnlm::i.
Referenced by RegularizeTList().
void GetComputationIo | ( | const std::vector< Index > & | input_indexes, |
const std::vector< Index > & | output_indexes, | ||
ConvolutionComputationIo * | io | ||
) |
This function takes lists of input and output indexes to a computation (e.g.
as supplied to ReorderIndexes()), and figures out a regular structure for them (i.e. the smallest grid that will completely cover all the t,n pairs). This function ignores any 't' values that are kNoTime.
Definition at line 1519 of file convolution.cc.
References kaldi::nnet3::GetNxList(), kaldi::nnet3::GetTList(), kaldi::GetVerboseLevel(), KALDI_ASSERT, ConvolutionComputationIo::num_images, ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::num_t_out, RegularizeTList(), ConvolutionComputationIo::reorder_t_in, ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputationIo::t_step_in, and ConvolutionComputationIo::t_step_out.
Referenced by CompileConvolutionComputation(), RestrictedAttentionComponent::GetComputationStructure(), TdnnComponent::PrecomputeIndexes(), and TdnnComponent::ReorderIndexes().
void GetIndexesForComputation | ( | const ConvolutionComputationIo & | io, |
const std::vector< Index > & | orig_input_indexes, | ||
const std::vector< Index > & | orig_output_indexes, | ||
std::vector< Index > * | input_indexes, | ||
std::vector< Index > * | output_indexes | ||
) |
This function computes the reordered and possibly padded indexes corresponding to the computation in 'io'.
Note: the computation may have undergone various manipulations (padding, etc.) after being obtained by the function GetComputationIo(). The original input and output indexes are needed because they dictate the set of (n, x) pairs; and because they determine when to use 'real' indexes and when to use 'blank' padding values (i.e. when to replace the t values in the indexes by kNoTime).
Definition at line 1543 of file convolution.cc.
References CreateIndexes(), kaldi::nnet3::GetNxList(), KALDI_ASSERT, ConvolutionComputationIo::num_images, ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::num_t_out, ConvolutionComputationIo::reorder_t_in, SetSomeIndexesBlank(), ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputationIo::t_step_in, and ConvolutionComputationIo::t_step_out.
Referenced by CompileConvolutionComputation(), TdnnComponent::PrecomputeIndexes(), and TdnnComponent::ReorderIndexes().
|
static |
Definition at line 78 of file convolution-test.cc.
References ConvolutionModel::all_time_offsets, ConvolutionModel::Check(), rnnlm::i, kaldi::IsSortedAndUniq(), rnnlm::j, KALDI_ASSERT, Index::n, rnnlm::n, kaldi::RandInt(), ConvolutionModel::required_time_offsets, kaldi::SortAndUniq(), Index::t, and Index::x.
Referenced by UnitTestTimeHeightConvolutionCompile().
|
static |
Definition at line 28 of file convolution-test.cc.
References ConvolutionModel::Check(), ConvolutionModel::ComputeDerived(), ConvolutionModel::height_in, ConvolutionModel::Offset::height_offset, ConvolutionModel::height_out, ConvolutionModel::height_subsample_out, rnnlm::i, ConvolutionModel::Info(), KALDI_WARN, ConvolutionModel::num_filters_in, ConvolutionModel::num_filters_out, ConvolutionModel::offsets, kaldi::RandInt(), ConvolutionModel::required_time_offsets, kaldi::SortAndUniq(), and ConvolutionModel::Offset::time_offset.
Referenced by UnitTestTimeHeightConvolutionCompile(), and UnitTestTimeHeightConvolutionIo().
void MakeComputation | ( | const ConvolutionModel & | model, |
ConvolutionComputationIo & | io, | ||
const ConvolutionComputationOptions & | opts, | ||
ConvolutionComputation * | computation | ||
) |
Definition at line 1568 of file convolution.cc.
References ComputeTempMatrixSize(), ConvolutionModel::height_in, ConvolutionComputation::height_in, ConvolutionComputation::ConvolutionStep::height_map, ConvolutionModel::height_out, ConvolutionComputation::height_out, ConvolutionModel::height_subsample_out, ConvolutionComputation::ConvolutionStep::input_time_shift, kaldi::IsSortedAndUniq(), KALDI_ASSERT, ConvolutionModel::num_filters_in, ConvolutionComputation::num_filters_in, ConvolutionModel::num_filters_out, ConvolutionComputation::num_filters_out, ConvolutionComputation::num_images, ConvolutionComputationIo::num_images, ConvolutionComputation::num_t_in, ConvolutionComputationIo::num_t_in, ConvolutionComputation::num_t_out, ConvolutionComputationIo::num_t_out, ConvolutionModel::offsets, ConvolutionComputation::ConvolutionStep::params_start_col, ConvolutionComputationIo::reorder_t_in, ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputation::steps, ConvolutionComputationIo::t_step_in, and ConvolutionComputationIo::t_step_out.
Referenced by CompileConvolutionComputation().
void PadComputationInputTime | ( | const ConvolutionModel & | model, |
ConvolutionComputationIo * | io | ||
) |
This function extends the set of input indexes that the computation has, to account for any required zero-padding in the time dimension.
It reads model.all_time_offsets and model.time_offsets_modulus; and it may modify members start_t_in t_stride_in and num_t_in of *io.
This is stage 1 of compilation.
Definition at line 1051 of file convolution.cc.
References ConvolutionModel::all_time_offsets, kaldi::Gcd(), KALDI_ASSERT, ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::num_t_out, ConvolutionComputationIo::start_t_in, ConvolutionComputationIo::start_t_out, ConvolutionComputationIo::t_step_in, ConvolutionComputationIo::t_step_out, and ConvolutionModel::time_offsets_modulus.
Referenced by CompileConvolutionComputation().
void PadModelHeight | ( | const ConvolutionModel & | model, |
ConvolutionModel * | model_padded | ||
) |
This function takes a model that might require zero padding in the height dimension and outputs a model accepting a possibly-larger input dimension which does not require zero padding.
*model_padded may differ from 'model' in its height_in and its 'offsets' variable (the height-offsets need to be shifted if we pad at the bottom). We then work out the computation in terms of the model that doesn't need padding (which is easier), and later convert it back to work in the space where there is no padding.
This is stage 2 of compilation.
Definition at line 918 of file convolution.cc.
References ConvolutionModel::Check(), ConvolutionModel::height_in, ConvolutionModel::height_out, ConvolutionModel::height_subsample_out, rnnlm::i, KALDI_ASSERT, and ConvolutionModel::offsets.
Referenced by CompileConvolutionComputation().
|
static |
Definition at line 1158 of file convolution.cc.
References KALDI_ASSERT, ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::num_t_out, ConvolutionComputationIo::reorder_t_in, ConvolutionComputationIo::t_step_in, and ConvolutionComputationIo::t_step_out.
Referenced by AppendInputFrames().
|
static |
Definition at line 1431 of file convolution.cc.
References FindGcdOfDifferences(), kaldi::IsSortedAndUniq(), and KALDI_ASSERT.
Referenced by GetComputationIo().
|
static |
This function, used in ConvolutionComputation::ComputeDerived(), reverses a mapping that may not be unique.
'columns' is a column mapping where each member is either -1 (meaning, copy a zero), or a number between 0 and input_dim - 1.
Its output, 'backward_columns', is the reverse mapping, but it's a vector of vectors instead of just a vector because the mapping may have been many-to-one. Each element of 'backward_columns' will be of dimension input_dim. For each columns[i] = j such that j != -1, for some k we will have (*backward_columns)[k][j] = i.
Definition at line 44 of file convolution.cc.
References rnnlm::i, rnnlm::j, and KALDI_ASSERT.
Referenced by ConvolutionComputation::ComputeDerived().
|
static |
Definition at line 1103 of file convolution.cc.
References kaldi::DivideRoundingDown().
Referenced by AppendInputFrames().
|
static |
This function modifies 'indexes' by, for any Indexes which was not present in 'ref_indexes', setting the 't' value to kNoTime.
This will cause the nnet3 framework to ignore such Indexes for certain purposes, it supresses certain error conditions that would otherwise happen from inserting unnecessary indexes into the input and output.
Definition at line 1505 of file convolution.cc.
References kaldi::nnet3::kNoTime.
Referenced by GetIndexesForComputation().
|
static |
Definition at line 1110 of file convolution.cc.
References ConvolutionModel::all_time_offsets, ConvolutionModel::offsets, and ConvolutionModel::required_time_offsets.
Referenced by AppendInputFrames().
void kaldi::nnet3::time_height_convolution::TestComputationIo | ( | const ConvolutionComputation & | computation | ) |
Definition at line 182 of file convolution-test.cc.
References KALDI_ASSERT, kaldi::RandInt(), ConvolutionComputation::Read(), and ConvolutionComputation::Write().
Referenced by UnitTestTimeHeightConvolutionCompile().
void kaldi::nnet3::time_height_convolution::TestDataBackprop | ( | const ConvolutionModel & | conv_model, |
const std::vector< Index > & | input_indexes, | ||
const std::vector< Index > & | output_indexes, | ||
const ConvolutionComputation & | computation | ||
) |
Definition at line 308 of file convolution-test.cc.
References kaldi::ApproxEqual(), ConvolveBackwardData(), ConvolveForward(), ConvolutionModel::InputDim(), KALDI_ERR, KALDI_LOG, kaldi::kSetZero, kaldi::kStrideEqualNumCols, kaldi::kTrans, ConvolutionModel::OutputDim(), ConvolutionModel::ParamCols(), ConvolutionModel::ParamRows(), CuMatrixBase< Real >::SetRandn(), kaldi::TraceMatMat(), and ZeroBlankRows().
Referenced by UnitTestTimeHeightConvolutionCompile().
void kaldi::nnet3::time_height_convolution::TestParamsBackprop | ( | const ConvolutionModel & | conv_model, |
const std::vector< Index > & | input_indexes, | ||
const std::vector< Index > & | output_indexes, | ||
const ConvolutionComputation & | computation | ||
) |
Definition at line 350 of file convolution-test.cc.
References kaldi::ApproxEqual(), ConvolveBackwardParams(), ConvolveForward(), ConvolutionModel::InputDim(), KALDI_ERR, KALDI_LOG, kaldi::kSetZero, kaldi::kStrideEqualNumCols, kaldi::kTrans, ConvolutionModel::OutputDim(), ConvolutionModel::ParamCols(), ConvolutionModel::ParamRows(), kaldi::RandInt(), CuMatrixBase< Real >::SetRandn(), kaldi::TraceMatMat(), and ZeroBlankRows().
Referenced by UnitTestTimeHeightConvolutionCompile().
void kaldi::nnet3::time_height_convolution::TestRunningComputation | ( | const ConvolutionModel & | conv_model, |
const std::vector< Index > & | input_indexes, | ||
const std::vector< Index > & | output_indexes, | ||
const ConvolutionComputation & | computation | ||
) |
Definition at line 280 of file convolution-test.cc.
References ConvolveForward(), ConvolveForwardSimple(), ConvolutionModel::Info(), ConvolutionModel::InputDim(), KALDI_ERR, KALDI_LOG, kaldi::kSetZero, kaldi::kStrideEqualNumCols, ConvolutionModel::OutputDim(), ConvolutionModel::ParamCols(), ConvolutionModel::ParamRows(), CuMatrixBase< Real >::SetRandn(), and ZeroBlankRows().
Referenced by UnitTestTimeHeightConvolutionCompile().
|
static |
Definition at line 1321 of file convolution.cc.
References ConvolutionComputationIo::num_t_in, ConvolutionComputationIo::start_t_in, and ConvolutionComputationIo::t_step_in.
Referenced by CheckModelAndIo().
void kaldi::nnet3::time_height_convolution::UnitTestTimeHeightConvolution | ( | ) |
Definition at line 437 of file convolution-test.cc.
References UnitTestTimeHeightConvolutionCompile(), and UnitTestTimeHeightConvolutionIo().
Referenced by main().
void kaldi::nnet3::time_height_convolution::UnitTestTimeHeightConvolutionCompile | ( | ) |
Definition at line 394 of file convolution-test.cc.
References CompileConvolutionComputation(), GetRandomConvolutionIndexes(), GetRandomConvolutionModel(), rnnlm::i, KALDI_LOG, TestComputationIo(), TestDataBackprop(), TestParamsBackprop(), TestRunningComputation(), and kaldi::nnet3::WriteIndexVector().
Referenced by UnitTestTimeHeightConvolution().
void kaldi::nnet3::time_height_convolution::UnitTestTimeHeightConvolutionIo | ( | ) |
Definition at line 165 of file convolution-test.cc.
References GetRandomConvolutionModel(), rnnlm::i, KALDI_ASSERT, KALDI_LOG, kaldi::RandInt(), ConvolutionModel::Read(), and ConvolutionModel::Write().
Referenced by UnitTestTimeHeightConvolution().
void UnPadModelHeight | ( | const ConvolutionComputationOptions & | opts, |
const ConvolutionModel & | model, | ||
const ConvolutionModel & | model_padded, | ||
ConvolutionComputation * | computation | ||
) |
This function modifies, if necessary, a computation that has been built for the model 'model_padded', so that it can work for the original model 'model'.
This may involve modifying the members 'height_in', 'temp_cols', and the column-related members of the elements of the 'steps' array. View it as the reverse step for 'PadModelHeight'.
This function has to be aware that the computation will have been compiled after 'AppendInputFrames()' was called [this makes a difference in setups with subsampling], so the computation may have been built for input frames that were appended over several of the frames that 'model_padded' would require.
This is the reverse step for stage 2 of compilation (it's a transformation of the computation).
Definition at line 1001 of file convolution.cc.
References ConvolutionComputation::Check(), ConvolutionComputation::ComputeDerived(), ComputeTempMatrixSize(), ConvolutionModel::height_in, ConvolutionComputation::height_in, ConvolutionComputation::ConvolutionStep::height_map, ConvolutionModel::height_out, ConvolutionComputation::height_out, rnnlm::i, KALDI_ASSERT, ConvolutionModel::offsets, and ConvolutionComputation::steps.
Referenced by CompileConvolutionComputation().
|
static |
Definition at line 77 of file convolution.cc.
References rnnlm::i, and KALDI_ASSERT.
Referenced by ConvolutionComputation::ComputeDerived(), and ComputeTempMatrixSize().
void kaldi::nnet3::time_height_convolution::ZeroBlankRows | ( | const std::vector< Index > & | indexes, |
CuMatrix< BaseFloat > * | matrix | ||
) |
Definition at line 198 of file convolution-test.cc.
References VectorBase< Real >::Data(), KALDI_ASSERT, kaldi::nnet3::kNoTime, kaldi::kUndefined, CuMatrixBase< Real >::MulRowsVec(), CuMatrixBase< Real >::NumRows(), VectorBase< Real >::Set(), and CuVector< Real >::Swap().
Referenced by TestDataBackprop(), TestParamsBackprop(), and TestRunningComputation().