The first step in compilation is to turn the ComputationSpecification into a ComputationGraph, where for each Cindex we have a list of other Cindexes that it depends on. More...
#include <nnet-computation-graph.h>
Public Member Functions | |
int32 | GetCindexId (const Cindex &cindex, bool is_input, bool *is_new) |
Maps a Cindex to an integer cindex_id. More... | |
int32 | GetCindexId (const Cindex &cindex) const |
Const version of GetCindexId that does not add CindexIds. More... | |
void | Renumber (int32 start_cindex_id, const std::vector< bool > &keep) |
This function renumbers the cindex-ids (but only those with index c >= start_cindex_id,. More... | |
void | Print (std::ostream &os, const std::vector< std::string > &node_names) |
This function, useful for debugging/visualization purposes, prints out a summary of the computation graph (which will take up multiple lines). More... | |
Public Attributes | |
std::vector< Cindex > | cindexes |
The mapping of cindex_id to Cindex. More... | |
std::vector< bool > | is_input |
For each Cindex this tells us whether it was provided as an input to the network. More... | |
std::vector< std::vector< int32 > > | dependencies |
dependencies[cindex_id] gives you the list of other cindex_ids that this particular cindex_id directly depends on to compute it. More... | |
std::vector< int32 > | segment_ends |
This variable is only of particular interest in a 'multi-segment' computation, which is used while creating computations for 'online' operation (for the kind of situation where you provide some input; run the computation; get some output, provide some more input for larger 't' values, etc.). More... | |
Private Attributes | |
unordered_map< Cindex, int32, CindexHasher > | cindex_to_cindex_id_ |
Maps each Cindex to an integer cindex_id: reverse mapping of "cindexes". More... | |
The first step in compilation is to turn the ComputationSpecification into a ComputationGraph, where for each Cindex we have a list of other Cindexes that it depends on.
All the stages of compilation use the ComputationGraph representation; they are mostly manipulations of it.
For efficiency, we give each Cindex its own integer identifier, called a "cindex_id". A cindex_id is only interpretable relative to a ComputationGraph; it's an index into the "cindexes" array of the ComputationGraph. The GetCindexId() functions perform the reverse mapping.
Definition at line 43 of file nnet-computation-graph.h.
Maps a Cindex to an integer cindex_id.
If not present, then add it (with the corresponding "is_input" flag set to the value "input") and set *is_new to true. If present, set is_new to false and return the existing cindex_id.
Definition at line 28 of file nnet-computation-graph.cc.
References ComputationGraph::cindex_to_cindex_id_, ComputationGraph::cindexes, ComputationGraph::dependencies, ComputationGraph::is_input, and KALDI_ASSERT.
Referenced by ComputationGraphBuilder::AddDependencies(), kaldi::nnet3::computation_graph::AddInputToGraph(), kaldi::nnet3::computation_graph::AddOutputToGraph(), ComputationStepsComputer::AddStep(), ComputationGraphBuilder::ComputeComputableInfo(), kaldi::nnet3::ComputeComputationGraph(), Compiler::ComputeInputLocationsList(), ComputationStepsComputer::ConvertToCindexIds(), ComputationGraphBuilder::GetComputableInfo(), CindexSet::operator()(), IndexSet::operator()(), ComputationGraph::Print(), and ComputationStepsComputer::ProcessInputOrOutputStep().
Const version of GetCindexId that does not add CindexIds.
It will return -1 if the Cindex is not present, and the user should check for this.
Definition at line 47 of file nnet-computation-graph.cc.
References ComputationGraph::cindex_to_cindex_id_.
void Print | ( | std::ostream & | os, |
const std::vector< std::string > & | node_names | ||
) |
This function, useful for debugging/visualization purposes, prints out a summary of the computation graph (which will take up multiple lines).
Format is: [ cindex1 -> dep-cindex1 dep-cindex2 ] [ cindex2 -> dep-cindex3 dep-cindex4 ] showing each Cindex and the Cindexes it depends on. cindexes from different network nodes are shown on different lines.
Definition at line 176 of file nnet-computation-graph.cc.
References ComputationGraph::cindexes, ComputationGraph::dependencies, ComputationGraph::GetCindexId(), rnnlm::i, ComputationGraph::is_input, rnnlm::j, and kaldi::nnet3::PrintCindex().
Referenced by kaldi::nnet3::EvaluateComputationRequest().
This function renumbers the cindex-ids (but only those with index c >= start_cindex_id,.
true. The "keep" array must be the same size as this->cindexes.size() - start_cindex_id.
Definition at line 57 of file nnet-computation-graph.cc.
References ComputationGraph::cindex_to_cindex_id_, ComputationGraph::cindexes, rnnlm::d, ComputationGraph::dependencies, ComputationGraph::is_input, rnnlm::j, KALDI_ASSERT, KALDI_ERR, and KALDI_PARANOID_ASSERT.
Referenced by ComputationGraphBuilder::Prune().
|
private |
Maps each Cindex to an integer cindex_id: reverse mapping of "cindexes".
Must be accessed via the GetCindexId() functions.
Definition at line 111 of file nnet-computation-graph.h.
Referenced by ComputationGraph::GetCindexId(), and ComputationGraph::Renumber().
std::vector<Cindex> cindexes |
The mapping of cindex_id to Cindex.
Definition at line 46 of file nnet-computation-graph.h.
Referenced by ComputationGraphBuilder::AddDependencies(), ComputationStepsComputer::AddStep(), ComputationGraphBuilder::Check(), ComputationStepsComputer::Check(), ComputationGraphBuilder::ComputationGraphBuilder(), ComputationStepsComputer::ComputationStepsComputer(), ComputationGraphBuilder::Compute(), ComputationGraphBuilder::ComputeComputableInfo(), kaldi::nnet3::ComputeComputationGraph(), kaldi::nnet3::ComputeComputationPhases(), kaldi::nnet3::computation_graph::ComputeDependenciesSubset(), Compiler::ComputeDerivNeeded(), kaldi::nnet3::computation_graph::ComputeEpochInfo(), ComputationGraphBuilder::ComputeRequiredArray(), Compiler::ComputeStepDependencies(), ComputationStepsComputer::ConvertToCindexes(), Compiler::CreateStepInfo(), ComputationGraph::GetCindexId(), ComputationGraphBuilder::GetComputableInfo(), ComputationGraph::Print(), ComputationStepsComputer::ProcessComponentStep(), ComputationGraphBuilder::Prune(), and ComputationGraph::Renumber().
std::vector<std::vector<int32> > dependencies |
dependencies[cindex_id] gives you the list of other cindex_ids that this particular cindex_id directly depends on to compute it.
No repeats will be present. Note, some of these dependencies may be optional dependencies; in early stages of compilation this will contain all "desired" inputs and later we will prune the dependencies to contain just those that are used (which will vary depending on availability).
Definition at line 63 of file nnet-computation-graph.h.
Referenced by ComputationGraphBuilder::AddDependencies(), ComputationGraphBuilder::Check(), kaldi::nnet3::ComputeComputationGraph(), kaldi::nnet3::computation_graph::ComputeDependenciesSubset(), ComputationGraphBuilder::ComputeRequiredArray(), Compiler::ComputeStepDependencies(), Compiler::CreateStepInfo(), ComputationGraphBuilder::DecrementUsableCount(), ComputationGraphBuilder::ExplainWhyNotComputable(), ComputationGraph::GetCindexId(), ComputationGraphBuilder::IncrementUsableCount(), ComputationGraph::Print(), ComputationStepsComputer::ProcessComponentStep(), ComputationGraphBuilder::PruneDependencies(), ComputationGraph::Renumber(), and ComputationGraphBuilder::UpdateComputableInfo().
std::vector<bool> is_input |
For each Cindex this tells us whether it was provided as an input to the network.
This is necessary for a couple of reasons: firstly, the framework allows users to provide values for nodes of type kComponent (e.g. for RNN context). Also, Cindexes for input nodes that were not provided by the user may be created during computation graph creation (although they will not be computable), and we need to distinguish these from the provided Cindexes.
Definition at line 55 of file nnet-computation-graph.h.
Referenced by ComputationGraphBuilder::AddInputs(), ComputationGraphBuilder::AddOutputs(), Compiler::AllocateMatrices(), ComputationGraphBuilder::ComputeComputableInfo(), kaldi::nnet3::ComputeComputationGraph(), Compiler::ComputeDerivNeeded(), kaldi::nnet3::computation_graph::ComputeEpochInfo(), ComputationGraph::GetCindexId(), ComputationGraph::Print(), ComputationGraphBuilder::Prune(), and ComputationGraph::Renumber().
std::vector<int32> segment_ends |
This variable is only of particular interest in a 'multi-segment' computation, which is used while creating computations for 'online' operation (for the kind of situation where you provide some input; run the computation; get some output, provide some more input for larger 't' values, etc.).
In this context, a 'segment' is a continuous range of cindex_ids, and a segment_end is one past the end of each segment, which is the same as the beginning of the next segment, if there is one. In the case of a fully-created computation graph with only one segment, this will contain just one value which equals the number of cindex_ids. This information is needed to correctly order the computation, because
the computation graph itself does not contain dependencies that encode the ordering of segments (and even if it did contain those dependencies, it's not really compatible with the way we use the scc's in the graph structure of the network to order the computation).
Definition at line 80 of file nnet-computation-graph.h.
Referenced by ComputationGraphBuilder::Compute(), kaldi::nnet3::ComputeComputationPhases(), kaldi::nnet3::computation_graph::ComputeEpochInfo(), and ComputationGraphBuilder::Prune().