espnet icon indicating copy to clipboard operation
espnet copied to clipboard

GPU vs CPU decoding

Open abnerLing opened this issue 5 years ago • 9 comments

Why might CPU decoding be quicker than GPU decoding (specifically for ESPnet2)? When decoding on CPU with 7.4min of audio files it took about 45sec but with GPU it took 185sec. I'm using a Quadro RTX 8000 with 48G of memory and not using the GPU for any other processes, so I'm not sure what may cause the slowness?

abnerLing avatar Dec 23 '20 02:12 abnerLing

Some observations (espnet not espnet2). On a 7min 30 sec file, CPU 1 core decoding takes 3m8.682s and on a single GPU (V100 32Gb) it takes 1m50.874s. However, the 7min 30 sec is splitted into smaller chunks (20 sec) and then used for decoding. The final ASR op can be concated. So maybe splitting may help.

I am not sure if thats the max improvement we can get using a GPU. Any other parameter, etc we need to change to get better improvements using GPU?

tanvinabpatel avatar Dec 30 '20 05:12 tanvinabpatel

Why might CPU decoding be quicker than GPU decoding (specifically for ESPnet2)? When decoding on CPU with 7.4min of audio files it took about 45sec but with GPU it took 185sec. I'm using a Quadro RTX 8000 with 48G of memory and not using the GPU for any other processes, so I'm not sure what may cause the slowness?

Thanks for your report. Could you explain more about it with an example and exact configuration so that we can reproduce it? Then, we'll investigate it.

Besides some implementation issues, one possible reason is the CTC prefix score calculation. To verify it, could you report the result when ctc_weight=0 (disable CTC prefix scoring) during decoding? The result would be very bad, but if the decoding speed becomes normal, it would be due to the CTC prefix score calculation. We used some thresholding to reduce the CTC prefix score calculation and we need to revisit this.

I am not sure if thats the max improvement we can get using a GPU. Any other parameter, etc we need to change to get better improvements using GPU?

Beam size? Actually, we still have some inefficient GPU usages in our beam search implementation, but we are also caring about the readability and simple coding. You could find a couple of redundant CPU-GPU communications and it requires more code-level optimization (but again it loses the readability and makes the code complicated so that the maintenance of the code and applying a new research idea becomes harder).

sw005320 avatar Dec 31 '20 14:12 sw005320

Thank you for the responses. I realized I was comparing 32 CPU cores vs a single GPU which is not a fair comparison. But when checking with a single CPU core I noticed there is very little difference with speed when using CTC prefix scoring (CPU: 74.5 sec, GPU: 71.3 sec). My decode configuration was set with beam_size=30, lm_weight=0.0, ctc_weight=0.3, however when setting the ctc_weight=0 there is a bigger difference and much faster inference (CPU: 44-45sec, GPU: 28-30sec). The model is a conformer-based architecture.

Another strange finding was that results (as in WER/CER) were mostly the same whether I disabled CTC prefix scoring or not? In both cases the performance had comparable WER/CER (5.1% CER with ctc_weight=0, and 5.0% CER with ctc_weight=0.3). Is this normal?

abnerLing avatar Jan 04 '21 06:01 abnerLing

Beam size?

batchsize: 0, beam-size: 10, ctc-weight: 0.5 Using a transformer architecture.

tanvinabpatel avatar Jan 04 '21 08:01 tanvinabpatel

But when checking with a single CPU core I noticed there is very little difference with speed when using CTC prefix scoring (CPU: 74.5 sec, GPU: 71.3 sec). My decode configuration was set with beam_size=30, lm_weight=0.0, ctc_weight=0.3, however when setting the ctc_weight=0 there is a bigger difference and much faster inference (CPU: 44-45sec, GPU: 28-30sec). The model is a conformer-based architecture.

@takaaki-hori, do you think this is expected behavior?

sw005320 avatar Jan 04 '21 13:01 sw005320

The decoding speed on GPU looks a bit strange to me. In my experience, batchsize: 1 on GPU should be much faster than batchsize: 0 on CPU. But, the CTC prefix scorer actually requires much more computation for longer utterances. So the problem might be due to such long inputs. Can you check the average and max utterance lengths?

takaaki-hori avatar Jan 05 '21 20:01 takaaki-hori

Can you check the average and max utterance lengths?

Average length = 4.5sec, max length = 15sec

@takaaki-hori sorry for the question, but why should we set the batchsize: 0 for CPU decoding (disabling batch decoding?) When testing I found the batchsize: 1 is much faster?

For a single 9sec audio file and ctc_weight=0, lm_weight=0, beam_size=30. (This was tested using the espnet2.bin.asr_inference Speech2Text function. CPU batchsize:0 --> inference speed= 9.92sec CPU batchsize:1 --> inference speed=1.05sec GPU batchsize:1 --> inference speed= 0.597sec

abnerLing avatar Jan 06 '21 01:01 abnerLing

Thanks for the length information. It doesn't seem to be super long. Regarding the batchsize, it is good to use batchsize: 1 for both CPU and GPU decoding. So you no longer have to use batchsize: 0. In my experience, for LibriSpeech dev-clean set, CPU decoding took 2.38 RTF while GPU decoding took 0.31 RTF, where the model consisted of a large Transformer + CTC + Transformer LM (with ESPnet1, beam-size: 20, batchsize: 1, ctc-weight: 0.3, api: v2). In your case, the CPU decoding has already achieved 0.12 RTF (=~ 1.05/9). This looks much different from my case. Is your CPU very fast? Maybe I need more information about the model size, label vocabulary size, the speed when ctc-weight > 0, etc. Actually, I have never checked the decoding speed with Conformer in ESPnet2. So I will check it later.

takaaki-hori avatar Jan 06 '21 03:01 takaaki-hori

Is your CPU very fast? Maybe I need more information about the model size, label vocabulary size, the speed when ctc-weight > 0, etc.

Thank you for your kind reply. I don't think my CPU is unusually fast (Intel Xeon Gold 6234 CPU @ 3.30GHz). The model was trained on about 170 hours of Korean data using mostly the same configuration as the aishell conformer one for ESPnet2. The actual model size is 182M and a label size of 5000 BPE units. When checking the speed with the same 9 sec audio file and using ctc_weight=0.3 I get the below results. CPU batchsize:1 --> inference speed=1.50sec GPU batchsize:1 --> inference speed= 1.36sec And when checking with 100 audio files equaling to about 7.4min I get: 74.5sec with CPU and 71.3sec with GPU. Maybe my method of checking speed is incorrect? I'm using the espnet2.bin.asr_inference's Speech2Text function to check individual audio file inference speed and summing the total. But when simply running "run.sh --stage 11 --stop_stage 11" and checking the elapsed duration there is a bigger difference (CPU: 192sec, GPU:98sec) for the same 7.4min audio set.

abnerLing avatar Jan 07 '21 01:01 abnerLing