How to synchonize DDP with drop layers?

oasjd7: <p>I tried to drop some layers in ResNet with random probabilities.<br>
But, I have a problem using DDP and random drop at the same time.<br>
How can I use random drop layers with DDP?</p>
<ol>
<li>without torch.manual_seed():<br>
 → GPU Hang with utilization 100%</li>
<li>with torch.manual_seed():<br>
 → 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 <code>forward</code> 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 <code>checkpoint</code> 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.</li>
</ol>
<pre><code class="lang-auto">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)
</code></pre>

ptrblck: <p>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 <code>find_unused_parameters=True</code> should work. Did you try to add this argument to your DDP setup?</p>

oasjd7: <p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
Thanks for the reply.</p>
<p>Yes, I already set <code>find_unused_parameters=True</code> as above code.</p>
<p>But still got ERROR:<br>
 → 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 <code>forward</code> 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 <code>checkpoint</code> 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.<br>
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.</p>
<p>How can I make all ranks handle the same dropped layers? Can’t I implement this through seed?</p>