|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | #
|
3 |
| -# Copyright (c) 2021 Intel Corporation |
| 3 | +# Copyright (c) 2020 Intel Corporation |
4 | 4 | #
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | # you may not use this file except in compliance with the License.
|
|
17 | 17 |
|
18 | 18 | MODEL_DIR=${MODEL_DIR-$PWD}
|
19 | 19 |
|
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" |
27 | 23 | exit 1
|
28 | 24 | fi
|
29 | 25 |
|
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" |
35 | 28 | exit 1
|
36 | 29 | fi
|
37 | 30 |
|
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" |
40 | 33 | exit 1
|
41 | 34 | fi
|
42 | 35 |
|
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" |
46 | 38 | exit 1
|
47 | 39 | fi
|
48 | 40 |
|
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 |
53 | 42 | unset DNNL_MAX_CPU_ISA
|
54 |
| - PRECISION=fp32 |
55 | 43 | fi
|
56 | 44 |
|
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" |
59 | 49 | 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" |
63 | 51 | 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 |
0 commit comments