This is my complete code:
np_data.shape                ->(42000, 784)
np_data=np_data.astype(np.float32).reshape(42000,28,28,1)
np_labels.shape              ->(42000, 1)
np_data.shape                ->(42000, 28, 28, 1)
np_data=np.transpose(np_data,[0,3,1,2])
np_data.shape                 ->(42000, 1, 28, 28)

batch_size=50
features=torch.from_numpy(np_data)
features=features.contiguous().view(42000,-1)
targets=torch.from_numpy(np_labels)

import torch.utils.data as data_utils

train = data_utils.TensorDataset(features, targets)
train_loader = data_utils.DataLoader(train, batch_size=batch_size, shuffle=True)

criterion = nn.CrossEntropyLoss() # use a Classification Cross-Entropy loss
import torch.optim as optim

def trainConvNet(train_loader,net,criterion,epochs,total_samples,learning_rate):
    prev_loss=0
    
    optimizer = optim.SGD(net.parameters(), lr=learning_rate, momentum=0.9)
    for epoch in range(int(epochs)): # loop over the dataset multiple times

        running_loss = 0.0
        for i,data in enumerate(train_loader):

            inputs,labels=data
            # wrap them in Variable
            inputs, labels = Variable(inputs).cuda(), Variable(labels).cuda()
            
            # zero the parameter gradients
            optimizer.zero_grad()

            # forward + backward + optimize
            outputs = net(inputs)
            loss = criterion(outputs, labels[:,0])
            loss.backward()        
            optimizer.step()
            # print statistics
            running_loss += loss.data[0]
    print('Finished Training')
    return net


class convNet(nn.Module):
    #constructor
    def __init__(self):
        super(convNet, self).__init__()
        #defining layers in convnet
        #input size=32x32x3
        self.conv1 = nn.Conv2d(1, 96, kernel_size=3,stride=1,padding=1)
        #conv1: 28x28x1 -> 28x28x96
        self.conv2 = nn.Conv2d(96, 256, kernel_size=3,stride=1,padding=1)
        #conv2: 28x28x96 -> 28x28x256
        self.conv3 = nn.Conv2d(256,384,kernel_size=3,stride=1,padding=1)
        #conv3: 28x28x256 -> 28x28x384
        #pooling: 28x28x384 -> 14x14x384
        self.conv4 = nn.Conv2d(384,512,kernel_size=3,stride=1,padding=1)
        #conv4: 14x14x384 -> 14x14x512
        #pooling: 14x14x512 -> 7x7x512        
        self.fc1   = nn.Linear(7*7*512, 300)
        self.fc2   = nn.Linear(300, 100)
        self.fc3   = nn.Linear(100, 10)
        
    def forward(self, x):
        x = nnFunctions.relu(self.conv1(x))
        x = nnFunctions.relu(self.conv2(x))
        x = nnFunctions.max_pool2d(nnFunctions.relu(self.conv3(x)),2)
        x = nnFunctions.max_pool2d(nnFunctions.relu(self.conv4(x)),2)
    
        x = x.view(-1, 7*7*512)
        x = nnFunctions.relu(self.fc1(x))
        x = nnFunctions.relu(self.fc2(x))
        x = self.fc3(x)
        return x
net=convNet()
net.cuda()
net=trainConvNet(train_loader,net,criterion,1,42000,0.01)

I dont understand why am I getting the above error.