Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: moving the operations to the GPU if GPU available #1522

Closed
wants to merge 1 commit into from

Conversation

asr-pub
Copy link

@asr-pub asr-pub commented Nov 2, 2023

According my testing, before the code modifications, the 8 speaker diarization processes running on 8 GPUs(A100) separately of the same node, with some operations still on the CPU, the RTF (Real-Time Factor) was 3.32, After moving the operations to the GPU, the RTF reached 0.015. On V100, the RFT reached 0.02.

@@ -606,7 +606,7 @@ def __call__(

embeddings[f] = self.session_.run(
output_names=["embs"],
input_feed={"feats": masked_feature.numpy()[None]},
input_feed={"feats": masked_feature.cpu().numpy()[None]},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you are actually sending the features back to CPU, before sending them to the inference. Therefore, I don't really understand why this should speed things up.

Can you please provide me with a bit more context?
Ideally, a Colab notebook illustrating the speed up that this brings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use the cpu() method, it will result in an error. You can refer to the official PyTorch documentation for this. What I've observed is that if we don't place the tensor on the GPU, both torch.vstack() and torch.fft.rfft() will consume a significant amount of CPU resources.

# Under the 'wavs_16k' directory, there are a total of 8 '.lst' files, each of which contains paths to audio files. 
# After running the following code, 8 PyAnnote processes are launched on a computing node equipped 
# with 8 V100 GPUs, with each process occupying one GPU.
for list in `ls wavs_16k/*.lst`
do
    sleep 1s
    echo $list
    srun  -N1 -n1 --gres=gpu:1 python scripts/pyannote_main.py ${list} > logs/`basename $list .lst`_${time}.log 2>&1 &
done

@@ -338,6 +338,10 @@ def iter_waveform_and_mask():
for i, batch in enumerate(batches, 1):
waveforms, masks = zip(*filter(lambda b: b[0] is not None, batch))

if torch.cuda.is_available():
Copy link

@grazder grazder Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move to GPU only if self.device == 'cuda'. This can lead to some troubles, for example if user have gpu available, but he wants to run it on cpu. Also it don't match with .to behaviour

@@ -338,6 +338,10 @@ def iter_waveform_and_mask():
for i, batch in enumerate(batches, 1):
waveforms, masks = zip(*filter(lambda b: b[0] is not None, batch))

if torch.cuda.is_available():
waveforms = tuple([x.cuda() for x in waveforms])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we can cast waveform somewhere before. Because casting to cuda for every element in list seems not efficient. May be we can cast original file or waveform to cuda before splitting it into batch? So we don't need to make multiple casts to cuda for every element in batch instead of 1 cast

@hbredin
Copy link
Member

hbredin commented Nov 7, 2023

Closing this PR as I think #1529 (just merged) fixes (at least part of) the issue.

@hbredin hbredin closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants