Skip to content

Adding Voice preset in AutoProcessor Giving error #623

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

Open
HarshPatil89 opened this issue Jan 22, 2025 · 1 comment
Open

Adding Voice preset in AutoProcessor Giving error #623

HarshPatil89 opened this issue Jan 22, 2025 · 1 comment

Comments

@HarshPatil89
Copy link

HarshPatil89 commented Jan 22, 2025

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)

@gruellan
Copy link

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)

Tested this change to your code and it worked

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

No branches or pull requests

2 participants