IndexError: tuple index out of range

for num_epochs in range(1):  # loop over the dataset multiple times

    running_loss = 0.0
    for i, data in enumerate(train_loader, 0):
        # get the inputs
        inputs, labels = data

        # zero the parameter gradients
        optimizer.zero_grad()

        # forward + backward + optimize
        outputs = hh(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()

        # print statistics
        running_loss += loss.item()
        if i % 2000 == 1999:    # print every 2000 mini-batches
            print('[%d, %5d] loss: %.3f' %
                  (epoch + 1, i + 1, running_loss / 2000))
            running_loss = 0.0

print('Finished Training')

in the code above when i run it gives me " IndexError: tuple index out of range "
i can see that the tensor size is zero here but i do nor know why

Which line is throwing this error?
I’m not sure where you are indexing.

Maybe it is similar to me. I am getting the same error in the for loop over the training dataloader. In my code it is happening exactly in the for line:

def train_model(model, optim, train_dl, class_weights=None):
  ...
  for x1, x2, y, source_apps, event_app_lists, target_app_lists, sw in train_dl:
    ...

event_app_lists and target_app_lists are packed sequences.

Could you post a minimal and executable code snippet I could use to reproduce and debug the issue, please?