"Expected to have finished reduction" error when dropping layers with DDP

I want to do layerdrop. Unfortunately when I do so I get an error:
Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. [...]

I thought this could be caused by the fact that I was doing DDP and different workers were dropping different layers leading to problems when trying to sync gradients. However I set the seed so the different workers should be dropping the same layer at the same time and I still get the error.

Why is this happening?

Thanks for posting @divinho. From your description it seems that your model is dropping a particular layer and the loss calculation does not use that layer at all. If you want to train in such way with DDP, can you try use find_unused_parameters=True when initializing DDP?

Currently, find_unused_parameters=True must be passed into torch.nn.parallel.DistributedDataParallel() initialization if there are parameters that may be unused in the forward pass.

1 Like

Thank you for the suggestion I will try that!

That solved it thank you!

Hi, adding find unused parameters = True throws the following error
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 52 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.