Skip to content

[src] Log nnet3 computation to VLOG, not std::cout #3072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/nnet3/decodable-simple-looped.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ DecodableNnetSimpleLoopedInfo::DecodableNnetSimpleLoopedInfo(
Init(opts, &(am_nnet->GetNnet()));
}


void DecodableNnetSimpleLoopedInfo::Init(
const NnetSimpleLoopedComputationOptions &opts,
Nnet *nnet) {
Expand Down Expand Up @@ -86,10 +85,8 @@ void DecodableNnetSimpleLoopedInfo::Init(
CompileLooped(*nnet, opts.optimize_config, request1, request2, request3,
&computation);
computation.ComputeCudaIndexes();
if (GetVerboseLevel() >= 3) {
KALDI_VLOG(3) << "Computation is:";
computation.Print(std::cerr, *nnet);
}
KALDI_VLOG(3) << "Computation is:\n"
<< NnetComputationPrintInserter{computation, *nnet};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason I did this to cerr directly rather than to a temporary string is that it is in danger of exhausting memory otherwise, it's very verbose. I believe these macros use temporary strings and store the string somewhere... I don't think this PR is a good idea, for that reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked--about 45K characters, which is pretty much nothing. Actually, this is a cherry-picked changeset that has been in production here since January, 21 last year, if I'm to trust my Git. And we valgrind it thoroughly.

The string is deleted when the MessageLogger goes out of scope, as soon as this line ends executing; it's a constructed temporary without a name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did actually declare the operator<< (without a definition), but printing requires both the computation and the nnet, so requires an inserter. It really looked like something left to implement later. So I just caught up where you left it : )

}


Expand Down
27 changes: 16 additions & 11 deletions src/nnet3/nnet-computation.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,22 @@ struct NnetComputation {
NnetComputation(): need_model_derivative(false) { }
};




// This operator is to print out the NnetComputation in a human-readable way, for
// debugging purposes.
// We don't give Read and Write functions to struct NnetComputation, because we
// don't anticipate needing to write it to disk.
std::ostream &operator << (std::ostream &os,
NnetComputation &computation);


// A helper class equipped with the stream insertion operator<< to print out
// the NnetComputation in a human-readable way, with NnetComputation::Print(),
// for debugging purposes, e.g.:
// KALDI_VLOG(3) << NnetComputationPrintInserter{mycomputation, mynet};
struct NnetComputationPrintInserter {
const NnetComputation& computation;
const Nnet& nnet;
void Print(std::ostream& os) const {
computation.Print(os, nnet);
}
friend inline std::ostream &operator <<(std::ostream &os,
NnetComputationPrintInserter xhis) {
xhis.Print(os);
return os;
}
};

} // namespace nnet3
} // namespace kaldi
Expand Down