WeiChengTseng / Pytorch-PCGrad

Pytorch reimplementation for "Gradient Surgery for Multi-Task Learning"
BSD 3-Clause "New" or "Revised" License
302 stars 42 forks source link

多GPU运行时报错 #16

Open yongdajiaozhixiang opened 1 year ago

yongdajiaozhixiang commented 1 year ago

您好!当使用单个GPU运行代码时没有问题,但是使用多个GPU运行时出现了一下问题: File "/home/ps/workplace/ruijia.yang/MoonHunter/libs/mmcv/mmcv/runner/base_runner.py", line 309, in call_hook getattr(hook, fn_name)(self) File "/home/ps/workplace/shuang.wang/MoonHunter/apps/nn/../../project/optimizer/optimizer_pc.py", line 267, in after_train_iter pc_optimizer.pc_backward(runner.outputs["head_loss"], self.G,self.pcG) File "/home/ps/workplace/shuang.wang/MoonHunter/apps/nn/../../project/optimizer/optimizer_pc.py", line 58, in pc_backward grads, shapes, has_grads,grads_dict = self._pack_grad(objectives) File "/home/ps/workplace/shuang.wang/MoonHunter/apps/nn/../../project/optimizer/optimizer_pc.py", line 144, in _pack_grad objectives[obj].backward(retain_graph=True) File "/home/ps/.conda/envs/torch1.11/lib/python3.8/site-packages/torch/_tensor.py", line 363, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs) File "/home/ps/.conda/envs/torch1.11/lib/python3.8/site-packages/torch/autograd/init.py", line 173, in backward Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass RuntimeError: Expected to mark a variable ready only once. This error is caused by one of the following reasons: 1) Use of a module parameter outside the forward function. Please make sure model parameters are not shared across multiple concurrent forward-backward passes. or try to use _set_static_graph() as a workaround if this module graph does not change during training loop.2) Reused parameters in multiple reentrant backward passes. For example, if you use multiple checkpoint functions to wrap the same part of your model, it would result in the same set of parameters been used by different reentrant backward passes multiple times, and hence marking a variable ready multiple times. DDP does not support such use cases in default. You can try to use _set_static_graph() as a workaround if your module graph does not change over iterations. Parameter at index 169 has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration. You can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print parameter names for further debugging. ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 79130) of binary: /home/ps/.conda/envs/torch1.11/bin/python 您能帮忙解决一下吗?非常感谢,期待您的回复

MingChaoXu commented 1 year ago

i also met this bug, pcgrad run well when i use only one gpu, but error when i use man gpus, and infos are as follows: image

it seems that when i use many gpus, the model forward computes error, i dont know why