How to synchonize DDP with drop layers?

I tried to drop some layers in ResNet with random probabilities.
But, I have a problem using DDP and random drop at the same time.
How can I use random drop layers with DDP?

  1. without torch.manual_seed():
    → GPU Hang with utilization 100%
  2. with torch.manual_seed():
    → 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.
class Bottleneck(nn.Module):
        self.m = torch.distributions.bernoulli.Bernoulli(torch.Tensor([0.5]))
        ...

    def forward(self, x):
        identity = x.clone()
        if torch.equal(self.m.sample(), torch.ones(1)):
        # forward ...
        else:
        # skip forward ...
        return out


model = torch.nn.parallel.DistributedDataParallel(model, ..., find_unused_parameters=True)
out = model(inputs)

Since you are using a subset of all modules and parameters in each forward pass I would assume seeding the code or guaranteeing the same parameter usage in another way and using find_unused_parameters=True should work. Did you try to add this argument to your DDP setup?

@ptrblck
Thanks for the reply.

Yes, I already set find_unused_parameters=True as above code.

But still got 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 277 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.

How can I make all ranks handle the same dropped layers? Can’t I implement this through seed?