-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that we can cast waveform somewhere before. Because casting to |
||
masks = tuple([x.cuda() for x in masks]) | ||
|
||
waveform_batch = torch.vstack(waveforms) | ||
# (batch_size, 1, num_samples) torch.Tensor | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,7 +481,7 @@ def dimension(self) -> int: | |
dummy_waveforms = torch.rand(1, 1, 16000) | ||
features = self.compute_fbank(dummy_waveforms) | ||
embeddings = self.session_.run( | ||
output_names=["embs"], input_feed={"feats": features.numpy()} | ||
output_names=["embs"], input_feed={"feats": features.cpu().numpy()} | ||
)[0] | ||
_, dimension = embeddings.shape | ||
return dimension | ||
|
@@ -504,7 +504,7 @@ def min_num_samples(self) -> int: | |
continue | ||
|
||
embeddings = self.session_.run( | ||
output_names=["embs"], input_feed={"feats": features.numpy()} | ||
output_names=["embs"], input_feed={"feats": features.cpu().numpy()} | ||
)[0] | ||
|
||
if np.any(np.isnan(embeddings)): | ||
|
@@ -583,7 +583,7 @@ def __call__( | |
|
||
if masks is None: | ||
embeddings = self.session_.run( | ||
output_names=["embs"], input_feed={"feats": features.numpy()} | ||
output_names=["embs"], input_feed={"feats": features.cpu().numpy()} | ||
)[0] | ||
|
||
return embeddings | ||
|
@@ -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]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
)[0][0] | ||
|
||
return embeddings | ||
|
There was a problem hiding this comment.
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