[DDP] 并行训练问题/Multi-head shared-backbone model triggers “Expected to mark a variable ready only once” — how to parallelize training?
@rulerman is already working on this.
Since Aug 6, 2025.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Description
In multi-GPU DDP training, the model has a shared backbone (LLM) and multiple output heads (8 channels, each computing a different loss).
In a single forward pass, all heads use the same backbone parameters (e.g., down_proj.weight) to compute 8 separate losses, which are then weighted, summed into a single total_loss, and backpropagated once.
Single-GPU training works fine, but in multi-GPU DDP we get:
RuntimeError: 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
or
Parameter at index 314 with name model.language_model.layers.27.mlp.down_proj.weight has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration.
Tried:
• Disabled gradient_checkpointing
• find_unused_parameters=True/False
• model._set_static_graph() + static_graph=True
• Only one backward() call
Still fails. I suspect this is a known limitation in DDP when handling multi-output, multi-loss architectures with shared parameters.
Could the maintainers share the recommended way to handle this, and how do you parallelize training in similar architectures?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.