There are errors while running on colab of google but not occurring on my local os

the all codes are shown as below:

class MnistDataSet(Dataset):
    def __init__(self,csv_file,transform,is_train):
        self.csv_file = csv_file
        self.samples = pd.read_csv(csv_file)
        self.transform = transform
        self.is_train = is_train
    def __len__(self):
        return self.samples.shape[0]
    def __getitem__(self,idx):
        if self.is_train:
            label,sample = self.samples.iloc[idx,0],self.samples.iloc[idx,1:]
        else:
            sample = self.samples.iloc[idx]
        sample = np.array(sample).reshape([28,28,1])
        if transforms:
            sample = self.transform(sample)
        if self.is_train:
            return label,sample
        else:
            return sample

transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (1.0,))])
mnistTrainDataSet = MnistDataSet('train.csv',transform,True)

the first is: when running
mnist1, mnist2 = cross_validation.train_test_split(mnistTrainDataSet,test_size=0.25,random_state=20)
error occurred:

/usr/local/lib/python3.6/dist-packages/sklearn/cross_validation.py in train_test_split(*arrays, **options)
   2070     train, test = next(iter(cv))
   2071     return list(chain.from_iterable((safe_indexing(a, train),
-> 2072                                      safe_indexing(a, test)) for a in arrays))
   2073 
   2074 

/usr/local/lib/python3.6/dist-packages/sklearn/cross_validation.py in <genexpr>(.0)
   2070     train, test = next(iter(cv))
   2071     return list(chain.from_iterable((safe_indexing(a, train),
-> 2072                                      safe_indexing(a, test)) for a in arrays))
   2073 
   2074 

/usr/local/lib/python3.6/dist-packages/sklearn/utils/__init__.py in safe_indexing(X, indices)
    162             return X[indices]
    163     else:
--> 164         return [X[idx] for idx in indices]
    165 
    166 

/usr/local/lib/python3.6/dist-packages/sklearn/utils/__init__.py in <listcomp>(.0)
    162             return X[indices]
    163     else:
--> 164         return [X[idx] for idx in indices]
    165 
    166 

<ipython-input-9-eaa3e4e1dde7> in __getitem__(self, idx)
     14         sample = np.array(sample).reshape([28,28,1])
     15         if transforms:
---> 16             sample = self.transform(sample)
     17         if self.is_train:
     18             return label,sample

/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py in __call__(self, img)
     47     def __call__(self, img):
     48         for t in self.transforms:
---> 49             img = t(img)
     50         return img
     51 

/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py in __call__(self, tensor)
    141             Tensor: Normalized Tensor image.
    142         """
--> 143         return F.normalize(tensor, self.mean, self.std)
    144 
    145     def __repr__(self):

/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py in normalize(tensor, mean, std)
    166     # TODO: make efficient
    167     for t, m, s in zip(tensor, mean, std):
--> 168         t.sub_(m).div_(s)
    169     return tensor
    170 

TypeError: sub_ received an invalid combination of arguments - got (float), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (!float!)
 * (torch.LongTensor other)
      didn't match because some of the arguments have invalid types: (!float!)
 * (int value, torch.LongTensor other)

but this didn’t happen in my local os.
I fixed the error above by removing transforms.Normalize((0.5,), (1.0,),

train_loader = DataLoader(mnist1,100)
test_loader = DataLoader(mnist2,100)

class MnistNet(nn.Module):
    def __init__(self):
        super(MnistNet, self).__init__()
        self.conv1 = nn.Conv2d(1,10,5)
        self.pool1 = nn.MaxPool2d(2)
        self.conv2 = nn.Conv2d(10,20,5)
        self.pool2 = nn.MaxPool2d(2)
        self.fc1 = nn.Linear(320,50)
        self.fc2 = nn.Linear(50,10)
        self.softmax = nn.Softmax()
    def forward(self,input):
        x = self.pool1(self.conv1(input))
        x = self.pool2(self.conv2(x))
        x = F.relu(self.fc1(x.view(x.size(0),-1)))
        x = (self.fc2(x))
        return self.softmax(x)

epoch = 1
mnistnet = MnistNet()

when I run:

optimizer = torch.optim.SGD(mnistnet.parameters(),lr=0.01)
loss_fn = torch.nn.CrossEntropyLoss()
for i in range(epoch):
    for j, sample in enumerate(train_loader):
        targets, inputs = sample
        targets, inputs = Variable(targets), Variable(inputs)
        outs = mnistnet(inputs)
        optimizer.zero_grad()
        loss = loss_fn(outs,targets)
        
        loss.backward()
        optimizer.step()
        
        if j%200 == 0:
            outs = mnistnet(inputs)
            _,pred = torch.max(outs,1)
            trues = torch.sum(pred.data == targets.data)
            print('%d,loss:%s,rate:%.4f' % (j,loss_fn(outs,targets).data[0],
                                          (trues/inputs.size(0))
                                         )
                 )

the error occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-25-72ba16ff08c8> in <module>()
      5         targets, inputs = sample
      6         targets, inputs = Variable(targets), Variable(inputs)
----> 7         outs = mnistnet(inputs)
      8         optimizer.zero_grad()
      9         loss = loss_fn(outs,targets)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    323         for hook in self._forward_pre_hooks.values():
    324             hook(self, input)
--> 325         result = self.forward(*input, **kwargs)
    326         for hook in self._forward_hooks.values():
    327             hook_result = hook(self, input, result)

<ipython-input-23-9f0a75882410> in forward(self, input)
     10         self.softmax = nn.Softmax()
     11     def forward(self,input):
---> 12         x = self.pool1(self.conv1(input))
     13         x = self.pool2(self.conv2(x))
     14         x = F.relu(self.fc1(x.view(x.size(0),-1)))

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    323         for hook in self._forward_pre_hooks.values():
    324             hook(self, input)
--> 325         result = self.forward(*input, **kwargs)
    326         for hook in self._forward_hooks.values():
    327             hook_result = hook(self, input, result)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
    275     def forward(self, input):
    276         return F.conv2d(input, self.weight, self.bias, self.stride,
--> 277                         self.padding, self.dilation, self.groups)
    278 
    279 

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in conv2d(input, weight, bias, stride, padding, dilation, groups)
     88                 _pair(0), groups, torch.backends.cudnn.benchmark,
     89                 torch.backends.cudnn.deterministic, torch.backends.cudnn.enabled)
---> 90     return f(input, weight, bias)
     91 
     92 

RuntimeError: conv2d_forward is not implemented for type torch.LongTensor

And this also didn’t happen on my own os(Windows10, py36,pytorch 0.3)

It seems you are loading the samples as long.
The error from the normalization also prints that another LongTensor is needed.
Same goes for the model.
inputs seems to be a LongTensor as well.
Could you check your Dataset and transform the sample to float: sample = np.array(sample, dtype=np.float32).

Also your channel dimension should be at dim=1. So your input shape would be [batch_size, 1, 28, 28].