From 85a76e8a91a3114e2061b8ffc1cad979c37a5873 Mon Sep 17 00:00:00 2001 From: Yimmon Zhuang Date: Sat, 10 Oct 2015 19:25:17 +0800 Subject: disable batch when sequence training --- kaldi_seq/Makefile | 11 +++++++---- kaldi_seq/src/kaldi_mmi.cpp | 3 +-- kaldi_seq/src/kaldi_mpe.cpp | 13 +++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) (limited to 'kaldi_seq') diff --git a/kaldi_seq/Makefile b/kaldi_seq/Makefile index 7e2dd2e..1232c5a 100644 --- a/kaldi_seq/Makefile +++ b/kaldi_seq/Makefile @@ -23,18 +23,21 @@ build: $(OBJ_DIR) $(OBJ_SUBDIR) $(OBJS) install: $(LUA_DIR) $(LUA_SUBDIR) $(LIBS) include $(KDIR)/src/kaldi.mk -KL := -L/home/slhome/ymz09/mylibs/ -L$(KDIR)/tools/openfst-1.3.4/lib/ $(KDIR)/src/feat/kaldi-feat.a $(KDIR)/src/matrix/kaldi-matrix.a $(KDIR)/src/base/kaldi-base.a $(KDIR)/src/util/kaldi-util.a $(KDIR)/src/hmm/kaldi-hmm.a $(KDIR)/src/tree/kaldi-tree.a $(KDIR)/src/nnet/kaldi-nnet.a $(KDIR)/src/cudamatrix/kaldi-cudamatrix.a $(KDIR)/src/lat/kaldi-lat.a $(KDIR)/src/hmm/kaldi-hmm.a $(KDIR)/src/tree/kaldi-tree.a $(KDIR)/src/matrix/kaldi-matrix.a $(KDIR)/src/util/kaldi-util.a $(KDIR)/src/base/kaldi-base.a -lcblas -llapack_atlas -lfst -lcudart -lcublas -DHAVE_CUDA + +KL1 := -rdynamic -Wl,-rpath=$(KDIR)/tools/openfst/lib -L/usr/local/cuda/lib64 -Wl,-rpath,/usr/local/cuda/lib64 -Wl,-rpath=$(KDIR)/src/lib -L. -L$(KDIR)/src/nnet/ -L$(KDIR)/src/cudamatrix/ -L$(KDIR)/src/lat/ -L$(KDIR)/src/hmm/ -L$(KDIR)/src/tree/ -L$(KDIR)/src/matrix/ -L$(KDIR)/src/util/ -L$(KDIR)/src/base/ $(KDIR)/src/nnet//libkaldi-nnet.so $(KDIR)/src/cudamatrix//libkaldi-cudamatrix.so $(KDIR)/src/lat//libkaldi-lat.so $(KDIR)/src/hmm//libkaldi-hmm.so $(KDIR)/src/tree//libkaldi-tree.so $(KDIR)/src/matrix//libkaldi-matrix.so $(KDIR)/src/util//libkaldi-util.so $(KDIR)/src/base//libkaldi-base.so -L$(KDIR)/tools/openfst/lib -lfst /usr/lib/liblapack.so /usr/lib/libcblas.so /usr/lib/libatlas.so /usr/lib/libf77blas.so -lm -lpthread -ldl -lcublas -lcudart -lkaldi-nnet -lkaldi-cudamatrix -lkaldi-lat -lkaldi-hmm -lkaldi-tree -lkaldi-matrix -lkaldi-util -lkaldi-base + +KL2 := -msse -msse2 -Wall -pthread -DKALDI_DOUBLEPRECISION=0 -DHAVE_POSIX_MEMALIGN -Wno-sign-compare -Wno-unused-local-typedefs -Winit-self -DHAVE_EXECINFO_H=1 -rdynamic -DHAVE_CXXABI_H -DHAVE_ATLAS -I$(KDIR)/tools/ATLAS/include -I$(KDIR)/tools/openfst/include -Wno-sign-compare -g -fPIC -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -DKALDI_NO_EXPF $(OBJ_DIR) $(LUA_DIR) $(OBJ_SUBDIR) $(LUA_SUBDIR): -mkdir -p $@ $(LUA_DIR)/%.lua: %.lua cp $< $@ $(LIBS): $(OBJ_DIR)/src/kaldi_mpe.o $(OBJ_DIR)/src/kaldi_mmi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o - gcc -shared -fPIC -o $@ $(OBJ_DIR)/src/kaldi_mpe.o $(OBJ_DIR)/src/kaldi_mmi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -lluaT $(KL) + gcc -shared -fPIC -o $@ $(OBJ_DIR)/src/kaldi_mpe.o $(OBJ_DIR)/src/kaldi_mmi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -lluaT $(KL1) $(OBJ_DIR)/src/kaldi_mpe.o: src/kaldi_mpe.cpp - g++ -o $@ -c $< -DHAVE_ATLAS $(KALDIINCLUDE) -g -fPIC $(INCLUDE) -DKALDI_DOUBLEPRECISION=0 -msse2 -DHAVE_POSIX_MEMALIGN + g++ -o $@ -c $< $(KALDIINCLUDE) -g -fPIC $(INCLUDE) $(KL2) $(OBJ_DIR)/src/kaldi_mmi.o: src/kaldi_mmi.cpp - g++ -o $@ -c $< -DHAVE_ATLAS $(KALDIINCLUDE) -g -fPIC $(INCLUDE) -DKALDI_DOUBLEPRECISION=0 -msse2 -DHAVE_POSIX_MEMALIGN + g++ -o $@ -c $< $(KALDIINCLUDE) -g -fPIC $(INCLUDE) $(KL2) $(OBJ_DIR)/%.o: %.c gcc -o $@ -c $< -g $(INCLUDE) -fPIC clean: diff --git a/kaldi_seq/src/kaldi_mmi.cpp b/kaldi_seq/src/kaldi_mmi.cpp index a64abd0..ea9b4f1 100644 --- a/kaldi_seq/src/kaldi_mmi.cpp +++ b/kaldi_seq/src/kaldi_mmi.cpp @@ -164,12 +164,11 @@ extern "C" { // Select the GPU #if HAVE_CUDA == 1 - CuDevice::Instantiate().SelectGpuId(use_gpu); + CuDevice::Instantiate().SelectGpuId(mmi->use_gpu); #endif // Read the class-frame-counts, compute priors mmi->log_prior = new PdfPrior(prior_opts); - PdfPrior &log_prior = *(mmi->log_prior); // Read transition model mmi->trans_model = new TransitionModel; diff --git a/kaldi_seq/src/kaldi_mpe.cpp b/kaldi_seq/src/kaldi_mpe.cpp index 8cdf010..60384e2 100644 --- a/kaldi_seq/src/kaldi_mpe.cpp +++ b/kaldi_seq/src/kaldi_mpe.cpp @@ -205,12 +205,11 @@ extern "C" { // Select the GPU #if HAVE_CUDA == 1 - CuDevice::Instantiate().SelectGpuId(use_gpu); + CuDevice::Instantiate().SelectGpuId(mpe->use_gpu); #endif // Read the class-frame-counts, compute priors mpe->log_prior = new PdfPrior(prior_opts); - PdfPrior &log_prior = *(mpe->log_prior); // Read transition model mpe->trans_model = new TransitionModel; @@ -256,7 +255,7 @@ extern "C" { return 0; } - assert(sizeof(BaseFloat) == sizeof(float)); + //assert(sizeof(BaseFloat) == sizeof(float)); // 1) get the features, numerator alignment mpe->ref_ali = mpe->ref_ali_reader->Value(utt); long mat_nrow = mat->nrow, mat_ncol = mat->ncol; @@ -309,8 +308,9 @@ extern "C" { NervMatrix * calc_diff_mpe(KaldiMPE * mpe, NervMatrix * mat, const char * key) { std::string utt(key); - assert(sizeof(BaseFloat) == sizeof(float)); + //assert(sizeof(BaseFloat) == sizeof(float)); + CuMatrix nnet_diff; kaldi::Matrix nnet_out_h; nnet_out_h.Resize(mat->nrow, mat->ncol, kUndefined); @@ -327,9 +327,10 @@ extern "C" { PdfPriorOptions &prior_opts = *(mpe->prior_opts); if (prior_opts.class_frame_counts != "") { CuMatrix nnet_out; - nnet_out.Resize(mat->nrow, mat->ncol, kUndefined); + nnet_out.Resize(nnet_out_h.NumRows(), nnet_out_h.NumCols(), kUndefined); nnet_out.CopyFromMat(nnet_out_h); mpe->log_prior->SubtractOnLogpost(&nnet_out); + nnet_out_h.Resize(nnet_out.NumRows(), nnet_out.NumCols(), kUndefined); nnet_out.CopyToMat(&nnet_out_h); nnet_out.Resize(0,0); } @@ -353,7 +354,6 @@ extern "C" { } // 6) convert the Posterior to a matrix, - CuMatrix nnet_diff; PosteriorToMatrixMapped(post, *(mpe->trans_model), &nnet_diff); nnet_diff.Scale(-1.0); // need to flip the sign of derivative, @@ -366,6 +366,7 @@ extern "C" { << " frames," << " diff-range(" << nnet_diff.Min() << "," << nnet_diff.Max() << ")"; + nnet_out_h.Resize(nnet_diff.NumRows(), nnet_diff.NumCols(), kUndefined); nnet_diff.CopyToMat(&nnet_out_h); nnet_diff.Resize(0,0); // release GPU memory, -- cgit v1.2.3-70-g09d2