Fix lost TP all-reduce results for non-contiguous tensors #8837
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
jinyouzhi
Problem
dist.all_reducereduces its argument in place. Three tensor-parallel autograd functions indeepspeed/module_inject/layers.pycalldist.all_reduce(x.contiguous(), ...)and then returnx. Whenxis 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_inputcomes frommatmuland 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 throughLinearLayerpasses 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
RowParallelforward andColumnParallelbackward tests intests/unit/module_inject/test_tp_autograd_reduce.py(2 ranks) gain acontiguousparameter. The non-contiguous cases feed a transposed input toRowParalleland a transposed gradient toColumnParallel, and check that the 2-rank group returns the sum over ranks (1 + 2 = 3).test_row_parallel_forward[pair-False]andtest_column_parallel[pair-False]fail; each rank keeps only its own value. All other cases pass.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()'overdeepspeed/finds only the three runtime sites fixed here, all inmodule_inject/layers.py. The fourth match,ColumnParallel.symbolic, only runs during ONNX tracing and is left unchanged. Theinference_all_reducebranch ofRowParallelpasses 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.
[pair-False]cases fail.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.