RuntimeError: stride should not be zero

I have just learn PyTorch on MAC for weeks, the issue is I can run the VGG16 on cpu , but I can’t run on mps. the error information listed as follow.


RuntimeError Traceback (most recent call last)
Input In [21], in <cell line: 6>()
6 for epoch in range(epochs):
8 since = time.time()
—> 10 epoch_loss, epoch_acc, epoch_test_loss, epoch_test_acc = fit(epoch,model,train_dl,test_dl)
12 train_loss.append(epoch_loss)
13 train_acc.append(epoch_acc)

Input In [19], in fit(epoch, model, trainloader, testloader)
8 for x, y in trainloader:
9 x, y = x.to(device), y.to(device)
—> 10 y_pred = model(x)
11 loss = loss_fn(y_pred, y)
12 optimizer.zero_grad()

File ~/opt/anaconda3/envs/deeplearning/lib/python3.9/site-packages/torch/nn/modules/module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don’t have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []

File ~/opt/anaconda3/envs/deeplearning/lib/python3.9/site-packages/torchvision/models/vgg.py:43, in VGG.forward(self, x)
41 def forward(self, x):
42 x = self.features(x)
—> 43 x = self.avgpool(x)
44 x = x.view(x.size(0), -1)
45 x = self.classifier(x)

File ~/opt/anaconda3/envs/deeplearning/lib/python3.9/site-packages/torch/nn/modules/module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don’t have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []

File ~/opt/anaconda3/envs/deeplearning/lib/python3.9/site-packages/torch/nn/modules/pooling.py:1179, in AdaptiveAvgPool2d.forward(self, input)
1178 def forward(self, input: Tensor) → Tensor:
→ 1179 return F.adaptive_avg_pool2d(input, self.output_size)

File ~/opt/anaconda3/envs/deeplearning/lib/python3.9/site-packages/torch/nn/functional.py:1214, in adaptive_avg_pool2d(input, output_size)
1212 return handle_torch_function(adaptive_avg_pool2d, (input,), input, output_size)
1213 _output_size = _list_with_default(output_size, input.size())
→ 1214 return torch._C._nn.adaptive_avg_pool2d(input, _output_size)

1 Like

the issue doesn’t happend when I use RESNET18.