← Back to Pull requests

Don't retain returned work in ProcessGroupDummy #376

Closed
unknown closed this pull request without merging on Oct 28, 2026 19:25 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 12:57 UTC
Author

Summary

ProcessGroupDummy appended every _DummyWork it returned to a self._work list that nothing ever read or cleared. torchft.ddp.DistributedDataParallel builds torch DDP on a ProcessGroupDummy with find_unused_parameters=True, so the reducer allreduces its local_used_map through the dummy group on every gradient-syncing backward, and each step retained one _DummyWork (its tensor list plus a done torch.futures.Future, about 1.3 KB) for the life of the model. Modules with buffers retained two more per forward, each holding a freshly flattened copy of the buffers.

This drops the list and returns the work directly. Nothing in the repo referenced ProcessGroupDummy._work.

Why the list is no longer needed

The list dates from e4f512e (Oct 2024) and acted as a keep-alive: at the time, a Python Work returned to C++ through the PyProcessGroup trampoline could be collected while the C++ Reducer still held it, and the next wait() fell back to the base Work::wait() and hung. pytorch/pytorch#146376 (torch 2.7) fixed that by wrapping returned Python works in PyWorkHolder, which keeps the Python object alive as long as the C++ intrusive_ptr is held. torchft requires torch>=2.7, so the dummy group no longer needs to pin the works itself. Verified on torch 2.14: after each backward exactly one _DummyWork (the reducer's current local_used_work_) is alive, and the reducer's wait() still dispatches to the Python override.

Test plan

  • New test_dummy_does_not_retain_work: weakrefs the work returned by allreduce, drops it and asserts it is collected. Fails on main, passes with this change.

  • Repro (one replica, one lighthouse, Linear(1, 1), CPU, 20k steps): on main len(pg._work) grows 4 -> 20004; with this change live _DummyWork objects stay at 1 and RSS is flat after warm-up.

  • pytest torchft/process_group_test.py torchft/ddp_test.py torchft/manager_test.py and torchft/manager_integ_test.py -k ddp pass (86 / 4 / 30 / 7 passed); ufmt check is clean; pyrefly check and flake8 report nothing new.
  • One note for reviewers: a ProcessGroupDummy that is registered with torch.distributed and used by torch DDP inside Join(divide_by_initial_world_size=False) would now hang, because Reducer._set_forward_pass_work_handle takes the Python work without PyWorkHolder; the leaked list used to mask that. torchft's DDP uses an unregistered dummy group and never uses Join, and the same hang already affects every other Python-defined Work on main, so this is a PyTorch-side gap rather than something this change introduces.

    🤖 Generated with Claude Code

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: d4l3k Review duration: 388m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #376"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%