microsoft / FocalNet

[NeurIPS 2022] Official code for "Focal Modulation Networks"
MIT License
694 stars 63 forks source link

torch.utils.checkpoint + DDP #4

Closed YanShuang17 closed 1 year ago

YanShuang17 commented 2 years ago

I found the useful trick Gradient Checkpointing in your implemention(i.e. use_checkpoint flag).

I failed to use it with DDP training(when using single GPU, it works fine), error occurs like below:

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 440 with name backbone.backbone.layers.3.blocks.2.mlp.fc2.bias has been marked as ready twice. This means that multiple autograd engine  hooks have fired for this particular parameter during this iteration.

My torch version is 1.10.0

Could you please provide some advice ? Thanks