This class is responsible for consolidating the model-update part of backprop commands, for components in (e.g.) recurrent networks that need to have many separate backprop commands, into more efficient single commands operating on consolidated data in larger matrices. More...
Public Member Functions | |
ModelUpdateConsolidator (const Nnet &nnet, NnetComputation *computation) | |
void | ConsolidateModelUpdate () |
Private Member Functions | |
void | ConsolidateUpdateForComponent (int32 component, const std::vector< int32 > &backprop_commands) |
This function, called from ConsolidateModelUpdate, is passed a list of commands that are all backprops for the same component, and it consolidates them into a single model-update command. More... | |
void | AddCommandsToComputation () |
This function, called at the end of ConsolidateModelUpdate(), takes the commands that we have put in extra_commands_, final_commands_ and final_deallocate_commands_, and puts them in the appropriate place in computation->commands_. More... | |
int32 | ConsolidateSubmatrices (const std::vector< int32 > &commands, const std::vector< int32 > &submatrices) |
You call this function when you want to consolidate the values of a list of submatrices taken just prior to particular commands. More... | |
void | AppendDebugInfoForSubmatrix (int32 submatrix_index, NnetComputation::MatrixDebugInfo *debug_info) const |
This function, called from ConsolidateSubmatrices, will update 'debug_info' by appending the corresponding 'indexes' from the existing debug info for this submatrix. More... | |
Private Attributes | |
const Nnet & | nnet_ |
NnetComputation * | computation_ |
std::vector< std::vector< NnetComputation::Command > > | extra_commands_ |
std::vector< NnetComputation::Command > | final_commands_ |
std::vector< NnetComputation::Command > | final_deallocate_commands_ |
This class is responsible for consolidating the model-update part of backprop commands, for components in (e.g.) recurrent networks that need to have many separate backprop commands, into more efficient single commands operating on consolidated data in larger matrices.
This is useful for recurrent networks.
Definition at line 1282 of file nnet-optimize-utils.cc.
ModelUpdateConsolidator | ( | const Nnet & | nnet, |
NnetComputation * | computation | ||
) |
Definition at line 1509 of file nnet-optimize-utils.cc.
|
private |
This function, called at the end of ConsolidateModelUpdate(), takes the commands that we have put in extra_commands_, final_commands_ and final_deallocate_commands_, and puts them in the appropriate place in computation->commands_.
Definition at line 1434 of file nnet-optimize-utils.cc.
References NnetComputation::commands, MatrixExtender::computation_, rnnlm::i, and KALDI_ASSERT.
Referenced by ModelUpdateConsolidator::ConsolidateModelUpdate().
|
private |
This function, called from ConsolidateSubmatrices, will update 'debug_info' by appending the corresponding 'indexes' from the existing debug info for this submatrix.
It will also set the 'is_deriv' of '*debug_info' to the same value as the debug info for 'submatrix_index', and set the 'node_index' to the 'node_index' in the debug info for that submatrix-index. It requires that computation_->matrix_debug_info be nonempty.
Definition at line 1347 of file nnet-optimize-utils.cc.
References NnetComputation::MatrixDebugInfo::cindexes, MatrixExtender::computation_, NnetComputation::MatrixDebugInfo::is_deriv, KALDI_ASSERT, NnetComputation::matrices, NnetComputation::matrix_debug_info, and NnetComputation::submatrices.
void ConsolidateModelUpdate | ( | ) |
Definition at line 1515 of file nnet-optimize-utils.cc.
References ModelUpdateConsolidator::AddCommandsToComputation(), NnetComputation::Command::arg1, NnetComputation::Command::command_type, NnetComputation::commands, ModelUpdateConsolidator::computation_, ModelUpdateConsolidator::ConsolidateUpdateForComponent(), Nnet::GetComponent(), kaldi::nnet3::kBackprop, kaldi::nnet3::kSimpleComponent, kaldi::nnet3::kUpdatableComponent, kaldi::nnet3::kUsesMemo, ModelUpdateConsolidator::nnet_, Nnet::NumComponents(), and Component::Properties().
Referenced by kaldi::nnet3::ConsolidateModelUpdate().
|
private |
You call this function when you want to consolidate the values of a list of submatrices taken just prior to particular commands.
The input 'commands' and 'submatrices' lists must be the same size, and size must be > 1. This function will create a new matrix that is the row-wise concatentation of all these submatrices, with values taken just prior to the respective command indexes. This function will will add to extra_commands_ the commands to do the copying at the appropriate places (at the supplied command indexes; they will be inserted just before). The return value is the submatrix index of a submatrix that represents the whole of the consolidated matrix. This command will insert, at the beginning of the computation (in extra_commands_[0]), a command to initialize the matrix; and will append to final_deallocate_commands_ the commands to deallocate the matrix. If computation_->matrix_debug_info is nonempty, this function will also update computation_->matrix_debug_info with suitable values for the newly added matrix
Definition at line 1371 of file nnet-optimize-utils.cc.
References MatrixExtender::computation_, rnnlm::i, NnetComputation::IsWholeMatrix(), KALDI_ASSERT, kaldi::nnet3::kAllocMatrix, kaldi::nnet3::kDeallocMatrix, kaldi::kDefaultStride, kaldi::nnet3::kMatrixCopy, kaldi::nnet3::kSetConst, kaldi::kStrideEqualNumCols, NnetComputation::matrices, NnetComputation::matrix_debug_info, NnetComputation::NewMatrix(), NnetComputation::NewSubMatrix(), and NnetComputation::submatrices.
|
private |
This function, called from ConsolidateModelUpdate, is passed a list of commands that are all backprops for the same component, and it consolidates them into a single model-update command.
Definition at line 1460 of file nnet-optimize-utils.cc.
References NnetComputation::Command::arg2, NnetComputation::Command::arg3, NnetComputation::Command::arg4, NnetComputation::Command::arg5, NnetComputation::Command::command_type, NnetComputation::commands, MatrixExtender::computation_, rnnlm::i, KALDI_ASSERT, kaldi::nnet3::kBackprop, kaldi::nnet3::kBackpropNeedsInput, kaldi::nnet3::kBackpropNeedsOutput, kaldi::nnet3::kBackpropNoModelUpdate, and Component::Properties().
Referenced by ModelUpdateConsolidator::ConsolidateModelUpdate().
|
private |
Definition at line 1329 of file nnet-optimize-utils.cc.
Referenced by ModelUpdateConsolidator::ConsolidateModelUpdate(), DerivativeTimeLimiter::GetPruneValues(), DerivativeTimeLimiter::MapAddRowRangesCommand(), DerivativeTimeLimiter::MapIndexesCommand(), DerivativeTimeLimiter::MapIndexesMultiCommand(), DerivativeTimeLimiter::MapSimpleMatrixCommand(), and DerivativeTimeLimiter::RowIsKept().
|
private |
Definition at line 1335 of file nnet-optimize-utils.cc.
|
private |
Definition at line 1340 of file nnet-optimize-utils.cc.
|
private |
Definition at line 1343 of file nnet-optimize-utils.cc.
|
private |
Definition at line 1328 of file nnet-optimize-utils.cc.
Referenced by ModelUpdateConsolidator::ConsolidateModelUpdate(), and DerivativeTimeLimiter::ModifyCommand().