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_CUDA___slow_conv2d_forward)
#21
by
followflows
- opened
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_CUDA___slow_conv2d_forward)
How to fix it?
followflows
changed discussion title from
untimeError: 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_CUDA___slow_conv2d_forward)
to 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_CUDA___slow_conv2d_forward)
hey i saw your comment and i figure out the code heres the updated code
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
import IPython.display as ipd
import torch
models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
"facebook/fastspeech2-en-ljspeech",
arg_overrides={"vocoder": "hifigan", "fp16": False}
)
# print(models)
model = models[0]
model.to("cuda")
# print(model.cuda())
device = "cuda"
# print(model)
TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
generator = task.build_generator([model], cfg)
text = "Hello, this is a test run, good goodddd, seem good so far. just like this segway, to our sponsor, Raid Shadow Legends." # abit of trolling
sample = TTSHubInterface.get_model_input(task, text)
sample['net_input']['src_tokens'] = sample['net_input']['src_tokens'].to(device)
sample['net_input']['src_lengths'] = sample['net_input']['src_lengths'].to(device)
sample['speaker'] = sample['speaker'].to(device) if sample['speaker'] != None else torch.tensor([[0]]).to(device)
wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
ipd.Audio(wav.cpu(), rate=rate)