IndexError: index 20 is out of bounds for dimension 1 with size 20

I was trying to train a model and getting the following error. I am confused why I am getting this error.
And the shape of all the variables are:
Data shape: torch.Size([321, 20, 14])
Mask shape: torch.Size([321, 20])
Decay shape: torch.Size([321, 20])
Redecay shape: torch.Size([321, 20])

The code is given below -

data = T.as_tensor(data.values.astype(float), dtype=T.float32)
data=data.view(int(data.shape[0]/args.seq_len), args.seq_len, data.shape[1])
mask = T.as_tensor(mask.values.astype(float), dtype=T.float32)
mask=mask.view(int(mask.shape[0]/args.seq_len), args.seq_len, mask.shape[1])
decay=mask[:,:,1]
rdecay=mask[:,:,2]
mask=mask[:,:,0]

data=data.squeeze()
mask=mask.squeeze()
decay=decay.squeeze()
rdecay=rdecay.squeeze()
ret_f, ret, disc = run_on_batch(model,discriminator,data,mask,decay,rdecay, args, optimizer=None,optimizer_d=None,epoch=None)

Error message:

IndexError                                Traceback (most recent call last)
<ipython-input-161-f02c9fd37373> in <module>
      3 #oBmi, oBmiF, iBmi, oAge, oSex = run(ARGS)
      4 
----> 5 run(ARGS)
      6 
<ipython-input-160-636128776031> in run(args)
     26 
     27     elif args.train:
---> 28         trainLoss,discLoss,gLoss, valLoss,discValLoss,gValLoss = run_epoch(args, model, discriminator)
     29         # return trainLoss,discLoss,gLoss, valLoss,discValLoss,gValLoss
     30 
<ipython-input-159-922ded87c953> in run_epoch(args, model, discriminator)
     84 
     85 
---> 86         ret_f, ret, disc = run_on_batch(model,discriminator,data,mask,decay,rdecay, args, optimizer,optimizer_d,epoch)#,bmi_norm)
     87         print(ret_f)
     88         RLoss=RLoss+ret['loss'].item()
~/Work/deep-learning-based-packet-imputation/BiGAN/biGan/bgan_i_ganOrig.ipynb in run_on_batch(model, discriminator, data, mask, decay, rdecay, args, optimizer, optimizer_d, epoch)
~/.local/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

~/Work/deep-learning-based-packet-imputation/BiGAN/biGan/bgan_i_ganOrig.ipynb in forward(self, data, mask, decay, rdecay, args)

~/.local/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

~/Work/deep-learning-based-packet-imputation/BiGAN/biGan/ugan_i_ganOrig.ipynb in forward(self, values, masks, deltas, args, direct)

IndexError: index 20 is out of bounds for dimension 1 with size 20

Thank you for your help.

Python and PyTorch use 0-based indexing so a tensor with a shape [batch_size, 20] can be indexed with indices in [0, 19] in dim1 while you are passing 20:

x = torch.randn(6, 20)
x[:, 19] # works
x[:, 20] # fails
# IndexError: index 20 is out of bounds for dimension 1 with size 20

Thanks, it is solved. But I have another error (link), if you have a look and help me to solve then it will be very much helpful.