RuntimeError when I use cuda

#1
by Yehor - opened

My test script:

import torchaudio
from speechbrain.pretrained import VAD


test_file = 'a.wav'
vad_final = 'bond_vad.wav'

######

VAD = VAD.from_hparams(run_opts={"device":"cuda"}, source="speechbrain/vad-crdnn-libriparty", savedir="pretrained_models/vad-crdnn-libriparty")

boundaries = VAD.get_speech_segments(test_file)


VAD.save_boundaries(boundaries, save_path='VAD_file.txt')

upsampled_boundaries = VAD.upsample_boundaries(boundaries, test_file)
torchaudio.save(vad_final, upsampled_boundaries.cpu(), 16000)

When I run it, the following error goes:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    boundaries = VAD.get_speech_segments(test_file)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/speechbrain/pretrained/interfaces.py", line 1861, in get_speech_segments
    prob_chunks = self.get_speech_prob_file(
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/speechbrain/pretrained/interfaces.py", line 1092, in get_speech_prob_file
    small_chunks_prob = self.get_speech_prob_chunk(small_chunks)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/speechbrain/pretrained/interfaces.py", line 1203, in get_speech_prob_chunk
    outputs = self.mods.cnn(feats)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/speechbrain/nnet/containers.py", line 144, in forward
    x = layer(x)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/speechbrain/nnet/normalization.py", line 222, in forward
    return self.norm(x)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/torch/nn/modules/normalization.py", line 189, in forward
    return F.layer_norm(
  File "/home/yehor/Tools/anaconda3/envs/my/lib/python3.8/site-packages/torch/nn/functional.py", line 2486, in layer_norm
    return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument weight in method wrapper__native_layer_norm)

you mentioned device as a cuda i.e. gpu and then you set upsampled_boundaries to cpu. because of that you are getting an error.

Sign up or log in to comment