Skip to content

Commit dc7c09e

Browse files
authored
Update SPR PyTorch RNN-T inference container packages to use model zoo scripts (#288)
* RNN-T inference updates to use model zoo scripts * Update dockerfile * script updates for log names * Add download model to the package * Update doc to fix download_model.sh path * Fix conditional to use CHECKPOINT_DIR
1 parent e7eb81a commit dc7c09e

18 files changed

+217
-443
lines changed

dockerfiles/pytorch/pytorch-spr-rnnt-inference.Dockerfile

+3-10
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,13 @@ RUN chown -R root ${MODEL_WORKSPACE}/${PACKAGE_NAME} && chgrp -R root ${MODEL_WO
6262

6363
WORKDIR ${MODEL_WORKSPACE}/${PACKAGE_NAME}
6464

65-
ARG RNNT_DIR="/workspace/pytorch-spr-rnnt-inference/models/rnnt"
6665

6766
RUN source activate pytorch && \
68-
conda install intel-openmp && \
69-
yum install -y libsndfile && \
70-
cd ${RNNT_DIR} && \
71-
cd training/rnn_speech_recognition/pytorch && \
67+
cd ${MODEL_WORKSPACE}/${PACKAGE_NAME}/models/language_modeling/pytorch/rnnt/inference/cpu && \
7268
pip install -r requirements.txt && \
7369
pip install unidecode inflect && \
74-
mkdir -p /root/.local
75-
76-
RUN source activate pytorch && \
77-
cd /workspace && \
70+
yum install -y libsndfile && \
71+
mkdir -p /root/.local && \
7872
git clone https://github.com/HawkAaron/warp-transducer && \
7973
cd warp-transducer && \
8074
mkdir build && \
@@ -84,7 +78,6 @@ RUN source activate pytorch && \
8478
cd ../pytorch_binding && \
8579
python setup.py install
8680

87-
8881
FROM intel-optimized-pytorch AS release
8982
COPY --from=intel-optimized-pytorch /root/conda /root/conda
9083
COPY --from=intel-optimized-pytorch /workspace/lib/ /workspace/lib/

quickstart/language_modeling/pytorch/rnnt/inference/cpu/.docs/datasets.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ docker run --rm \
1616
-w /workspace/<package dir> \
1717
-it \
1818
<docker image> \
19-
/bin/bash quickstart/download_inference_dataset.sh
19+
/bin/bash quickstart/download_dataset.sh
2020
```
2121

2222
This `DATASET_DIR` environment variable will be used again when

quickstart/language_modeling/pytorch/rnnt/inference/cpu/.docs/docker_spr.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
## Run the model
22

3-
Download the pretrained model and set the `PRETRAINED_MODEL` environment variable
4-
to point to the file:
3+
Set the `CHECKPOINT_DIR` environment variable and run the script to download the
4+
pretrained model:
55
```
6-
wget https://zenodo.org/record/3662521/files/DistributedDataParallel_1576581068.9962234-epoch-100.pt?download=1 -O rnnt.pt
7-
export PRETRAINED_MODEL=$(pwd)/rnnt.pt
6+
export CHECKPOINT_DIR=<directory to download the pretrained model>
7+
mkdir -p $CHECKPOINT_DIR
8+
cd <package dir>
9+
bash download_model.sh
810
```
911

1012
After you've downloaded the pretrained model and followed the instructions to
@@ -22,7 +24,7 @@ cd <package dir>
2224
2325
# Set the required environment vars
2426
export DATASET_DIR=<path to the dataset>
25-
export PRETRAINED_MODEL=<path to the rnnt.pt file>
27+
export CHECKPOINT_DIR=<path to the downloaded model weights directory>
2628
export PRECISION=<specify the precision to run (fp32 or bf16)>
2729
export OUTPUT_DIR=<directory where log files will be written>
2830

quickstart/language_modeling/pytorch/rnnt/inference/cpu/.docs/quickstart.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
| Script name | Description |
55
|-------------|-------------|
6-
| `download_inference_dataset.sh` | Download and prepare the LibriSpeech inference dataset. See the [datasets section](#datasets) for instructions on it's usage. |
6+
| `download_dataset.sh` | Download and prepare the LibriSpeech inference dataset. See the [datasets section](#datasets) for instructions on it's usage. |
77
| `inference_realtime.sh` | Runs multi-instance inference using 4 cores per instance for the specified precision (fp32, avx-fp32, or bf16). |
88
| `inference_throughput.sh` | Runs multi-instance inference using 1 instance per socket for the specified precision (fp32, avx-fp32, or bf16). |
99
| `accuracy.sh` | Runs an inference accuracy test for the specified precision (fp32, avx-fp32, or bf16). |

quickstart/language_modeling/pytorch/rnnt/inference/cpu/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Follow [link](/docs/general/pytorch/BareMetalSetup.md) to install Conda and buil
1919
* Download and preprocess RNN-T dataset:
2020
```bash
2121
export DATASET_DIR=#Where_to_save_Dataset
22-
bash ${MODEL_DIR}/quickstart/language_modeling/pytorch/rnnt/inference/cpu/download_dataset_baremetal.sh
22+
bash ${MODEL_DIR}/quickstart/language_modeling/pytorch/rnnt/inference/cpu/download_dataset.sh
2323
```
2424

2525
* Download pretrained model
2626
```bash
2727
export CHECKPOINT_DIR=#Where_to_save_pretrained_model
28-
bash ${MODEL_DIR}/quickstart/language_modeling/pytorch/rnnt/inference/cpu/download_model_baremetal.sh
28+
bash ${MODEL_DIR}/quickstart/language_modeling/pytorch/rnnt/inference/cpu/download_model.sh
2929
```
3030

3131
* Set Jemalloc Preload for better performance
@@ -52,8 +52,8 @@ Follow [link](/docs/general/pytorch/BareMetalSetup.md) to install Conda and buil
5252

5353
| DataType | Throughput | Latency | Accuracy |
5454
| ----------- | ----------- | ----------- | ----------- |
55-
| FP32 | bash batch_inference_baremetal.sh fp32 | bash online_inference_baremetal.sh fp32 | bash accuracy_baremetal.sh fp32 |
56-
| BF16 | bash batch_inference_baremetal.sh bf16 | bash online_inference_baremetal.sh bf16 | bash accuracy_baremetal.sh bf16 |
55+
| FP32 | bash inference_throughput.sh fp32 | bash inference_realtime.sh fp32 | bash accuracy.sh fp32 |
56+
| BF16 | bash inference_throughput.sh bf16 | bash inference_realtime.sh bf16 | bash accuracy.sh bf16 |
5757

5858
## Run the model
5959

@@ -76,7 +76,7 @@ export DATASET_DIR=<path to the dataset>
7676
7777
# Run a quickstart script (for example, FP32 batch inference)
7878
cd ${MODEL_DIR}/quickstart/language_modeling/pytorch/rnnt/inference/cpu
79-
bash batch_inference_baremetal.sh fp32
79+
bash inference_throughput.sh fp32
8080
```
8181

8282
<!--- 80. License -->

quickstart/language_modeling/pytorch/rnnt/inference/cpu/README_SPR.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pytorch-spr-rnnt-inference
2929

3030
| Script name | Description |
3131
|-------------|-------------|
32-
| `download_inference_dataset.sh` | Download and prepare the LibriSpeech inference dataset. See the [datasets section](#datasets) for instructions on it's usage. |
32+
| `download_dataset.sh` | Download and prepare the LibriSpeech inference dataset. See the [datasets section](#datasets) for instructions on it's usage. |
3333
| `inference_realtime.sh` | Runs multi-instance inference using 4 cores per instance for the specified precision (fp32, avx-fp32, or bf16). |
3434
| `inference_throughput.sh` | Runs multi-instance inference using 1 instance per socket for the specified precision (fp32, avx-fp32, or bf16). |
3535
| `accuracy.sh` | Runs an inference accuracy test for the specified precision (fp32, avx-fp32, or bf16). |
@@ -83,19 +83,21 @@ docker run --rm \
8383
-w /workspace/pytorch-spr-rnnt-inference \
8484
-it \
8585
model-zoo:pytorch-spr-rnnt-inference \
86-
/bin/bash quickstart/download_inference_dataset.sh
86+
/bin/bash quickstart/download_dataset.sh
8787
```
8888

8989
This `DATASET_DIR` environment variable will be used again when
9090
[running the model](#run-the-model).
9191

9292
## Run the model
9393

94-
Download the pretrained model and set the `PRETRAINED_MODEL` environment variable
95-
to point to the file:
94+
Set the `CHECKPOINT_DIR` environment variable and run the script to download the
95+
pretrained model:
9696
```
97-
wget https://zenodo.org/record/3662521/files/DistributedDataParallel_1576581068.9962234-epoch-100.pt?download=1 -O rnnt.pt
98-
export PRETRAINED_MODEL=$(pwd)/rnnt.pt
97+
export CHECKPOINT_DIR=<directory to download the pretrained model>
98+
mkdir -p $CHECKPOINT_DIR
99+
cd pytorch-spr-rnnt-inference
100+
bash download_model.sh
99101
```
100102

101103
After you've downloaded the pretrained model and followed the instructions to
@@ -113,7 +115,7 @@ cd pytorch-spr-rnnt-inference
113115
114116
# Set the required environment vars
115117
export DATASET_DIR=<path to the dataset>
116-
export PRETRAINED_MODEL=<path to the rnnt.pt file>
118+
export CHECKPOINT_DIR=<path to the downloaded model weights directory>
117119
export PRECISION=<specify the precision to run (fp32 or bf16)>
118120
export OUTPUT_DIR=<directory where log files will be written>
119121
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2021 Intel Corporation
3+
# Copyright (c) 2020 Intel Corporation
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -17,47 +17,62 @@
1717

1818
MODEL_DIR=${MODEL_DIR-$PWD}
1919

20-
echo "PRETRAINED_MODEL: ${PRETRAINED_MODEL}"
21-
echo "DATASET_DIR: ${DATASET_DIR}"
22-
echo "PRECISION: ${PRECISION}"
23-
echo "OUTPUT_DIR: ${OUTPUT_DIR}"
24-
25-
if [ -z "${OUTPUT_DIR}" ]; then
26-
echo "The required environment variable OUTPUT_DIR has not been set"
20+
if [ ! -e "${MODEL_DIR}/models/language_modeling/pytorch/rnnt/inference/cpu/inference.py" ]; then
21+
echo "Could not find the script of inference.py. Please set environment variable '\${MODEL_DIR}'."
22+
echo "From which the inference.py exist at the: \${MODEL_DIR}/models/language_modeling/pytorch/rnnt/inference/cpu/inference.py"
2723
exit 1
2824
fi
2925

30-
# Create the output directory in case it doesn't already exist
31-
mkdir -p ${OUTPUT_DIR}
32-
33-
if [ -z "${DATASET_DIR}" ]; then
34-
echo "The required environment variable DATASET_DIR has not been set"
26+
if [ ! -e "${CHECKPOINT_DIR}/results/rnnt.pt" ]; then
27+
echo "The pretrained model \${CHECKPOINT_DIR}/results/rnnt.pt does not exist"
3528
exit 1
3629
fi
3730

38-
if [ ! -d "${DATASET_DIR}" ]; then
39-
echo "The DATASET_DIR '${DATASET_DIR}' does not exist"
31+
if [ ! -d "${DATASET_DIR}/dataset/LibriSpeech" ]; then
32+
echo "The DATASET_DIR \${DATASET_DIR}/dataset/LibriSpeech does not exist"
4033
exit 1
4134
fi
4235

43-
if [ -z "${PRECISION}" ]; then
44-
echo "The required environment variable PRECISION has not been set"
45-
echo "Please set PRECISION to fp32, avx-fp32, or bf16."
36+
if [ ! -d "${OUTPUT_DIR}" ]; then
37+
echo "The OUTPUT_DIR '${OUTPUT_DIR}' does not exist"
4638
exit 1
4739
fi
4840

49-
cd ${MODEL_DIR}/models/rnnt/training/rnn_speech_recognition/pytorch
50-
export work_space=${OUTPUT_DIR}
51-
52-
if [[ $PRECISION == "avx-fp32" ]]; then
41+
if [[ "$1" == *"avx"* ]]; then
5342
unset DNNL_MAX_CPU_ISA
54-
PRECISION=fp32
5543
fi
5644

57-
if [[ $PRECISION == "bf16" || $PRECISION == "fp32" ]]; then
58-
bash run_inference_cpu_accuracy_ipex.sh ${DATASET_DIR} ${PRETRAINED_MODEL} ipex ${PRECISION} jit 2>&1 | tee -a ${OUTPUT_DIR}/rnnt-inference-accuracy-${PRECISION}.log
45+
ARGS=""
46+
if [ "$1" == "bf16" ]; then
47+
ARGS="$ARGS --mix-precision"
48+
echo "### running bf16 datatype"
5949
else
60-
echo "The specified precision '${PRECISION}' is unsupported."
61-
echo "Supported precisions are: fp32, avx-fp32, and bf16"
62-
exit 1
50+
echo "### running fp32 datatype"
6351
fi
52+
53+
export DNNL_PRIMITIVE_CACHE_CAPACITY=1024
54+
export KMP_BLOCKTIME=1
55+
export KMP_AFFINITY=granularity=fine,compact,1,0
56+
57+
BATCH_SIZE=64
58+
PRECISION=$1
59+
60+
rm -rf ${OUTPUT_DIR}/rnnt_${PRECISION}_inference_accuracy*
61+
62+
python -m intel_extension_for_pytorch.cpu.launch \
63+
--use_default_allocator \
64+
${MODEL_DIR}/models/language_modeling/pytorch/rnnt/inference/cpu/inference.py \
65+
--dataset_dir ${DATASET_DIR}/dataset/LibriSpeech/ \
66+
--val_manifest ${DATASET_DIR}/dataset/LibriSpeech/librispeech-dev-clean-wav.json \
67+
--model_toml ${MODEL_DIR}/models/language_modeling/pytorch/rnnt/inference/cpu/configs/rnnt.toml \
68+
--ckpt ${CHECKPOINT_DIR}/results/rnnt.pt \
69+
--batch_size $BATCH_SIZE \
70+
--ipex \
71+
--jit \
72+
$ARGS 2>&1 | tee ${OUTPUT_DIR}/rnnt_${PRECISION}_inference_accuracy.log
73+
74+
# For the summary of results
75+
wait
76+
77+
accuracy=$(grep 'Accuracy:' ${OUTPUT_DIR}/rnnt_${PRECISION}_inference_accuracy* |sed -e 's/.*Accuracy//;s/[^0-9.]//g')
78+
echo ""RNN-T";"accuracy";$1; ${BATCH_SIZE};${accuracy}" | tee -a ${OUTPUT_DIR}/summary.log

quickstart/language_modeling/pytorch/rnnt/inference/cpu/accuracy_baremetal.sh

-73
This file was deleted.

0 commit comments

Comments
 (0)