You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
processor = AutoProcessor.from_pretrained("suno/bark")
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = BarkModel.from_pretrained("suno/bark").to(device)
voice_preset = "v2/en_speaker_4"
inputs = processor("Hello, my dog is cute, I need him in my life", voice_preset=voice_preset).to(device)
audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()
sample_rate = 24000
scipy.io.wavfile.write("bark_out2.wav", rate=sample_rate, data=audio_array)`
When I add voice_preset as an argument it gives error regarding
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper_CUDA__index_select)
The text was updated successfully, but these errors were encountered:
inputs = processor("Hello, my dog is cute, I need him in my life", voice_preset=voice_preset).to(device) returns a dictionary, not a tensor. Calling .to(device) on the whole dict won't automatically put the tensors inside inputs on the GPU.
You should instead iterate through and put each tensor onto GPU:
inputs = processor("Hello, my dog is cute, I need him in my life", voice_preset=voice_preset)
for key, value in inputs.items():
inputs[key] = inputs[key].to(device)
audio_array = model.generate(**inputs)
Below is my code Its very simple.
`from transformers import AutoProcessor, BarkModel
import scipy
import torch
processor = AutoProcessor.from_pretrained("suno/bark")
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = BarkModel.from_pretrained("suno/bark").to(device)
voice_preset = "v2/en_speaker_4"
inputs = processor("Hello, my dog is cute, I need him in my life", voice_preset=voice_preset).to(device)
audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()
sample_rate = 24000
scipy.io.wavfile.write("bark_out2.wav", rate=sample_rate, data=audio_array)`
When I add voice_preset as an argument it gives error regarding
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper_CUDA__index_select)
The text was updated successfully, but these errors were encountered: