Here is code:
for i, (train_images_1, train_labels_1) in enumerate(train_loader):
	running_loss = 0.0
	running_corrects = 0
             #wrap them in Variable
            if use_gpu:
            	train_images_1, train_labels_1 = Variable(train_images_1.cuda()), \
             Variable(train_labels_1.cuda())

	

            # zero the parameter gradients
            optimizer.zero_grad()

            # forward
            outputs = cnn(train_images_1)

            _, preds = torch.max(outputs.data, 1)
            loss = criterion(outputs, train_labels_1)
            loss.backward()
            optimizer.step()