Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix_init
Browse files Browse the repository at this point in the history
  • Loading branch information
LiChenda committed Aug 24, 2022
2 parents 37eccb6 + f274ebe commit ed7db10
Show file tree
Hide file tree
Showing 90 changed files with 7,551 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.pytorch-version }}-${{ hashFiles('**/setup.py') }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.pytorch-version }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test_import.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
pytorch-version: [1.11.0]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.pytorch-version }}-${{ hashFiles('**/setup.py') }}
- name: Set up Python
uses: actions/setup-python@v1
with:
Expand All @@ -35,10 +31,14 @@ jobs:
env:
TH_VERSION: ${{ matrix.pytorch-version }}
run: |
python3 -m pip install "numpy<=1.21.4"
python3 -m pip freeze
./tools/installers/install_torch.sh false ${TH_VERSION} CPU
./tools/installers/install_chainer.sh CPU
python3 setup.py bdist_wheel
python3 -m pip install dist/espnet-*.whl
# log
python3 -m pip freeze
- name: Import all modules (Try1)
run: |
python3 ./ci/test_import_all.py
Expand All @@ -47,6 +47,8 @@ jobs:
TH_VERSION: ${{ matrix.pytorch-version }}
run: |
python3 -m pip install "$(ls dist/espnet-*.whl)[all]"
# log
python3 -m pip freeze
- name: Import all modules (Try2)
run: |
python3 ./ci/test_import_all.py
24 changes: 24 additions & 0 deletions ci/test_integration_espnet2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ if python3 -c "import k2" &> /dev/null; then
--asr-args "--model_conf extract_feats_in_collect_stats=false --max_epoch=1"
fi

if python3 -c "from warprnnt_pytorch import RNNTLoss" &> /dev/null; then
echo "==== [ESPnet2] ASR Transducer (standalone) ==="

for t in ${token_types}; do
asr_tag="transducer_${t}"

echo "==== [Conformer-RNN-T] feats_type=raw, token_types=${t}, model_conf.extract_feats_in_collect_stats=False, normalize=utt_mvn ==="
./run.sh --asr_task "asr_transducer" --ngpu 0 --stage 10 --stop-stage 13 --skip-upload false --feats-type "raw" --token-type ${t} \
--feats_normalize "utterance_mvn" --lm-args "--max_epoch=1" --python "${python}" --inference_asr_model "valid.loss.best.pth" \
--asr-tag "${asr_tag}_conformer" --asr-args "--model_conf extract_feats_in_collect_stats=false --max_epoch=1 \
--encoder_conf body_conf='[{'block_type': 'conformer', 'hidden_size': 30, 'linear_size': 30, 'heads': 2, 'conv_mod_kernel_size': 3}]' \
--decoder_conf='{'embed_size': 30, 'hidden_size': 30}' --joint_network_conf joint_space_size=30"

echo "==== [Streaming Conformer-RNN-T] feats_type=raw, token_types=${t}, model_conf.extract_feats_in_collect_stats=False, normalize=utt_mvn ==="
./run.sh --asr_task "asr_transducer" --ngpu 0 --stage 10 --stop-stage 13 --skip-upload false --feats-type "raw" --token-type ${t} \
--feats_normalize "utterance_mvn" --lm-args "--max_epoch=1" --python "${python}" --inference_asr_model "valid.loss.best.pth" \
--asr-tag "${asr_tag}_conformer_streaming" --asr-args "--model_conf extract_feats_in_collect_stats=false --max_epoch=1 \
--encoder_conf main_conf='{'dynamic_chunk_training': True}' \
--encoder_conf body_conf='[{'block_type': 'conformer', 'hidden_size': 30, 'linear_size': 30, 'heads': 2, 'conv_mod_kernel_size': 3}]' \
--decoder_conf='{'embed_size': 30, 'hidden_size': 30}' --joint_network_conf joint_space_size=30 " \
--inference-args "--streaming true --chunk_size 2 --left_context 2 --right_context 0"
done
fi

# Remove generated files in order to reduce the disk usage
rm -rf exp dump data
cd "${cwd}"
Expand Down
244 changes: 242 additions & 2 deletions doc/espnet2_tutorial.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions egs2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See: https://espnet.github.io/espnet/espnet2_tutorial.html#recipes-using-espnet2

| Directory name | Corpus name | Task | Language | URL | Note |
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------|-------------------------| --------------------- | ------------------------------------------------------------------------------------------------------------ | ------------ |
| aesrc2020 | Accented English Speech Recognition Challenge 2020 | ASR | ENG | https://arxiv.org/abs/2102.10233 | |
| aidatatang_200zh | Aidatatang_200zh A free Chinese Mandarin speech corpus | ASR | CMN | http://www.openslr.org/resources/62 | |
| aishell | AISHELL-ASR0009-OS1 Open Source Mandarin Speech Corpus | ASR | CMN | http://www.aishelltech.com/kysjcp | |
| aishell2 | AISHELL-2 Open Source Mandarin Speech Corpus | ASR | CMN | https://www.aishelltech.com/aishell_2 | |
Expand Down
46 changes: 24 additions & 22 deletions egs2/TEMPLATE/asr1/asr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ num_splits_lm=1 # Number of splitting for lm corpus.
word_vocab_size=10000 # Size of word vocabulary.

# ASR model related
asr_task=asr # ASR task mode. Either 'asr' or 'asr_transducer'.
asr_tag= # Suffix to the result dir for asr model training.
asr_exp= # Specify the directory path for ASR experiment.
# If this option is specified, asr_tag is ignored.
Expand Down Expand Up @@ -203,6 +204,7 @@ Options:
--num_splits_lm # Number of splitting for lm corpus (default="${num_splits_lm}").
# ASR model related
--asr_task # ASR task mode. Either 'asr' or 'asr_transducer'. (default="${asr_task}").
--asr_tag # Suffix to the result dir for asr model training (default="${asr_tag}").
--asr_exp # Specify the directory path for ASR experiment.
# If this option is specified, asr_tag is ignored (default="${asr_exp}").
Expand Down Expand Up @@ -974,7 +976,7 @@ if ! "${skip_train}"; then

# shellcheck disable=SC2046,SC2086
${train_cmd} JOB=1:"${_nj}" "${_logdir}"/stats.JOB.log \
${python} -m espnet2.bin.asr_train \
${python} -m espnet2.bin.${asr_task}_train \
--collect_stats true \
--use_preprocessor true \
--bpemodel "${bpemodel}" \
Expand Down Expand Up @@ -1101,7 +1103,7 @@ if ! "${skip_train}"; then
--num_nodes "${num_nodes}" \
--init_file_prefix "${asr_exp}"/.dist_init_ \
--multiprocessing_distributed true -- \
${python} -m espnet2.bin.asr_train \
${python} -m espnet2.bin.${asr_task}_train \
--use_preprocessor true \
--bpemodel "${bpemodel}" \
--token_type "${token_type}" \
Expand Down Expand Up @@ -1191,24 +1193,24 @@ if ! "${skip_eval}"; then
# 2. Generate run.sh
log "Generate '${asr_exp}/${inference_tag}/run.sh'. You can resume the process from stage 12 using this script"
mkdir -p "${asr_exp}/${inference_tag}"; echo "${run_args} --stage 12 \"\$@\"; exit \$?" > "${asr_exp}/${inference_tag}/run.sh"; chmod +x "${asr_exp}/${inference_tag}/run.sh"
if "${use_k2}"; then
# Now only _nj=1 is verified if using k2
asr_inference_tool="espnet2.bin.asr_inference_k2"

_opts+="--is_ctc_decoding ${k2_ctc_decoding} "
_opts+="--use_nbest_rescoring ${use_nbest_rescoring} "
_opts+="--num_paths ${num_paths} "
_opts+="--nll_batch_size ${nll_batch_size} "
_opts+="--k2_config ${k2_config} "
else
if "${use_streaming}"; then
asr_inference_tool="espnet2.bin.asr_inference_streaming"
elif "${use_maskctc}"; then
asr_inference_tool="espnet2.bin.asr_inference_maskctc"
else
asr_inference_tool="espnet2.bin.asr_inference"
fi
fi

inference_bin_tag=""
if [ ${asr_task} == "asr" ]; then
if "${use_k2}"; then
# Now only _nj=1 is verified if using k2
inference_bin_tag="_k2"

_opts+="--is_ctc_decoding ${k2_ctc_decoding} "
_opts+="--use_nbest_rescoring ${use_nbest_rescoring} "
_opts+="--num_paths ${num_paths} "
_opts+="--nll_batch_size ${nll_batch_size} "
_opts+="--k2_config ${k2_config} "
elif "${use_streaming}"; then
inference_bin_tag="_streaming"
elif "${use_maskctc}"; then
inference_bin_tag="_maskctc"
fi
fi

for dset in ${test_sets}; do
_data="${data_feats}/${dset}"
Expand Down Expand Up @@ -1250,7 +1252,7 @@ if ! "${skip_eval}"; then
rm -f "${_logdir}/*.log"
# shellcheck disable=SC2046,SC2086
${_cmd} --gpu "${_ngpu}" JOB=1:"${_nj}" "${_logdir}"/asr_inference.JOB.log \
${python} -m ${asr_inference_tool} \
${python} -m espnet2.bin.${asr_task}_inference${inference_bin_tag} \
--batch_size ${batch_size} \
--ngpu "${_ngpu}" \
--data_path_and_name_and_type "${_data}/${_scp},speech,${_type}" \
Expand All @@ -1261,7 +1263,7 @@ if ! "${skip_eval}"; then
${_opts} ${inference_args} || { cat $(grep -l -i error "${_logdir}"/asr_inference.*.log) ; exit 1; }

# 3. Calculate and report RTF based on decoding logs
if [ $asr_inference_tool == "espnet2.bin.asr_inference" ]; then
if [ ${asr_task} == "asr" ] && [ -z ${inference_bin_tag} ]; then
log "Calculating RTF & latency... log: '${_logdir}/calculate_rtf.log'"
rm -f "${_logdir}"/calculate_rtf.log
_fs=$(python3 -c "import humanfriendly as h;print(h.parse_size('${fs}'))")
Expand Down
34 changes: 34 additions & 0 deletions egs2/aesrc2020/asr1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- Generated by scripts/utils/show_asr_result.sh -->
# RESULTS
## Environments
- date: `Sat Aug 20 06:55:57 EDT 2022`
- python version: `3.8.13 (default, Mar 28 2022, 11:38:47) [GCC 7.5.0]`
- espnet version: `espnet 202207`
- pytorch version: `pytorch 1.8.1`
- Git hash: `c892feb2ba248c85b683bf3cdef6c8f7ce85449a`
- Commit date: `Thu Aug 18 11:54:56 2022 -0400`

## asr_train_asr_raw_en_bpe5000_sp

- Model link: [huggingface](https://huggingface.co/espnet/brianyan918_aesrc2020_asr_conformer)
- ASR config: [./conf/train_asr.yaml](./conf/train_asr.yaml)
- Inference config: [./conf/decode_asr.yaml](./conf/decode_asr.yaml)

### WER

|dataset|Snt|Wrd|Corr|Sub|Del|Ins|Err|S.Err|
|---|---|---|---|---|---|---|---|---|
|decode_asr_asr_model_valid.acc.ave/test|15299|146813|94.8|4.7|0.6|0.7|5.9|31.9|

### CER

|dataset|Snt|Wrd|Corr|Sub|Del|Ins|Err|S.Err|
|---|---|---|---|---|---|---|---|---|
|decode_asr_asr_model_valid.acc.ave/test|15299|708064|97.9|1.2|0.9|0.7|2.8|31.9|

### TER

|dataset|Snt|Wrd|Corr|Sub|Del|Ins|Err|S.Err|
|---|---|---|---|---|---|---|---|---|
|decode_asr_asr_model_valid.acc.ave/test|15299|165136|93.2|4.3|2.6|0.6|7.4|31.9|

1 change: 1 addition & 0 deletions egs2/aesrc2020/asr1/asr.sh
110 changes: 110 additions & 0 deletions egs2/aesrc2020/asr1/cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ====== About run.pl, queue.pl, slurm.pl, and ssh.pl ======
# Usage: <cmd>.pl [options] JOB=1:<nj> <log> <command...>
# e.g.
# run.pl --mem 4G JOB=1:10 echo.JOB.log echo JOB
#
# Options:
# --time <time>: Limit the maximum time to execute.
# --mem <mem>: Limit the maximum memory usage.
# -–max-jobs-run <njob>: Limit the number parallel jobs. This is ignored for non-array jobs.
# --num-threads <ngpu>: Specify the number of CPU core.
# --gpu <ngpu>: Specify the number of GPU devices.
# --config: Change the configuration file from default.
#
# "JOB=1:10" is used for "array jobs" and it can control the number of parallel jobs.
# The left string of "=", i.e. "JOB", is replaced by <N>(Nth job) in the command and the log file name,
# e.g. "echo JOB" is changed to "echo 3" for the 3rd job and "echo 8" for 8th job respectively.
# Note that the number must start with a positive number, so you can't use "JOB=0:10" for example.
#
# run.pl, queue.pl, slurm.pl, and ssh.pl have unified interface, not depending on its backend.
# These options are mapping to specific options for each backend and
# it is configured by "conf/queue.conf" and "conf/slurm.conf" by default.
# If jobs failed, your configuration might be wrong for your environment.
#
#
# The official documentation for run.pl, queue.pl, slurm.pl, and ssh.pl:
# "Parallelization in Kaldi": http://kaldi-asr.org/doc/queue.html
# =========================================================~


# Select the backend used by run.sh from "local", "stdout", "sge", "slurm", or "ssh"
cmd_backend='local'

# Local machine, without any Job scheduling system
if [ "${cmd_backend}" = local ]; then

# The other usage
export train_cmd="run.pl"
# Used for "*_train.py": "--gpu" is appended optionally by run.sh
export cuda_cmd="run.pl"
# Used for "*_recog.py"
export decode_cmd="run.pl"

# Local machine logging to stdout and log file, without any Job scheduling system
elif [ "${cmd_backend}" = stdout ]; then

# The other usage
export train_cmd="stdout.pl"
# Used for "*_train.py": "--gpu" is appended optionally by run.sh
export cuda_cmd="stdout.pl"
# Used for "*_recog.py"
export decode_cmd="stdout.pl"


# "qsub" (Sun Grid Engine, or derivation of it)
elif [ "${cmd_backend}" = sge ]; then
# The default setting is written in conf/queue.conf.
# You must change "-q g.q" for the "queue" for your environment.
# To know the "queue" names, type "qhost -q"
# Note that to use "--gpu *", you have to setup "complex_value" for the system scheduler.

export train_cmd="queue.pl"
export cuda_cmd="queue.pl"
export decode_cmd="queue.pl"


# "qsub" (Torque/PBS.)
elif [ "${cmd_backend}" = pbs ]; then
# The default setting is written in conf/pbs.conf.

export train_cmd="pbs.pl"
export cuda_cmd="pbs.pl"
export decode_cmd="pbs.pl"


# "sbatch" (Slurm)
elif [ "${cmd_backend}" = slurm ]; then
# The default setting is written in conf/slurm.conf.
# You must change "-p cpu" and "-p gpu" for the "partition" for your environment.
# To know the "partion" names, type "sinfo".
# You can use "--gpu * " by default for slurm and it is interpreted as "--gres gpu:*"
# The devices are allocated exclusively using "${CUDA_VISIBLE_DEVICES}".

export train_cmd="slurm.pl"
export cuda_cmd="slurm.pl"
export decode_cmd="slurm.pl"

elif [ "${cmd_backend}" = ssh ]; then
# You have to create ".queue/machines" to specify the host to execute jobs.
# e.g. .queue/machines
# host1
# host2
# host3
# Assuming you can login them without any password, i.e. You have to set ssh keys.

export train_cmd="ssh.pl"
export cuda_cmd="ssh.pl"
export decode_cmd="ssh.pl"

# This is an example of specifying several unique options in the JHU CLSP cluster setup.
# Users can modify/add their own command options according to their cluster environments.
elif [ "${cmd_backend}" = jhu ]; then

export train_cmd="queue.pl --mem 2G"
export cuda_cmd="queue-freegpu.pl --mem 2G --gpu 1 --config conf/queue.conf"
export decode_cmd="queue.pl --mem 4G"

else
echo "$0: Error: Unknown cmd_backend=${cmd_backend}" 1>&2
return 1
fi
6 changes: 6 additions & 0 deletions egs2/aesrc2020/asr1/conf/decode_asr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
beam_size: 20
ctc_weight: 0.3
lm_weight: 0.0
maxlenratio: 0.0
minlenratio: 0.0
penalty: 0.0
2 changes: 2 additions & 0 deletions egs2/aesrc2020/asr1/conf/fbank.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sample-frequency=16000
--num-mel-bins=80
11 changes: 11 additions & 0 deletions egs2/aesrc2020/asr1/conf/pbs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default configuration
command qsub -V -v PATH -S /bin/bash
option name=* -N $0
option mem=* -l mem=$0
option mem=0 # Do not add anything to qsub_opts
option num_threads=* -l ncpus=$0
option num_threads=1 # Do not add anything to qsub_opts
option num_nodes=* -l nodes=$0:ppn=1
default gpu=0
option gpu=0
option gpu=* -l ngpus=$0
1 change: 1 addition & 0 deletions egs2/aesrc2020/asr1/conf/pitch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sample-frequency=16000
12 changes: 12 additions & 0 deletions egs2/aesrc2020/asr1/conf/queue.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Default configuration
command qsub -v PATH -cwd -S /bin/bash -j y -l arch=*64*
option name=* -N $0
option mem=* -l mem_free=$0,ram_free=$0
option mem=0 # Do not add anything to qsub_opts
option num_threads=* -pe smp $0
option num_threads=1 # Do not add anything to qsub_opts
option max_jobs_run=* -tc $0
option num_nodes=* -pe mpi $0 # You must set this PE as allocation_rule=1
default gpu=0
option gpu=0
option gpu=* -l gpu=$0 -q g.q
14 changes: 14 additions & 0 deletions egs2/aesrc2020/asr1/conf/slurm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default configuration
command sbatch --export=PATH
option name=* --job-name $0
option time=* --time $0
option mem=* --mem-per-cpu $0
option mem=0
option num_threads=* --cpus-per-task $0
option num_threads=1 --cpus-per-task 1
option num_nodes=* --nodes $0
default gpu=0
option gpu=0 -p cpu
option gpu=* -p gpu --gres=gpu:$0 -c $0 # Recommend allocating more CPU than, or equal to the number of GPU
# note: the --max-jobs-run option is supported as a special case
# by slurm.pl and you don't have to handle it in the config file.
1 change: 1 addition & 0 deletions egs2/aesrc2020/asr1/conf/train_asr.yaml

0 comments on commit ed7db10

Please sign in to comment.