Hi!
I’m testing adding custom regularization to loss function like this:
regu = torch.tensor([0.]).to(torch.device('cuda'))
for name, param in model.named_parameters():
if 'alpha' in name:
print(name)
regu += param**2.
loss = criterion(outputs, targets) + regu
It worked well when I used 1 gpu.
But after I changed the code to test it in distributed mode, it gave me an error.
regu = torch.tensor([0.]).to(torch.device('cuda'))
if args.distributed:
for name, param in model.module.named_parameters():
if 'alpha' in name:
print(name)
regu += param**2.
loss = criterion(outputs, targets) + regu
Error Message:
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 316 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: 605186) of binary: /home/sis/vautoformer/bin/python
I can’t understand why it doesn’t work.
Could you give me any advice about this?