MMdnn icon indicating copy to clipboard operation
MMdnn copied to clipboard

RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu

Open hot-dog opened this issue 5 years ago • 8 comments

Platform (like ubuntu 16.04/win10): Ubuntu 16.04 Python version: python 3.6 Source framework with version (like Tensorflow 1.4.1 with GPU): pytorch 1.2.0 with GPU torchvision 0.4.0 Destination framework with version (like CNTK 2.3 with GPU): tensorflow 1.8.0 with GPU Pre-trained model path (webpath or webdisk path): local disk Running scripts: mmtoir -f pytorch -d mobilenet_v2 --inputShape 3,224,224 -n test_model.pth

The model was trained with 4 GPUs, and I saved the architecture and weights of the net. When I excute the scripts "mmtoir -f pytorch -d mobilenet_v2 --inputShape 3,224,224 -n test_model.pth", I encountered the error:RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu, i dont know where is worng, any advices?

hot-dog avatar Aug 19 '19 13:08 hot-dog

Here is the whole error information: Traceback (most recent call last): File "/home/xx/anaconda3/envs/py36-1/bin/mmtoir", line 11, in sys.exit(_main()) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 192, in _main ret = _convert(args) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 92, in _convert parser = PytorchParser(model, inputshape[0]) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/mmdnn/conversion/pytorch/pytorch_parser.py", line 85, in init self.pytorch_graph.build(self.input_shape) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/mmdnn/conversion/pytorch/pytorch_graph.py", line 122, in build trace, output = torch.jit.get_trace_graph(self.model, (dummy_input, )) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/jit/init.py", line 256, in get_trace_graph return LegacyTracedModule(f, _force_outplace, return_inputs)(*args, **kwargs) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, **kwargs) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/jit/init.py", line 323, in forward out = self.inner(*trace_inputs) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/nn/modules/module.py", line 545, in call result = self._slow_forward(*input, **kwargs) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/nn/modules/module.py", line 531, in _slow_forward result = self.forward(*input, **kwargs) File "/home/xx/anaconda3/envs/py36-1/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 146, in forward "them on device: {}".format(self.src_device_obj, t.device)) RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu

any reply is welcomed~

hot-dog avatar Aug 19 '19 13:08 hot-dog

I have the same problem and I don't know who to assess what device the parameters are on. Hopefully someone responds.

JohnLaMaster avatar Aug 27 '19 17:08 JohnLaMaster

Maybe change this line to dummy_input = torch.autograd.Variable(torch.randn(shape), requires_grad=False).cuda() would help.

Thanks!

rainLiuplus avatar Sep 09 '19 03:09 rainLiuplus

I have a similar problem in computing the FLOPs. The error is corrected by using net instead of net.module.

JINGTING92 avatar Dec 23 '19 07:12 JINGTING92

"module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu"

For anybody still encountering this issue: This error often happens when the nn.Model is not passed to the GPU. Make sure to

  1. Select your desired GPU with e.g. torch.cuda.set_device('cuda:0') and
  2. call model.cuda() for your nn.Model

KreitnerL avatar Sep 23 '20 14:09 KreitnerL

@Linus4world it worked, thanks

yustiks avatar Sep 26 '21 20:09 yustiks

"module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu"

For anybody still encountering this issue: This error often happens when the nn.Model is not passed to the GPU. Make sure to

  1. Select your desired GPU with e.g. torch.cuda.set_device('cuda:0') and
  2. call model.cuda() for your nn.Model

What about I use CPU only?

hitbuyi avatar Oct 08 '22 13:10 hitbuyi

I have the same question ,what about just use cpu ?

mmoneyy avatar Oct 23 '22 12:10 mmoneyy