35 bool binary = (
Rand() % 2 == 0);
36 std::ostringstream os;
37 computation->
Write(os, binary);
38 const std::string &original_output = os.str();
39 std::istringstream computation_is(original_output);
40 computation->
Read(computation_is, binary);
41 std::istringstream computation_is2(original_output);
43 computation2.
Read(computation_is2, binary);
45 std::ostringstream os2, os3;
46 computation->
Write(os2, binary);
47 computation2.
Write(os3, binary);
50 if (!(os2.str() == original_output)) {
51 KALDI_ERR <<
"Outputs differ for computation";
57 bool binary = (
Rand() % 2 == 0);
58 std::ostringstream os;
59 request->
Write(os, binary);
60 const std::string &original_output = os.str();
61 std::istringstream request_is(original_output);
62 request->
Read(request_is, binary);
63 std::istringstream request_is2(original_output);
65 request2.
Read(request_is2, binary);
67 std::ostringstream os2, os3;
68 request->
Write(os2, binary);
69 request2.
Write(os3, binary);
84 ivector_dim = std::max<int32>(0, nnet->
InputDim(
"ivector"));
95 if (priors.
Dim() != 0) {
101 output2(num_frames, output_dim);
108 (ivector_dim != 0 ? &ivector : NULL));
109 for (
int32 t = 0; t < num_frames; t++) {
120 (ivector_dim != 0 ? &ivector : NULL));
121 for (
int32 t = 0; t < num_frames; t++) {
132 nnet->
Info().find(
"statistics-extraction") == std::string::npos &&
133 nnet->
Info().find(
"TimeHeightConvolutionComponent") == std::string::npos &&
134 nnet->
Info().find(
"RestrictedAttentionComponent") == std::string::npos) {
139 for (
int32 t = 0; t < num_frames; t++) {
150 bool test_collapse_model = (
RandInt(0, 1) == 0);
152 std::vector<std::string> configs;
155 for (
size_t j = 0;
j < configs.size();
j++) {
156 KALDI_LOG <<
"Input config[" <<
j <<
"] is: " << configs[
j];
157 std::istringstream is(configs[
j]);
162 std::vector<Matrix<BaseFloat> > inputs;
168 if (test_collapse_model) {
180 Nnet nnet_collapsed(nnet);
184 if (test_collapse_model) {
186 Compiler compiler_collapsed(request, nnet_collapsed);
193 std::ostringstream os;
194 computation.
Print(os, nnet);
195 KALDI_LOG <<
"Generated computation is: " << os.str();
212 std::ostringstream os;
213 computation.
Print(os, nnet);
214 KALDI_LOG <<
"Optimized computation is: " << os.str();
220 compute_opts.
debug =
true;
228 for (
size_t i = 0;
i < request.
inputs.size();
i++) {
239 KALDI_LOG <<
"Output sum is " << output.Sum();
241 if (test_collapse_model) {
243 computation_collapsed,
246 for (
size_t i = 0;
i < request.
inputs.size();
i++) {
251 computer_collapsed.
Run();
254 KALDI_LOG <<
"Output sum [collapsed] is " << output_collapsed.Sum();
256 KALDI_ERR <<
"Regular and collapsed computations' outputs differ";
263 if (request.
outputs[0].has_deriv) {
266 for (
size_t i = 0;
i < request.
inputs.size();
i++) {
267 if (request.
inputs[
i].has_deriv) {
270 KALDI_LOG <<
"Input-deriv sum for input '" 271 << request.
inputs[
i].name <<
"' is " << in_deriv.
Sum();
283 using namespace kaldi;
292 CuDevice::Instantiate().SetDebugStrideMode(
true);
294 CuDevice::Instantiate().SelectGpuId(
"no");
296 CuDevice::Instantiate().SelectGpuId(
"yes");
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 InputDim(const std::string &input_name) const
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
void TestNnetDecodable(Nnet *nnet)
void ApplyExp()
Apply exponential to each value in vector.
void ReadConfig(std::istream &config_file)
void ComputeCudaIndexes()
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
This file contains various routines that are useful in test code.
void Print(std::ostream &os, const Nnet &nnet) const
This file contains utilities for analyzing and checking computations, which are used in the optimizat...
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent.
std::vector< IoSpecification > inputs
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void GetOutputForFrame(int32 frame, VectorBase< BaseFloat > *output)
int32 OutputDim(const std::string &output_name) const
This file contains some miscellaneous functions dealing with class Nnet.
std::string Info() const
returns some human-readable information about the network, mostly for debugging purposes.
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
void AcceptInput(const std::string &node_name, CuMatrix< BaseFloat > *input)
e.g.
void ComputeExampleComputationRequestSimple(const Nnet &nnet, ComputationRequest *request, std::vector< Matrix< BaseFloat > > *inputs)
This function computes an example computation request, for testing purposes.
const CuMatrixBase< BaseFloat > & GetOutput(const std::string &node_name)
void Read(std::istream &istream, bool binary)
int32 MaxOutputTimeInRequest(const ComputationRequest &request)
void Read(std::istream &istream, bool binary)
void GetOutputForFrame(int32 subsampled_frame, VectorBase< BaseFloat > *output)
MatrixIndexT Dim() const
Returns the dimension of the vector.
void Optimize(const NnetOptimizeOptions &config, const Nnet &nnet, int32 max_output_time_in_request, NnetComputation *computation)
This is the top-level function for optimizing a computation.
int Rand(struct RandomState *state)
void SetRandn()
Set vector to random normally-distributed noise.
void UnitTestComputationRequestIo(ComputationRequest *request)
Matrix for CUDA computing.
A class representing a vector.
class NnetComputer is responsible for executing the computation described in the "computation" object...
void CreateComputation(const CompilerOptions &opts, NnetComputation *computation)
void UnitTestNnetCompute()
#define KALDI_ASSERT(cond)
std::vector< IoSpecification > outputs
This class creates an initial version of the NnetComputation, without any optimization or sharing of ...
void UnitTestNnetComputationIo(NnetComputation *computation)
void Write(std::ostream &ostream, bool binary) const
bool NnetIsRecurrent(const Nnet &nnet)
Returns true if 'nnet' has some kind of recurrency.
void GenerateConfigSequence(const NnetGenerationOptions &opts, std::vector< std::string > *configs)
Generates a sequence of at least one config files, output as strings, where the first in the sequence...
When you instantiate class DecodableNnetSimpleLooped, you should give it a const reference to this cl...
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
void Write(std::ostream &ostream, bool binary) const
Config class for the CollapseModel function.
void Run()
This does either the forward or backward computation, depending when it is called (in a typical compu...