RuntimeError: input_lengths must be of size batch_size
See original GitHub issueI am getting the error mentioned in the title while trying to run acoustic model training using wav2vec config Following are the flags used for asr.sh used in run.sh
./asr.sh \
--stage 10 \
--stop_stage 10 \
--feats_normalize null \
--lang en \
--audio_format wav \
--ngpu 4 \
--nbpe 10000 \
--max_wav_duration 30 \
--speed_perturb_factors "0.9 1.0 1.1" \
--asr_config "${asr_config}" \
--lm_config "${lm_config}" \
--inference_config "${inference_config}" \
--train_set "${train_set}" \
--valid_set "${valid_set}" \
--test_sets "${test_sets}" \
--lm_train_text "data/${train_set}/text" \
--bpe_train_text "data/${train_set}/text" "$@"
Below is the log of error obtained
Traceback (most recent call last):
File "/miniconda/envs/espnet/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/miniconda/envs/espnet/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/espnet/espnet2/tasks/abs_task.py", line 1284, in main_worker
cls.trainer.run(
File "/espnet/espnet2/train/trainer.py", line 279, in run
all_steps_are_invalid = cls.train_one_epoch(
File "/espnet/espnet2/train/trainer.py", line 499, in train_one_epoch
retval = model(**batch)
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/parallel/distributed.py", line 705, in forward
output = self.module(*inputs[0], **kwargs[0])
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/espnet/espnet2/asr/espnet_model.py", line 153, in forward
loss_ctc, cer_ctc = self._calc_ctc_loss(
File "/espnet/espnet2/asr/espnet_model.py", line 301, in _calc_ctc_loss
loss_ctc = self.ctc(encoder_out, encoder_out_lens, ys_pad, ys_pad_lens)
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/espnet/espnet2/asr/ctc.py", line 139, in forward
loss = self.loss_fn(ys_hat, ys_true, hlens, ys_lens).to(
File "/espnet/espnet2/asr/ctc.py", line 54, in loss_fn
loss = self.ctc_loss(th_pred, th_target, th_ilen, th_olen)
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/modules/loss.py", line 1590, in forward
return F.ctc_loss(log_probs, targets, input_lengths, target_lengths, self.blank, self.reduction,
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/nn/functional.py", line 2307, in ctc_loss
return torch.ctc_loss(
RuntimeError: input_lengths must be of size batch_size
Traceback (most recent call last):
File "/miniconda/envs/espnet/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/miniconda/envs/espnet/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/espnet/espnet2/bin/asr_train.py", line 23, in <module>
main()
File "/espnet/espnet2/bin/asr_train.py", line 19, in main
ASRTask.main(cmd=cmd)
File "/espnet/espnet2/tasks/abs_task.py", line 1044, in main
while not ProcessContext(processes, error_queues).join():
File "/miniconda/envs/espnet/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 139, in join
raise ProcessExitedException(
torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with exit code 1
# Accounting: time=37 threads=1
# Ended (code 1) at Wed Sep 1 12:48:13 UTC 2021, elapsed time 37 seconds
Can anybody suggest me on this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Problem with expected tensor size of input of ctc_loss function
RuntimeError : Expected tensor to have size at least 225 at dimension 1 ... When the batch size is 2, the input_lengths tensor...
Read more >[Feature request] PackedSequence with length = 0 · Issue #4582
If you run pack_padded_sequence(input, lengths) with one of the lengths <= 0 it raises a ValueError: length of all samples has to be...
Read more >python - Pytorch with CUDA throws RuntimeError when using ...
Within PadSequence function (which acts as a collate_fn which gathers samples and makes a batch from them) you are explicitly casting to ...
Read more >Selecting Optimal LSTM Batch Size | by Caner - Medium
The batches are used to train LSTMs, and selecting the batch-size is a vital ... the batch size as 32, 64, 128 which...
Read more >What is batch size in neural network? - Cross Validated
The batch size defines the number of samples that will be propagated through the network. For instance, let's say you have 1050 training...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi I have made the modifications present in the pull request acoustic model training is now working fine!
@nellorebhanuteja
No, I’m suggesting the other way. I suspect the error you posted is because the lengths of sequences in the same batch are all the same. Would you like to try the modifications I made? It’s just two lines.