0

I have a problem when I run model.py

if you don't mind can you correct my code here

run with CPU

seq_ent = torch.cat([torch.index_select(seq_out[i,:,:],0,ids[i,:].long()).unsqueeze(0) for i in range(batch_size)], 0) # [batchsize, 4, 768]

IndexError: index out of range in self

run with GPU

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-43fe30517134> in <module>()
     98       # print(train_data['ids'].shape)
     99 
--> 100       token_ids = train_data['token_ids'].to(device)
    101       attention_masks = train_data['attention_masks'].to(device)
    102       token_type_ids = train_data['token_type_ids'].to(device)

RuntimeError: CUDA error: device-side assert triggered
Dimas
  • 39
  • 3
  • For CUDA error, I recommend setting your device to 'cpu'. – Kevin Choi May 27 '22 at 05:59
  • Thank you, but when set device to 'CPU' I still get error' with IndexError: index out of range in self – Dimas May 27 '22 at 09:12
  • 1
    suggestions: (1) write this line as cycle with several individual operations inside, so you'd see which part triggers error. (2) search for and check out similar cases, like https://stackoverflow.com/questions/62081155/pytorch-indexerror-index-out-of-range-in-self-how-to-solve – Poe Dator May 27 '22 at 13:01

0 Answers0