RuntimeError: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

Hello,
I am running the tacotron2 training from train_tts.py and using LJSpeech dataset. Actually I flowing the steps motioned in this notebook
So, I done the modification needed in the config.json file and I ran the training. Bur unfortunately I receive this error:

> TRAINING (2020-11-12 10:58:19) 
Traceback (most recent call last):
  File "TTS/bin/train_tts.py", line 715, in <module>
    main(args)
  File "TTS/bin/train_tts.py", line 627, in main
    global_step, epoch, amp, speaker_mapping)
  File "TTS/bin/train_tts.py", line 163, in train
    text_input, text_lengths, mel_input, mel_lengths, speaker_ids=speaker_ids, speaker_embeddings=speaker_embeddings)
  File "/home/khalil/anaconda3/envs/mozilla_tts/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/khalil/anaconda3/envs/mozilla_tts/lib/python3.7/site-packages/TTS-0.0.5+79ce06c-py3.7-linux-x86_64.egg/TTS/tts/models/tacotron2.py", line 102, in forward
    encoder_outputs = self.encoder(embedded_inputs, text_lengths)
  File "/home/khalil/anaconda3/envs/mozilla_tts/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/khalil/anaconda3/envs/mozilla_tts/lib/python3.7/site-packages/TTS-0.0.5+79ce06c-py3.7-linux-x86_64.egg/TTS/tts/layers/tacotron2.py", line 106, in forward
    batch_first=True)
  File "/home/khalil/anaconda3/envs/mozilla_tts/lib/python3.7/site-packages/torch/nn/utils/rnn.py", line 244, in pack_padded_sequence
    _VF._pack_padded_sequence(input, lengths, batch_first)
RuntimeError: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
 ! Run is removed from output/ljspeech-ddc-November-12-2020_10+58AM-79ce06c

I made a search in this forum and in the github issues but didn’t find any topic about this.
Any help?

I think the issue is related to pytorch version (pytorch 1.7.0) because I found the same issue in Pytorch repo’s issue and think this is the fix for it

Please use the dev branch, master isn’t always best. And it works with pytorch 1.6, so 1.7 could be the problem or the master branch.

1 Like

Yes, I just downgraded pytorch to 1.6 and it worked successfully

1 Like