ASR finetuning/training 7x slower on v1.8.2
Describe the bug
I recently updated from NeMo 1.7.2 to 1.8.2
When running a training session, the speed is now 4.04s/it whereas it used to be 2.97it/s.
Note it's taking ~4 seconds per iteration whereas it used to be ~3 iterations per second!
Here's my trainer config since it's the only things that's different from the NeMo examples config for CitriNet-1024 with SPE tokenizer:
trainer:
devices: 8
accelerator: gpu
max_epochs: 100
max_steps: -1
num_nodes: 1
strategy: ddp
accumulate_grad_batches: 4
enable_checkpointing: false # Provided by exp_manager
logger: false # Provided by exp_manager
log_every_n_steps: 100
val_check_interval: 1.0
precision: 16
Steps/Code to reproduce bug
Run any training example script.
Expected behavior
Speed should not be significantly affected.
Environment overview (please complete the following information)
- Environment location: Docker (tried
nvcr.io/nvidia/pytorch:22.03-py3andnvcr.io/nvidia/pytorch:22.02-py3) - Method of NeMo install:
pip install nemo_toolkit[all]==1.8.2 - If method of install is [Docker], provide
docker pull&docker runcommands used
docker run --rm -it --gpus all --ipc=host --env-file .env train
Additional context
Running this on an AWS p3dn.24xlarge instance (8xV100)
Are you providing num_workers to your train_ds config ?
Yes, my train_ds config looks like this:
train_ds:
manifest_filepath: "/path/to/manifest.json"
sample_rate: *sample_rate
max_duration: 31
batch_size: 8
num_workers: 16
trim_silence: false
use_dali: false
shuffle: true
is_tarred: false
pin_memory: false
Is the comparison between a container built with Nemo 1.7x on 22.01 and Nemo 1.8x with 22.03? I dunno if it would work properly but could you try Nemo 1.8x with 22.01 container?
We've done some speed checks on these containers and have noticed some speed issues, however nothing so drastic as 7x slowdown.
And I'll review if there were any significant modifications to ASR training between the two versions but I've not found any code that could have affected Citrinets (there were many changes to Conformers but not the Jasper family of models).
Is the comparison between a container built with Nemo 1.7x on 22.01 and Nemo 1.8x with 22.03?
No, it was between 22.02 and 22.03, however I can try 1.8x with 22.01 and report back.
Maybe something to do with PyTorch or PyTorch lightning since I noticed those two were bumped up (both in the repo requirements and in the container).
Unfortunately similar behavior with NeMo 1.8x and container version 22.01.
This time though, the speed settles on ~3.44s/it (slight improvement to the newer containers).
Are you sure that your script (configs) are exactly the same when you do the speed testing? Let's reduce the num_workers to 4, and also disable the grad accumulation and try again.
Following up. I did some checking and could not se an obvious slowdown between 1.7.2, 1.8.2 (installed over 22.03) and the head after training for two epochs from scratch on librispeech. Could you share any additional details to reproduce? Thank you.
@VahidooX Will try your suggestions and report back. @bmwshop will work on compiling a full breakdown of differences between both versions, but the script is def. constant between both versions.
@piraka9011 appreciate it. I see no difference at all between the three versions tested, ran for 2 full epochs on a DGX-1 with 8x V100 32GB. could it be related to startup effects that quiesce over time?

Also make sure that you set log_every_n_steps and progress_bar_refresh_rate to a large enough number like 100. Using small number makes training very slow.
could it be related to startup effects that quiesce over time
This is possible!
Also make sure that you set log_every_n_steps and progress_bar_refresh_rate to a large enough number like 100. Using small number makes training very slow.
I see! Will try this too.
AWS resources are currently a bit starved, so will post once I get an instance up again.
I am now trying this on a p4dn instance (8x A100) and disabled accumulate_grad_batches:
trainer:
gpus: -1
max_epochs: 90
max_steps: -1
num_nodes: 1
strategy: ddp
# accumulate_grad_batches: 1
checkpoint_callback: false
logger: false
log_every_n_steps: 100
val_check_interval: 1.0
check_val_every_n_epoch: 1
precision: 16
Performance is still very slow. But will leave for a few epochs to see if it makes a difference after.
When accumulate_grad_batches is disabled, the startup is slow, but it eventually speeds up from 4.04s/it to 1.0s/it by 1400 steps (batch size 16).
By the end of the epoch (3500 steps) it's at 1.3it/s.
At the second epoch, training quickly ramps up from 1.3it/s to 2.23it/s. Still not as fast as NeMo 1.7.2 though
It seems this is also some issue with startup, but it would be good to understand why that is the case and how to improve this? Is there a difference for example using Tar manifests vs. file manifests?
Tarred Datasets are meant for clusters - or large datasets with hundreds of thousands of files. You are probably hitting network io as your slowdown, and after an epoch the instance cashes the dataset into memory (either fully or partially) which speeds up your training to normal levels.
You are probably hitting network io as your slowdown
How is there a network I/O slowdown when the data is already downloaded?
And why is this occurring in v1.8.x and not v1.7.x? The only major change I've seen to the models is the infra around it (PyTorch/Lightning).
Reading 100k files vs 1024 tar files is very different behaviour for networked IO - all cloud providers don't physically attach storage to your vms, they use mounted network storage. This is the cost - since to manage and manipulate 100k files is much harder for network file systems than just managing 1024 tarfiles.
all cloud providers don't physically attach storage to your vms, they use mounted network storage.
I see... I did not know that! Thank you for clarifying this. I will try another training run but with a tarred dataset and see if that improves performance. We do have ~500k individual files, so what you're suggesting makes sense.
If this is indeed the case, would be something good to point out in the docs that JSON manifests may incur a slowdown after ~100k files, esp. if you are using a cloud provider/network storage? (Maybe here?)
Ok, it looks like tarred datasets definitely result in a speed up to training as suggested. The first epoch is still slower (for me it went from ~40 min/epoch to 6 min/epoch) but the following epoch is significantly faster (from 20-25 min/epoch to 2 min/epoch).
Thanks again for helping me debug this.
Two things before closing the issue though:
- Should validation manifests also be tarred? or that doesn't matter?
- The epoch now only completes partially before starting validation Here's an example of what this looks like. Is this expected?
Epoch 3: 23%|█████████████████▌ | 221/981 [01:25<04:53, 2.59it/s, loss=614, v_num=0-55]
Epoch 3, global step 112: 'val_wer' reached 1.03452 (best 1.03452), saving model to '/home/ubuntu/tdreeb/experiments/CnLgGm025_SpeUni1024_DI_EATL/2022-05-21_21-20-55/checkpoints/CnLgGm025_SpeUni1024_DI_EATL--val_wer=1.0345-epoch=3.ckpt' as top 2
Validation and test datasets are never tarred. We actually explicitly do not support it because tarring drops a few samples, and therefore fair academic comparisons would be impossible. Usually validation and test datasets are run infrequently - once every epoch, and are orders of magnitude smaller than the train set so it makes sense to leave them as loose files.
Re incomplete epoch, No this is not expected. We see full epoch completion with tarred datasets same as with normal datasets, even step per epoch should be roughly same (+- a little due to file dropping). Do you have val check interval < 1.0?
Agreed with your point regarding documentation, will update next week.