AttributeError: 'DataParallel' object has no attribute 'src_device_obj'

vyaslkv: <p>I am getting the above error when I am running the the same code on different machine<br>
Kindly help!!<br>
I trained the model on gpu machine and then testing it on cpu machine only (is this the issue do I need to retrain the model on cpu)</p>
<p>AttributeError                            Traceback (most recent call last)<br>
 in <br>
33<br>
34 start = datetime.datetime.now()<br>
—&gt; 35 inp, out, lab, pred, paths = predict_test_paths(model, dataloaders=dataloaders)<br>
36 end = datetime.datetime.now()<br>
37</p>
<p> in predict_test_paths(model, dataloaders, device_type)<br>
126                 labels = labels.to(device)<br>
127<br>
–&gt; 128                 outputs = model(inputs)<br>
129                 _, preds = torch.max(outputs, 1)<br>
130</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
530             result = self._slow_forward(*input, **kwargs)<br>
531         else:<br>
–&gt; 532             result = self.forward(*input, **kwargs)<br>
533         for hook in self._forward_hooks.values():<br>
534             hook_result = hook(self, input, result)</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py in forward(self, *inputs, **kwargs)<br>
141<br>
142         for t in chain(self.module.parameters(), self.module.buffers()):<br>
–&gt; 143             if t.device != self.src_device_obj:<br>
144                 raise RuntimeError("module must have its parameters and buffers "<br>
145                                    "on device {} (device_ids[0]) but found one of "</p>
<p>~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in <strong>getattr</strong>(self, name)<br>
574                 return modules[name]<br>
575         raise AttributeError("’{}’ object has no attribute ‘{}’".format(<br>
–&gt; 576             type(self).<strong>name</strong>, name))<br>
577<br>
578     def <strong>setattr</strong>(self, name, value):</p>
<p>AttributeError: ‘DataParallel’ object has no attribute ‘src_device_obj’</p>

ptrblck: <p>Are you using different PyTorch versions on these machines?<br>
The attribute was added approx. one year ago, so versions after this date should be compatible.</p>

vyaslkv: <p>If the put the same version in the new machine as the old one on which it was trained it gives import error on pytorch</p>

vyaslkv: <p>on old machine on which trained<br>
(base) [centos@datascience-gpudev-1 notebooks]$ conda list | grep torch<br>
cpuonly                   1.0                           0    pytorch<br>
pytorch                   1.0.1           py3.6_cuda9.0.176_cudnn7.4.2_2    pytorch<br>
torch                     1.3.1                    pypi_0    pypi<br>
torchtext                 0.4.0                    pypi_0    pypi<br>
torchvision               0.2.2                      py_3    pytorch</p>

vyaslkv: <p>on new machine<br>
lalit@ip-172-31-28-15:~$ conda list | grep torch<br>
cpuonly                   1.0                           0    pytorch<br>
pytorch                   1.4.0               py3.7_cpu_0  [cpuonly]  pytorch<br>
torchvision               0.5.0                  py37_cpu  [cpuonly]  pytorch</p>

ptrblck: <p>What kind of import error do you get? Could you please post it here?</p>

vyaslkv: <pre><code class="lang-auto">conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly -c pytorch
</code></pre>
<p>solved it (going back to older version) thanks!!</p>