← Back to Pull requests

Fix lost TP all-reduce results for non-contiguous tensors #8837

Open
unknown opened this pull request with 410 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 16, 2026 10:02 UTC
Author

Problem


dist.all_reduce reduces its argument in place. Three tensor-parallel autograd functions in deepspeed/module_inject/layers.py call dist.all_reduce(x.contiguous(), ...) and then return x. When x is not contiguous, .contiguous() returns a copy. The reduction lands in that copy and is discarded, so the TP sum is silently skipped:

  • RowParallel.forward (training path): the forward output is not reduced.

  • ColumnParallel.backward: the input gradient is not reduced, e.g. when the output is transposed before the loss.

  • AsyncColumnParallel.backward: grad_input comes from matmul and is normally contiguous, but it uses the same pattern, so it is fixed the same way.
  • In-tree AutoTP layers only hand these functions matmul / embedding outputs and their gradients, which are contiguous, so the bug is latent there today. It is hit by any caller that passes a non-contiguous tensor, such as a custom TP layer. A training-loop test through LinearLayer passes with or without this fix, so the regression tests target the autograd functions directly.

    Fix


    Assign the contiguous tensor first, reduce it, and return it.

    Tests


    The existing RowParallel forward and ColumnParallel backward tests in tests/unit/module_inject/test_tp_autograd_reduce.py (2 ranks) gain a contiguous parameter. The non-contiguous cases feed a transposed input to RowParallel and a transposed gradient to ColumnParallel, and check that the 2-rank group returns the sum over ranks (1 + 2 = 3).
  • Before the fix: test_row_parallel_forward[pair-False] and test_column_parallel[pair-False] fail; each rank keeps only its own value. All other cases pass.

  • After the fix: everything passes, together with test_tp_shard.py (33 passed in total).
  • Run on 2× Intel Arc Pro B70 (XPU, XCCL), torch 2.14.0.dev20260804+xpu.

    Contribution checklist

    Related work. A search of open and closed PRs found no existing fix for this.

    Sibling paths checked. git grep 'all_reduce(<x>.contiguous()' over deepspeed/ finds only the three runtime sites fixed here, all in module_inject/layers.py. The fourth match, ColumnParallel.symbolic, only runs during ONNX tracing and is left unchanged. The inference_all_reduce branch of RowParallel passes the tensor itself, so it is not affected.

    Commands and results. Hardware and software: 2× Intel Arc Pro B70 (XPU, XCCL), Level Zero driver 1.15.39122 (compute runtime 26.27.39122.11), torch 2.14.0.dev20260804+xpu.

    pytest -p no:randomly tests/unit/module_inject/test_tp_autograd_reduce.py tests/unit/module_inject/test_tp_shard.py
    

  • Before the fix, the two [pair-False] cases fail.

  • After the fix, everything passes (33 passed).
  • Numerics, performance, memory. Nothing changes for contiguous inputs, which is the case for every in-tree AutoTP layer: .contiguous() returns the same tensor. For non-contiguous inputs, the result is now the reduced tensor, which is the intended behavior.

    Compatibility matrix. Validated: TP=2, fp32, at the autograd-function level. ZeRO stage and offload do not interact with this code. Not validated: CUDA, HPU.

    AI assistance. This PR was developed with AI assistance (GitHub Copilot CLI). I reviewed every changed line and ran the tests above.

    Diff: 410 lines (+307 / -103) across 5 files Reviewer: jinyouzhi Review duration: 65645m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.52) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 410 lines diff across 5 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.360
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #8837"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 51.9% (MEDIUM) · Higher = larger blast radius
    51.9%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 28.7% · Safe to merge
    28.7%