jaywalnut310 / vits

VITS: Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech
https://jaywalnut310.github.io/vits-demo/index.html
MIT License
6.48k stars 1.21k forks source link

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) #135

Closed Arszr closed 1 year ago

Arszr commented 1 year ago

Hi, I made this mistake when I tried to train: IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) May I ask why? I didn't change the part of the code that produced the error, but I changed some of the code. Because I was using PyTorch 2.0. That didn't happen to me in the first round of training, but only when I started the second round Here is my error message:


-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "e:\code\venv37\lib\site-packages\torch\multiprocessing\spawn.py", line 19, in _wrap
    fn(i, *args)
  File "E:\code\vits\train.py", line 123, in run
    train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval])
  File "E:\code\vits\train.py", line 143, in train_and_evaluate
    for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 435, in __next__
    data = self._next_data()
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 1111, in _process_data
    data.reraise()
  File "e:\code\venv37\lib\site-packages\torch\_utils.py", line 428, in reraise
    raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "e:\code\venv37\lib\site-packages\torch\utils\data\_utils\worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "e:\code\venv37\lib\site-packages\torch\utils\data\_utils\fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "E:\code\vits\data_utils.py", line 114, in __call__
    torch.LongTensor([x[1].size(1) for x in batch]),
  File "E:\code\vits\data_utils.py", line 114, in <listcomp>
    torch.LongTensor([x[1].size(1) for x in batch]),
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

  File "E:\code\vits\train.py", line 55, in main
    mp.spawn(run, nprocs=n_gpus, args=(n_gpus, hps,))
  File "E:\code\vits\train.py", line 303, in <module>
    main()
Exception: 

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "e:\code\venv37\lib\site-packages\torch\multiprocessing\spawn.py", line 19, in _wrap
    fn(i, *args)
  File "E:\code\vits\train.py", line 123, in run
    train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval])
  File "E:\code\vits\train.py", line 143, in train_and_evaluate
    for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 435, in __next__
    data = self._next_data()
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "e:\code\venv37\lib\site-packages\torch\utils\data\dataloader.py", line 1111, in _process_data
    data.reraise()
  File "e:\code\venv37\lib\site-packages\torch\_utils.py", line 428, in reraise
    raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "e:\code\venv37\lib\site-packages\torch\utils\data\_utils\worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "e:\code\venv37\lib\site-packages\torch\utils\data\_utils\fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "E:\code\vits\data_utils.py", line 114, in __call__
    torch.LongTensor([x[1].size(1) for x in batch]),
  File "E:\code\vits\data_utils.py", line 114, in <listcomp>
    torch.LongTensor([x[1].size(1) for x in batch]),
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

This is the main thing I changed,In the mel_processing file

    spec = torch.stft(y, n_fft, hop_length=hop_size, win_length=win_size, window=hann_window[wnsize_dtype_device],
                        center=center, pad_mode='reflect', normalized=False, onesided=True,return_complex=True)
    spec = torch.view_as_real(spec)

    spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
    spec = spec.type_as(mel_basis[fmax_dtype_device])

If this is the problem, how to adjust it? thank !

jb-01 commented 1 year ago

Double-check that the ln -s /path/to/LJSpeech-1.1/wavs DUMMY1 folder contains wav files only. Any other file types will cause an out of range error.

Arszr commented 1 year ago

您的邮件我收到了。

Arszr commented 1 year ago

Thanks, resolved

dyustc commented 1 year ago

Hi, I met the same problem, first round trained successfully, but got the same error, I even changed the pt store path to make sure only wav files in data folder.

Could you please tell me how you resolved this? @Arszr Original Traceback (most recent call last): File "/home/eeodev/anaconda3/envs/wetts/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "/home/eeodev/anaconda3/envs/wetts/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch return self.collate_fn(data) File "/data2/daiyi/github/vits/data_utils.py", line 117, in __call__ torch.LongTensor([x[1].size(1) for x in batch]), File "/data2/daiyi/github/vits/data_utils.py", line 117, in <listcomp> torch.LongTensor([x[1].size(1) for x in batch]), IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Antonoko commented 1 year ago

encountered the same problem too😿, the wavs folder only contains comprises wav files meeting mono, 22050 hz, PCM 16 bit spec only. here's my error msg:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\multiprocessing\spawn.py", line 69, in _wrap
    fn(i, *args)
  File "D:\AI\vits\train.py", line 122, in run
    train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval])
  File "D:\AI\vits\train.py", line 142, in train_and_evaluate
    for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 634, in __next__
    data = self._next_data()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1346, in _next_data
    return self._process_data(data)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1372, in _process_data
    data.reraise()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\_utils.py", line 644, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\fetch.py", line 54, in fetch
    return self.collate_fn(data)
  File "D:\AI\vits\data_utils.py", line 114, in __call__
    torch.LongTensor([x[1].size(1) for x in batch]),
  File "D:\AI\vits\data_utils.py", line 114, in <listcomp>
    torch.LongTensor([x[1].size(1) for x in batch]),
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
Arszr commented 1 year ago

您的邮件我收到了。

Arszr commented 1 year ago

Hi, I met the same problem, first round trained successfully, but got the same error, I even changed the pt store path to make sure only wav files in data folder.

Could you please tell me how you resolved this? @Arszr Original Traceback (most recent call last): File "/home/eeodev/anaconda3/envs/wetts/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "/home/eeodev/anaconda3/envs/wetts/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch return self.collate_fn(data) File "/data2/daiyi/github/vits/data_utils.py", line 117, in __call__ torch.LongTensor([x[1].size(1) for x in batch]), File "/data2/daiyi/github/vits/data_utils.py", line 117, in <listcomp> torch.LongTensor([x[1].size(1) for x in batch]), IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Match the PyTorch version with the version of the repository, and reinstall the relevant libraries

Arszr commented 1 year ago

encountered the same problem too😿, the wavs folder only contains comprises wav files meeting mono, 22050 hz, PCM 16 bit spec only. here's my error msg:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\multiprocessing\spawn.py", line 69, in _wrap
    fn(i, *args)
  File "D:\AI\vits\train.py", line 122, in run
    train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval])
  File "D:\AI\vits\train.py", line 142, in train_and_evaluate
    for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 634, in __next__
    data = self._next_data()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1346, in _next_data
    return self._process_data(data)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1372, in _process_data
    data.reraise()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\_utils.py", line 644, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\fetch.py", line 54, in fetch
    return self.collate_fn(data)
  File "D:\AI\vits\data_utils.py", line 114, in __call__
    torch.LongTensor([x[1].size(1) for x in batch]),
  File "D:\AI\vits\data_utils.py", line 114, in <listcomp>
    torch.LongTensor([x[1].size(1) for x in batch]),
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

encountered the same problem too😿, the wavs folder only contains comprises wav files meeting mono, 22050 hz, PCM 16 bit spec only. here's my error msg:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\multiprocessing\spawn.py", line 69, in _wrap
    fn(i, *args)
  File "D:\AI\vits\train.py", line 122, in run
    train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval])
  File "D:\AI\vits\train.py", line 142, in train_and_evaluate
    for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 634, in __next__
    data = self._next_data()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1346, in _next_data
    return self._process_data(data)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\dataloader.py", line 1372, in _process_data
    data.reraise()
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\_utils.py", line 644, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\haru\AppData\Roaming\Python\Python310\site-packages\torch\utils\data\_utils\fetch.py", line 54, in fetch
    return self.collate_fn(data)
  File "D:\AI\vits\data_utils.py", line 114, in __call__
    torch.LongTensor([x[1].size(1) for x in batch]),
  File "D:\AI\vits\data_utils.py", line 114, in <listcomp>
    torch.LongTensor([x[1].size(1) for x in batch]),
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

The PyTorch version uses 1.6

shabariiyyappan commented 1 year ago

Thanks, resolved

How did you resolved it.. please help me as well

deryaguler95 commented 1 year ago

Hi I got the same problem I changed torch version to 1.6.0 and the DUMMY1 folder just includes wav files. But I get the same result I don not know why. Please help me?

Arszr commented 1 year ago

您的邮件我收到了。

CSharperMantle commented 1 year ago

I assume the changes @Arszr made on the callsite of torch.stft() was indeed critical to this issue.

According to the highlighted warning in the documentation, before torch==1.8.0, this function will return its complex results as a real tensor, with real part and imaginary parts in different dims. After said version, the function returns a complex tensor directly, breaking this code.

This is also why @Arszr downgrading their library to 1.6.0 will work.

The final solution is simple: 1) Downgrade to 1.6.0; 2) Stay at newer versions and add a call to torch.view_as_real() in series after STFT is sufficient to tackle with this issue.

ice-lynn commented 11 months ago

Stay at newer versions and add a call to torch.view_as_real() in series after STFT is sufficient to tackle with this issue.

Thank u for your reply. resolved my problem!!!!!

Arszr commented 11 months ago

您的邮件我收到了。

WithAngleOrDemon commented 2 months ago

May I ask why my code ran incorrectly

PS D:\vits> python train.py -c "D:\vits\configs\config.json" -m keqing INFO:keqing:{'train': {'log_interval': 200, 'eval_interval': 1000, 'seed': 1234, 'epochs': 2000, 'learning_rate': 0.0002, 'betas': [0.8, 0.99], 'eps': 1e-09, 'batch_size': 4, 'fp16_run': True, 'lr_decay': 0.999875, 'segment_size': 8192, 'init_lr_ratio': 1, 'warmup_epochs': 0, 'c_mel': 45, 'c_kl': 1.0}, 'data': {'training_files': 'D:/vits/list.txt.cleaned', 'validation_files': 'D:/vits/list_val.txt.cleaned', 'text_cleaners': ['chinese_cleaners'], 'max_wav_value': 32768.0, 'sampling_rate': 22050, 'filter_length': 1024, 'hop_length': 256, 'win_length': 1024, 'n_mel_channels': 80, 'mel_fmin': 0.0, 'mel_fmax': None, 'add_blank': True, 'n_speakers': 0, 'cleaned_text': True}, 'model': {'inter_channels': 192, 'hidden_channels': 192, 'filter_channels': 768, 'n_heads': 2, 'n_layers': 6, 'kernel_size': 3, 'p_dropout': 0.1, 'resblock': '1', 'resblock_kernel_sizes': [3, 7, 11], 'resblock_dilation_sizes': [[1, 3, 5], [1, 3, 5], [1, 3, 5]], 'upsample_rates': [8, 8, 2, 2], 'upsample_initial_channel': 512, 'upsample_kernel_sizes': [16, 16, 4, 4], 'n_layers_q': 3, 'use_spectral_norm': False, 'ginchannels': 256}, 'speakers': ['小茸', '唐乐吟', '小殷', '花玲', '许老师', '邱琳', '七一', '八四'], 'symbols': ['', ',', '。', '!', '?', '—', '…', 'ㄅ', 'ㄆ', 'ㄇ', 'ㄈ', 'ㄉ', 'ㄊ', 'ㄋ', 'ㄌ', 'ㄍ', 'ㄎ', 'ㄏ', 'ㄐ', 'ㄑ', 'ㄒ', 'ㄓ', 'ㄔ', 'ㄕ', 'ㄖ', 'ㄗ', 'ㄘ', 'ㄙ', 'ㄚ', 'ㄛ', 'ㄜ', 'ㄝ', 'ㄞ', 'ㄟ', 'ㄠ', 'ㄡ', 'ㄢ', 'ㄣ', 'ㄤ', 'ㄥ', 'ㄦ', 'ㄧ', 'ㄨ', 'ㄩ', 'ˉ', 'ˊ', 'ˇ', 'ˋ', '˙', ' '], 'model_dir': '../drive/MyDrive\keqing'} INFO:torch.distributed.distributed_c10d:Added key: store_based_barrier_key:1 to store for rank: 0 INFO:torch.distributed.distributed_c10d:Rank 0: Completed store-based barrier for key:store_based_barrier_key:1 with 1 nodes. Traceback (most recent call last): File "train.py", line 301, in main() File "train.py", line 55, in main mp.spawn(run, nprocs=n_gpus, args=(n_gpus, hps,)) File "F:\anaconda3\envs\vits\lib\site-packages\torch\multiprocessing\spawn.py", line 240, in spawn return start_processes(fn, args, nprocs, join, daemon, start_method='spawn') File "F:\anaconda3\envs\vits\lib\site-packages\torch\multiprocessing\spawn.py", line 198, in start_processes while not context.join(): File "F:\anaconda3\envs\vits\lib\site-packages\torch\multiprocessing\spawn.py", line 160, in join
raise ProcessRaisedException(msg, error_index, failed_process.pid) torch.multiprocessing.spawn.ProcessRaisedException:

-- Process 0 terminated with the following error:

Traceback (most recent call last):

File "F:\anaconda3\envs\vits\lib\site-packages\torch\multiprocessing\spawn.py", line 69, in _wrap
fn(i, *args) File "D:\vits\train.py", line 122, in run train_and_evaluate(rank, epoch, hps, [net_g, net_d], [optim_g, optim_d], [scheduler_g, scheduler_d], scaler, [train_loader, eval_loader], logger, [writer, writer_eval]) File "D:\vits\train.py", line 142, in train_and_evaluate for batch_idx, (x, x_lengths, spec, spec_lengths, y, y_lengths) in enumerate(train_loader):
File "F:\anaconda3\envs\vits\lib\site-packages\torch\utils\data\dataloader.py", line 530, in next data = self._next_data() File "F:\anaconda3\envs\vits\lib\site-packages\torch\utils\data\dataloader.py", line 1224, in _next_data return self._process_data(data) File "F:\anaconda3\envs\vits\lib\site-packages\torch\utils\data\dataloader.py", line 1250, in _process_data data.reraise() File "F:\anaconda3\envs\vits\lib\site-packages\torch_utils.py", line 457, in reraise raise exception IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "F:\anaconda3\envs\vits\lib\site-packages\torch\utils\data_utils\worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "F:\anaconda3\envs\vits\lib\site-packages\torch\utils\data_utils\fetch.py", line 52, in fetch return self.collate_fn(data) File "D:\vits\data_utils.py", line 114, in call torch.LongTensor([x[1].size(1) for x in batch]), File "D:\vits\data_utils.py", line 114, in torch.LongTensor([x[1].size(1) for x in batch]), IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

I try python 3.7, 3.8, 3.9 but it doesn't work My cuda is 11.3v and pytorch is 1.11v