Skip to content

Commit

Permalink
Merge branch 'dropout_schedule' into nnet3-dropout
Browse files Browse the repository at this point in the history
  • Loading branch information
vimalmanohar authored Dec 15, 2016
2 parents 5435f23 + 7899760 commit 18404a9
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 34 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ Development pattern for contributors
You can use the [Google's cpplint.py]
(https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py)
to verify that your code is free of basic mistakes.

Platform specific notes
-----------------------

PowerPC 64bits little-endian (ppc64le):
- Kaldi is expected to work out of the box in RHEL >= 7 and Ubuntu >= 16.04 with
OpenBLAS, ATLAS, or CUDA.
- CUDA drivers for ppc64le can be found at [https://developer.nvidia.com/cuda-downloads]
(https://developer.nvidia.com/cuda-downloads).
- An [IBM Redbook] (https://www.redbooks.ibm.com/abstracts/redp5169.html) is
available as a guide to install and configure CUDA.
2 changes: 1 addition & 1 deletion egs/wsj/s5/steps/cleanup/create_segments_from_ctm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ sub InsertSilence {
my $first_word = $col[$x * 3];
my $second_word = $col[$x * 3 + 1];
if ($x * 3 + 2 < @col) {
if ($col[$x*3 + 2] != $separator) {
if ($col[$x * 3 + 2] ne $separator) {
die "Bad line in align-text output (expected separator '$separator'): $_";
}
}
Expand Down
43 changes: 25 additions & 18 deletions egs/wsj/s5/steps/libs/nnet3/train/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,44 +389,50 @@ def _parse_dropout_string(num_archives_to_process, dropout_str):
"""
dropout_values = []
parts = dropout_str.strip().split(',')

try:
if len(parts) < 2:
raise Exception("dropout proportion string must specify "
"at least the start and end dropouts")

# Starting dropout proportion
dropout_values.append((0, float(parts[0])))
data_fraction_one_previous='' # used to control situations like: [email protected],[email protected]
for i in range(1, len(parts) - 1):
value_x_pair = parts[i].split('@')
if len(value_x_pair) == 1:
# Dropout proportion at half of training
dropout_proportion = float(parts[i])
dropout_values.append((0.5 * num_archives_to_process,
dropout_proportion))
dropout_proportion = float(value_x_pair)
num_archives = int(0.5 * num_archives_to_process)
else:
assert len(value_x_pair) == 2
dropout_proportion, data_fraction = value_x_pair
if data_fraction == data_fraction_one_previous :
dropout_values.append(
(float(data_fraction) * num_archives_to_process + 1.0,
float(dropout_proportion)))
else:
dropout_values.append(
(float(data_fraction) * num_archives_to_process,
float(dropout_proportion)))
_, data_fraction_one_previous = value_x_pair

dropout_proportion = float(value_x_pair[0])
data_fraction = float(value_x_pair[1])
num_archives = round(float(data_fraction)
* num_archives_to_process)

if (num_archives < dropout_values[-1][0]
or num_archives >= num_archives_to_process):
logger.error(
"Failed while parsing value %s in dropout-schedule. "
"dropout-schedule must be in incresing "
"order of data fractions.", value_x_pair)
raise ValueError
elif num_archives == dropout_values[-1][0]:
num_archives += 1.0

dropout_values.append(num_archives, float(dropout_proportion))

dropout_values.append((num_archives_to_process, float(parts[-1])))
except Exception:
logger.error("Unable to parse dropout proportion string {0}. "
logger.error("Unable to parse dropout proportion string %s. "
"See help for option "
"--trainer.dropout-schedule.".format(dropout_str))
"--trainer.dropout-schedule.", dropout_str)
raise

# reverse sort so that its easy to retrieve the dropout proportion
# for a particular data fraction
dropout_values.sort(key=lambda x: x[0], reverse=True)
dropout_values.reverse()
for num_archives, proportion in dropout_values:
assert num_archives <= num_archives_to_process and num_archives >= 0
assert proportion <= 1 and proportion >= 0
Expand Down Expand Up @@ -738,7 +744,8 @@ def __init__(self):
doesn't increase the effective learning
rate.""")
self.parser.add_argument("--trainer.dropout-schedule", type=str,
dest='dropout_schedule', default='',
action=common_lib.NullstrToNoneAction,
dest='dropout_schedule', default=None,
help="""Use this to specify the dropout
schedule. You specify a piecewise linear
function on the domain [0,1], where 0 is the
Expand Down
3 changes: 2 additions & 1 deletion egs/wsj/s5/steps/libs/nnet3/xconfig/basic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import print_function
import sys
import math
import libs.nnet3.xconfig.utils as xutils
from libs.nnet3.xconfig.utils import XconfigParserError as xparser_error

Expand Down Expand Up @@ -849,7 +850,7 @@ def set_default_configs(self):
def set_derived_configs(self):
super(XconfigAffineLayer, self).set_derived_configs()
if self.config['param-stddev'] < 0:
self.config['param-stddev'] = 1.0 / self.descriptors['input']['dim']
self.config['param-stddev'] = 1.0 / math.sqrt(self.descriptors['input']['dim'])

def check_configs(self):
if self.config['dim'] <= 0:
Expand Down
4 changes: 2 additions & 2 deletions egs/wsj/s5/steps/scoring/score_kaldi_cer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "$0 $@" # Print the command line for logging
. parse_options.sh || exit 1;

if [ $# -ne 3 ]; then
echo "Usage: local/score.sh [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
echo "Usage: $0 [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
echo " Options:"
echo " --cmd (run.pl|queue.pl...) # specify how to run the sub-processes."
echo " --stage (0|1|2) # start scoring script from part-way through."
Expand All @@ -50,7 +50,7 @@ dir=$3
symtab=$lang_or_graph/words.txt

for f in $symtab $dir/lat.1.gz $data/text; do
[ ! -f $f ] && echo "score.sh: no such file $f" && exit 1;
[ ! -f $f ] && echo "$0: no such file $f" && exit 1;
done


Expand Down
4 changes: 2 additions & 2 deletions egs/wsj/s5/steps/scoring/score_kaldi_compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ echo "$0 $@" # Print the command line for logging
. parse_options.sh || exit 1;

if [ $# -ne 3 ]; then
echo "Usage: local/score_compare.sh [--cmd (run.pl|queue.pl...)] <score-dir1> <score-dir2> <score-compare-dir>"
echo "Usage: $0 [--cmd (run.pl|queue.pl...)] <score-dir1> <score-dir2> <score-compare-dir>"
echo " Options:"
echo " --cmd (run.pl|queue.pl...) # specify how to run the sub-processes."
echo " --replications <int> # number of bootstrap evaluation to compute confidence."
Expand All @@ -29,7 +29,7 @@ mkdir -p $dir_compare/log

for d in $dir1 $dir2; do
for f in test_filt.txt best_wer; do
[ ! -f $d/$f ] && echo "score_compare.sh: no such file $d/$f" && exit 1;
[ ! -f $d/$f ] && echo "$0: no such file $d/$f" && exit 1;
done
done

Expand Down
2 changes: 1 addition & 1 deletion egs/wsj/s5/steps/scoring/score_kaldi_wer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ echo "$0 $@" # Print the command line for logging
. parse_options.sh || exit 1;

if [ $# -ne 3 ]; then
echo "Usage: local/score.sh [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
echo "Usage: $0 [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
echo " Options:"
echo " --cmd (run.pl|queue.pl...) # specify how to run the sub-processes."
echo " --stage (0|1|2) # start scoring script from part-way through."
Expand Down
20 changes: 20 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ function configure_cuda {
else
cat makefiles/cuda_64bit.mk >> kaldi.mk
fi
elif [ "`uname -m`" == "ppc64le" ]; then
cat makefiles/cuda_ppc64le.mk >> kaldi.mk
else
cat makefiles/cuda_32bit.mk >> kaldi.mk
fi
Expand Down Expand Up @@ -526,6 +528,8 @@ function linux_atlas_failure { # function we use when we couldn't find
echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand Down Expand Up @@ -581,6 +585,8 @@ function linux_configure_debian_ubuntu {
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand All @@ -604,6 +610,8 @@ function linux_configure_debian_ubuntu3 {
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand All @@ -630,6 +638,8 @@ function linux_configure_debian7 {
echo
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand All @@ -653,6 +663,8 @@ function linux_configure_redhat {
echo
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand All @@ -678,6 +690,8 @@ function linux_configure_redhat_fat {
echo
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand Down Expand Up @@ -735,6 +749,8 @@ function linux_configure_static {
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand Down Expand Up @@ -818,6 +834,8 @@ function linux_configure_dynamic {
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
Expand Down Expand Up @@ -1104,6 +1122,8 @@ if [ "`uname`" == "Linux" ]; then
echo "OPENBLASROOT = $OPENBLASROOT" >> kaldi.mk
if [[ "`uname -m`" == arm* ]]; then
cat makefiles/linux_openblas_arm.mk >> kaldi.mk
elif [[ "`uname -m`" == ppc64le ]]; then
cat makefiles/linux_openblas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_openblas.mk >> kaldi.mk
fi
Expand Down
12 changes: 12 additions & 0 deletions src/makefiles/cuda_ppc64le.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

ifndef DOUBLE_PRECISION
$(error DOUBLE_PRECISION not defined.)
endif


CUDA_INCLUDE= -I$(CUDATKDIR)/include
CUDA_FLAGS = -g -Xcompiler -fPIC --verbose --machine 64 -DHAVE_CUDA \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION)
CXXFLAGS += -DHAVE_CUDA -I$(CUDATKDIR)/include
CUDA_LDFLAGS += -L$(CUDATKDIR)/lib64 -Wl,-rpath,$(CUDATKDIR)/lib64
CUDA_LDLIBS += -lcublas -lcudart -lcurand #LDLIBS : The libs are loaded later than static libs in implicit rule
37 changes: 37 additions & 0 deletions src/makefiles/linux_atlas_ppc64le.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# You have to make sure ATLASLIBS is set...

ifndef FSTROOT
$(error FSTROOT not defined.)
endif

ifndef ATLASINC
$(error ATLASINC not defined.)
endif

ifndef ATLASLIBS
$(error ATLASLIBS not defined.)
endif


DOUBLE_PRECISION = 0
CXXFLAGS = -m64 -maltivec -mcpu=power8 -Wall -I.. \
-mtune=power8 -mpower8-vector -mvsx -pthread \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-Wno-sign-compare -Wno-unused-local-typedefs -Winit-self \
-DHAVE_EXECINFO_H=1 -rdynamic -DHAVE_CXXABI_H \
-DHAVE_ATLAS -I$(ATLASINC) \
-I$(FSTROOT)/include \
$(EXTRA_CXXFLAGS) \
-g # -O0 -DKALDI_PARANOID

ifeq ($(KALDI_FLAVOR), dynamic)
CXXFLAGS += -fPIC
endif

LDFLAGS = -rdynamic $(OPENFSTLDFLAGS)
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(ATLASLIBS) -lm -lpthread -ldl
CC = g++
CXX = g++
AR = ar
AS = as
RANLIB = ranlib
37 changes: 37 additions & 0 deletions src/makefiles/linux_openblas_ppc64le.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# You have to make sure FSTROOT,OPENBLASROOT,OPENBLASLIBS are set...

ifndef FSTROOT
$(error FSTROOT not defined.)
endif

ifndef OPENBLASLIBS
$(error OPENBLASLIBS not defined.)
endif

ifndef OPENBLASROOT
$(error OPENBLASROOT not defined.)
endif


DOUBLE_PRECISION = 0
CXXFLAGS = -m64 -maltivec -mcpu=power8 -Wall -I.. \
-mtune=power8 -mpower8-vector -mvsx -pthread \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-Wno-sign-compare -Wno-unused-local-typedefs -Winit-self \
-DHAVE_EXECINFO_H=1 -rdynamic -DHAVE_CXXABI_H \
-DHAVE_OPENBLAS -I $(OPENBLASROOT)/include \
-I $(FSTROOT)/include \
$(EXTRA_CXXFLAGS) \
-g # -O0 -DKALDI_PARANOID

ifeq ($(KALDI_FLAVOR), dynamic)
CXXFLAGS += -fPIC
endif

LDFLAGS = -rdynamic $(OPENFSTLDFLAGS)
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(OPENBLASLIBS) -lm -lpthread -ldl
CC = g++
CXX = g++
AR = ar
AS = as
RANLIB = ranlib
2 changes: 0 additions & 2 deletions src/nnet3/am-nnet-simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ void AmNnetSimple::SetPriors(const VectorBase<BaseFloat> &priors) {

std::string AmNnetSimple::Info() const {
std::ostringstream ostr;
ostr << "left-context: " << left_context_ << "\n";
ostr << "right-context: " << right_context_ << "\n";
ostr << "input-dim: " << nnet_.InputDim("input") << "\n";
ostr << "ivector-dim: " << nnet_.InputDim("ivector") << "\n";
ostr << "num-pdfs: " << nnet_.OutputDim("output") << "\n";
Expand Down
Loading

0 comments on commit 18404a9

Please sign in to comment.