Skip to content

Commit 10e8059

Browse files
committed
[Jasper/PyT] Updated notebooks
1 parent 2fec868 commit 10e8059

8 files changed

Lines changed: 62 additions & 76 deletions

File tree

‎PyTorch/SpeechRecognition/Jasper/notebooks/JasperTRT.ipynb‎

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"cell_type": "markdown",
2727
"metadata": {},
2828
"source": [
29-
"<img src=\"img/nvidia_logo.png\" style=\"width: 90px; float: right;\">\n",
29+
"<img src=http://developer.download.nvidia.com/compute/machine-learning/frameworks/nvidia_logo.png style=\"width: 90px; float: right;\">\n",
3030
"\n",
3131
"# Jasper Inference For TensorRT 6\n",
3232
"This Jupyter notebook provides scripts to perform high-performance inference using NVIDIA TensorRT. \n",
@@ -88,17 +88,6 @@
8888
"### 3.1 Start a detached session in the NGC container"
8989
]
9090
},
91-
{
92-
"cell_type": "code",
93-
"execution_count": null,
94-
"metadata": {},
95-
"outputs": [],
96-
"source": [
97-
"DATA_DIR=\"$PWD/../data\" # replace with absolute path to dataset root folder that contains various datasets. E.g. this path should contain LibriSpeech as subfolder\n",
98-
"CHECKPOINT_DIR=\"$PWD/../checkpoints\" # replace with absolute path to checkpoint folder. Following code assumes this folder to contain 'jasper_fp16.pt'\n",
99-
"RESULT_DIR=\"$PWD/../results\" # replace with absolute path to result folder, where log files and prediction files will be saved after inference."
100-
]
101-
},
10291
{
10392
"cell_type": "code",
10493
"execution_count": null,
@@ -110,17 +99,18 @@
11099
" --shm-size=4g \\\n",
111100
" --ulimit memlock=-1 \\\n",
112101
" --ulimit stack=67108864 \\\n",
113-
" -v $DATA_DIR:/datasets \\\n",
114-
" -v $CHECKPOINT_DIR:/checkpoints/ \\\n",
115-
" -v $RESULT_DIR:/results/ \\\n",
102+
" -v $PWD/data:/datasets \\\n",
103+
" -v $PWD/checkpoint:/checkpoints/ \\\n",
104+
" -v $PWD/result:/results/ \\\n",
105+
" -v $PWD:/workspace/jasper/ \\\n",
116106
" jasper:trt6 bash"
117107
]
118108
},
119109
{
120110
"cell_type": "markdown",
121111
"metadata": {},
122112
"source": [
123-
"You can also specify the GPU to run the container on by adding \\\"NV_GPU\\\" before the \\\"nvidia-docker run\\\" command. For example, to specify GPU ID 0 to run the container, add \\\"NV_GPU=0\\\" before the \\\"nvidia-docker run\\\" command. You can use the command \\\"nvidia-smi\\\" to check your GPU IDs and utilization"
113+
"You can also specify single or multiple GPUs to run the container by adding \"NV_GPU\" before the \"nvidia-docker run\" command. For example, to specify GPU ID 2 to run the container, add \"NV_GPU=2\" before the \"nvidia-docker run\" command. You can use the command \"nvidia-smi\" to check your GPU IDs and utilization."
124114
]
125115
},
126116
{
@@ -129,22 +119,17 @@
129119
"metadata": {},
130120
"outputs": [],
131121
"source": [
132-
"!NV_GPU=0 nvidia-docker run -it -d --rm --name \"JasperTRT\" \\\n",
133-
" --runtime=nvidia \\\n",
134-
" --shm-size=4g \\\n",
135-
" --ulimit memlock=-1 \\\n",
136-
" --ulimit stack=67108864 \\\n",
137-
" -v $DATA_DIR:/datasets \\\n",
138-
" -v $CHECKPOINT_DIR:/checkpoints/ \\\n",
139-
" -v $RESULT_DIR:/results/ \\\n",
140-
" jasper:trt6 bash"
122+
"#check the container that you just started\n",
123+
"!docker ps -a"
141124
]
142125
},
143126
{
144127
"cell_type": "markdown",
145128
"metadata": {},
146129
"source": [
147130
"### 3.2 Download and preprocess the dataset.\n",
131+
"You will not need to download the dataset if you directly go to Section 5 to play with audio examples.\n",
132+
"\n",
148133
"If LibriSpeech http://www.openslr.org/12 has already been downloaded and preprocessed, no further steps in this subsection need to be taken.\n",
149134
"If LibriSpeech has not been downloaded already, note that only a subset of LibriSpeech is typically used for inference (dev-* and test-*). LibriSpeech contains 1000 hours of 16kHz read English speech derived from public domain audiobooks from LibriVox project and has been carefully segmented and aligned. For more information, see paper [LIBRISPEECH: AN ASR CORPUS BASED ON PUBLIC DOMAIN AUDIO BOOKS paper](http://www.danielpovey.com/files/2015_icassp_librispeech.pdf).\n",
150135
"To acquire the inference subset of LibriSpeech run (does not require GPU):"
@@ -205,16 +190,7 @@
205190
"cell_type": "markdown",
206191
"metadata": {},
207192
"source": [
208-
"### 3.3 Download pretrained model checkpoint\n",
209-
"A pretrained model checkpoint can be downloaded from NGC model repository https://ngc.nvidia.com/catalog/models/nvidia:jasperpyt_fp16\n",
210-
" \n"
211-
]
212-
},
213-
{
214-
"cell_type": "markdown",
215-
"metadata": {},
216-
"source": [
217-
"### 3.4. Start TensorRT inference prediction\n",
193+
"### 3.3. Start TensorRT inference prediction\n",
218194
"\n",
219195
"Inside the container, use the following script to run inference with TensorRT.\n",
220196
"You will need to set the parameters such as: \n",
@@ -244,7 +220,7 @@
244220
"cell_type": "markdown",
245221
"metadata": {},
246222
"source": [
247-
" ### 3.5. Start TensorRT Inference Benchmark\n",
223+
" ### 3.4. Start TensorRT Inference Benchmark\n",
248224
"\n",
249225
"Run the following commmand to run inference benchmark with TensorRT inside the container.\n",
250226
"\n",
@@ -299,14 +275,14 @@
299275
"metadata": {},
300276
"outputs": [],
301277
"source": [
302-
"!nvidia-docker exec -it -e CHECKPOINT=/checkpoints/jasper_fp16.pt -e TRT_PREDICTION_PATH=/results/benchmark.txt -e TRT_PRECISION=fp16 -e PYTORCH_PRECISION=fp16 -e CSV_PATH=/results/res_fp16.csv JasperTRT bash trt/scripts/trt_inference_benchmark.sh"
278+
"!nvidia-docker exec -it -e CHECKPOINT=/checkpoints/jasper_fp16.pt -e TRT_PREDICTION_PATH=/results/benchmark.txt -e TRT_PRECISION=fp16 -e PYTORCH_PRECISION=fp16 -e CSV_PATH=/result/res_fp16.csv JasperTRT bash trt/scripts/trt_inference_benchmark.sh"
303279
]
304280
},
305281
{
306282
"cell_type": "markdown",
307283
"metadata": {},
308284
"source": [
309-
"From the performance metrics that you get from res.csv (fp32) and res_fp16.csv (automatic mixed precision) files, you can see that automatic mixed precision can speedup the inference efficiently compared to fp32."
285+
"From the performance metrics (pyt_infer) that you get from res.csv (for fp32) and res_fp16.csv (for automatic mixed precision) files, you can see that automatic mixed precision can speedup the inference efficiently compared to fp32."
310286
]
311287
},
312288
{
@@ -315,7 +291,7 @@
315291
"source": [
316292
"### 5. Play with audio examples\n",
317293
"\n",
318-
"You can perform inference using pre-trained checkpoints which takes audio file (in .wav format) as input, and produces the corresponding text file. You can customize the content of the text file. For example, there are examples of audio files in \\\"notebooks\\\" directory and we can listen to keynote.wav"
294+
"You can perform inference using pre-trained checkpoints which takes audio file (in .wav format) as input, and produces the corresponding text file. You can customize the content of the text file. For example, there are several examples of input files at \"notebooks\" dirctory and we can listen to example1.wav:"
319295
]
320296
},
321297
{
@@ -325,7 +301,7 @@
325301
"outputs": [],
326302
"source": [
327303
"import IPython.display as ipd\n",
328-
"ipd.Audio('keynote.wav', rate=22050)"
304+
"ipd.Audio('notebooks/example1.wav', rate=22050)"
329305
]
330306
},
331307
{
@@ -334,9 +310,9 @@
334310
"source": [
335311
"You can run inference using the trt/perf.py script:\n",
336312
"* the checkpoint is passed as `--ckpt` argument \n",
337-
"* `--model_toml` specifies the path to network configuration file (see examples in \\\"config\\\" directory)\n",
313+
"* `--model_toml` specifies the path to network configuration file (see examples in \"config\" directory)\n",
338314
"* `--make_onnx` exports to ONNX file at the path if set\n",
339-
"* `--engine_path` saves the engine (*.plan) file.\n",
315+
"* `--engine_path` saves the engine file (*.plan) \n",
340316
"\n",
341317
"To create a new engine file (jasper.plan) for TensorRT and run it using fp32 (building the engine for the first time can take several minutes):"
342318
]
@@ -347,7 +323,7 @@
347323
"metadata": {},
348324
"outputs": [],
349325
"source": [
350-
"!nvidia-docker exec -it JasperTRT python trt/perf.py --ckpt_path /checkpoints/jasper_fp16.pt --wav=notebooks/keynote.wav --model_toml=configs/jasper10x5dr_nomask.toml --make_onnx --onnx_path jasper.onnx --engine_path jasper.plan"
326+
"!nvidia-docker exec -it JasperTRT python trt/perf.py --ckpt_path /checkpoints/jasper_fp16.pt --wav=notebooks/example1.wav --model_toml=configs/jasper10x5dr_nomask.toml --make_onnx --onnx_path jasper.onnx --engine_path jasper.plan"
351327
]
352328
},
353329
{
@@ -363,7 +339,7 @@
363339
"metadata": {},
364340
"outputs": [],
365341
"source": [
366-
"!nvidia-docker exec -it JasperTRT python trt/perf.py --wav=notebooks/keynote.wav --model_toml=configs/jasper10x5dr_nomask.toml --use_existing_engine --engine_path jasper.plan --trt_fp16"
342+
"!nvidia-docker exec -it JasperTRT python trt/perf.py --wav=notebooks/example1.wav --model_toml=configs/jasper10x5dr_nomask.toml --use_existing_engine --engine_path jasper.plan --trt_fp16"
367343
]
368344
},
369345
{
@@ -379,7 +355,7 @@
379355
"metadata": {},
380356
"outputs": [],
381357
"source": [
382-
"!nvidia-docker exec -it JasperTRT python trt/perf.py --ckpt_path /checkpoints/jasper_fp16.pt --wav=notebooks/keynote.wav --model_toml=configs/jasper10x5dr_nomask.toml --make_onnx --onnx_path jasper.onnx --engine_path jasper_fp16.plan --trt_fp16"
358+
"!nvidia-docker exec -it JasperTRT python trt/perf.py --ckpt_path /checkpoints/jasper_fp16.pt --wav=notebooks/example1.wav --model_toml=configs/jasper10x5dr_nomask.toml --make_onnx --onnx_path jasper.onnx --engine_path jasper_fp16.plan --trt_fp16"
383359
]
384360
},
385361
{
@@ -395,14 +371,14 @@
395371
"metadata": {},
396372
"outputs": [],
397373
"source": [
398-
"!nvidia-docker exec -it JasperTRT python trt/perf.py --wav=notebooks/keynote.wav --model_toml=configs/jasper10x5dr_nomask.toml --use_existing_engine --engine_path jasper_fp16.plan --trt_fp16"
374+
"!nvidia-docker exec -it JasperTRT python trt/perf.py --wav=notebooks/example1.wav --model_toml=configs/jasper10x5dr_nomask.toml --use_existing_engine --engine_path jasper_fp16.plan --trt_fp16"
399375
]
400376
},
401377
{
402378
"cell_type": "markdown",
403379
"metadata": {},
404380
"source": [
405-
"You can also input your own audio files and generate the output text files in this way.\n",
381+
"You can play with other examples at \"notebooks\" dirctory. You can also input your own audio files and generate the output text files in this way.\n",
406382
"\n",
407383
"For more information about TensorRT and building an engine file in Python, please see: https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#python_topics"
408384
]
@@ -448,7 +424,7 @@
448424
"name": "python",
449425
"nbconvert_exporter": "python",
450426
"pygments_lexer": "ipython3",
451-
"version": "3.7.3"
427+
"version": "3.6.8"
452428
}
453429
},
454430
"nbformat": 4,
Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,74 @@
1+
# Jasper notebook
2+
13
## Overview
24

3-
This notebook provides scripts for you to run Jasper with TRT for inference step by step. You can run inference using either LibriSpeech dataset or your own audio input in .wav format, to generate the corresponding text file for the audio file.
5+
This notebook provides scripts for you to run Jasper with TRT for inference step by step. You can run inference using either LibriSpeech dataset or your own audio input in .wav format, to generate the corresponding text file for the audio file.
46

57
## Requirements
68

79
This repository contains a Dockerfile which extends the PyTorch 19.09-py3 NGC container and encapsulates some dependencies. Aside from these dependencies, ensure you have the following components:
8-
9-
* [NVIDIA Docker](https://github.com/NVIDIA/nvidia-docker)
10-
* [PyTorch 19.09-py3 NGC container](https://ngc.nvidia.com/catalog/containers/nvidia:pytorch)
11-
* [NVIDIA Turing](https://www.nvidia.com/en-us/geforce/turing/) or [Volta](https://www.nvidia.com/en-us/data-center/volta-gpu-architecture/) based GPU
12-
* [Pretrained Jasper Model Checkpoint](https://ngc.nvidia.com/catalog/models/nvidia:jasperpyt_fp16)
10+
11+
- NVIDIA Docker
12+
- PyTorch 19.09-py3 NGC container
13+
- NVIDIA Turing or Volta based GPU
14+
- Pretrained Jasper Model Checkpoint
1315

1416
## Quick Start Guide
1517

1618
Running the following scripts will build and launch the container containing all required dependencies for both TensorRT as well as native PyTorch. This is necessary for using inference with TensorRT and can also be used for data download, processing and training of the model.
1719

18-
1. Clone the repository.
20+
#### 1. Clone the repository.
1921

20-
```bash
22+
```
2123
git clone https://github.com/NVIDIA/DeepLearningExamples
2224
cd DeepLearningExamples/PyTorch/SpeechRecognition/Jasper
2325
```
24-
2. Build the Jasper PyTorch with TRT 6 container:
2526

26-
```bash
27+
#### 2. Build the Jasper PyTorch with TRT 6 container:
28+
29+
```
2730
bash trt/scripts/docker/trt_build.sh
2831
```
29-
3. Prepare to start a detached session in the NGC container
32+
33+
#### 3. Create directories
34+
Prepare to start a detached session in the NGC container.
3035
Create three directories on your local machine for dataset, checkpoint, and result, respectively, naming "data" "checkpoint" "result":
3136

32-
```bash
37+
```
3338
mkdir data checkpoint result
3439
```
35-
Download the checkpoint file `jasperpyt_fp16` to the directory `checkpoint` from NGC Model Repository: https://ngc.nvidia.com/catalog/models/nvidia:jasperpyt_fp16
36-
Assume you will download the dataset to /dev/sdb and mount the data on /dev/sdb to "data", please replace "/dev/sdb" with your own directories if you use other directories:
3740

38-
```bash
39-
sudo mount /dev/sdb data
40-
```
41-
The Jasper PyTorch container will be launched in the Jupyter notebook. Within the container, the contents of the root repository will be copied to the /workspace/jasper directory. The /datasets, /checkpoints, /results directories are mounted as volumes and mapped to the corresponding directories "data" "checkpoint" "result" on the host.
41+
#### 4. Download the checkpoint
42+
Download the checkpoint file jasperpyt_fp16 from NGC Model Repository:
43+
- https://ngc.nvidia.com/catalog/models/nvidia:jasperpyt_fp16
44+
45+
to the directory: _checkpoint_
46+
47+
The Jasper PyTorch container will be launched in the Jupyter notebook. Within the container, the contents of the root repository will be copied to the /workspace/jasper directory.
4248

43-
Copy the JasperTRT.ipynb notebook to the root directory of Jasper:
44-
```bash
49+
The /datasets, /checkpoints, /results directories are mounted as volumes and mapped to the corresponding directories "data" "checkpoint" "result" on the host.
50+
51+
#### 5. Copy the notebook to the root
52+
53+
Copy the notebook to the root directory of Jasper:
54+
55+
```
4556
cp notebooks/JasperTRT.ipynb .
4657
```
4758

59+
#### 6. Run the notebook
4860
For running the notebook on your local machine, run:
4961

50-
```bash
62+
```
5163
jupyter notebook JasperTRT.ipynb
5264
```
53-
For running the notebook on another machine remotely, run:
5465

55-
```bash
66+
For running the notebook on another machine remotely, run:
67+
68+
```
5669
jupyter notebook --ip=0.0.0.0 --allow-root
5770
```
58-
And navigate a web browser to the IP address or hostname of the host machine at port 8888: http://[host machine]:8888
59-
60-
Use the token listed in the output from running the jupyter command to log in, for example: http://[host machine]:8888/?token=aae96ae9387cd28151868fee318c3b3581a2d794f3b25c6b
61-
6271

72+
And navigate a web browser to the IP address or hostname of the host machine at port 8888: `http://[host machine]:8888`
6373

74+
Use the token listed in the output from running the jupyter command to log in, for example: `http://[host machine]:8888/?token=aae96ae9387cd28151868fee318c3b3581a2d794f3b25c6b`
314 KB
Binary file not shown.
451 KB
Binary file not shown.
511 KB
Binary file not shown.
309 KB
Binary file not shown.

‎PyTorch/SpeechRecognition/Jasper/notebooks/keynote.wav‎

100755100644
File mode changed.

‎PyTorch/SpeechRecognition/Jasper/trt/Dockerfile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
ARG FROM_IMAGE_NAME=nvcr.io/nvidia/pytorch:19.09-py3
32
FROM ${FROM_IMAGE_NAME}
43

0 commit comments

Comments
 (0)