Ok, if I understand your targets are the arguments max. This may not work, you should have a vector of zeros with a “one” where you want an activation:
for i, (train_images_1, train_labels_1) in enumerate(train_loader):
  # prepare target
  target = torch.zeros(1, num_labels)
  target[0,train_labels_1] = 1
  
  running_loss = 0.0
  running_corrects = 0
  #wrap them in Variable
  train_images_1 = Variable(train_images_1.cuda(), requires_grad=True)
  target = Variable(target.cuda(), requires_grad=False)
  
  # zero the parameter gradients
  optimizer.zero_grad()

  # forward
  outputs = cnn(train_images_1)
  loss = criterion(outputs, target)
  loss.backward()
  optimizer.step()