Skip to content

Commit 0a1f827

Browse files
kkm000danpovey
authored andcommitted
[src] Log nnet3 computation to VLOG, not std::cout (#3072)
1 parent 17b7f3f commit 0a1f827

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/nnet3/decodable-simple-looped.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ DecodableNnetSimpleLoopedInfo::DecodableNnetSimpleLoopedInfo(
5252
Init(opts, &(am_nnet->GetNnet()));
5353
}
5454

55-
5655
void DecodableNnetSimpleLoopedInfo::Init(
5756
const NnetSimpleLoopedComputationOptions &opts,
5857
Nnet *nnet) {
@@ -86,10 +85,8 @@ void DecodableNnetSimpleLoopedInfo::Init(
8685
CompileLooped(*nnet, opts.optimize_config, request1, request2, request3,
8786
&computation);
8887
computation.ComputeCudaIndexes();
89-
if (GetVerboseLevel() >= 3) {
90-
KALDI_VLOG(3) << "Computation is:";
91-
computation.Print(std::cerr, *nnet);
92-
}
88+
KALDI_VLOG(3) << "Computation is:\n"
89+
<< NnetComputationPrintInserter{computation, *nnet};
9390
}
9491

9592

src/nnet3/nnet-computation.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,22 @@ struct NnetComputation {
514514
NnetComputation(): need_model_derivative(false) { }
515515
};
516516

517-
518-
519-
520-
// This operator is to print out the NnetComputation in a human-readable way, for
521-
// debugging purposes.
522-
// We don't give Read and Write functions to struct NnetComputation, because we
523-
// don't anticipate needing to write it to disk.
524-
std::ostream &operator << (std::ostream &os,
525-
NnetComputation &computation);
526-
527-
517+
// A helper class equipped with the stream insertion operator<< to print out
518+
// the NnetComputation in a human-readable way, with NnetComputation::Print(),
519+
// for debugging purposes, e.g.:
520+
// KALDI_VLOG(3) << NnetComputationPrintInserter{mycomputation, mynet};
521+
struct NnetComputationPrintInserter {
522+
const NnetComputation& computation;
523+
const Nnet& nnet;
524+
void Print(std::ostream& os) const {
525+
computation.Print(os, nnet);
526+
}
527+
friend inline std::ostream &operator <<(std::ostream &os,
528+
NnetComputationPrintInserter xhis) {
529+
xhis.Print(os);
530+
return os;
531+
}
532+
};
528533

529534
} // namespace nnet3
530535
} // namespace kaldi

0 commit comments

Comments
 (0)