[PyTorch] Type the grouped wgrad from main_grad for distributed weights - #3397
[PyTorch] Type the grouped wgrad from main_grad for distributed weights#3397fanshiqing wants to merge 1 commit into
Conversation
c9a1f5a routed distributed weights into the no-fusion branch, which allocates at the compute dtype -- so under fp32 grad accumulation the reduce-scatter rounded to BF16 on every rank: wgrad alloc fp32 ---> reduce fp32 ---> accum fp32 <- this fix (was compute dtype ---> compute dtype ---> fp32) Two dispatchers beside finalize_weight_grads: weight_grad_buffers() GEMM writes into the implementer's buffer (no per-backward wgrad allocation) weight_grad_dtype() fallback for the single-grouped branches Signed-off-by: Shiqing Fan <shiqingf@nvidia.com>
Greptile SummaryThe PR routes grouped distributed-weight gradients through implementer-provided buffers or allocates them using Confidence Score: 4/5The PR should not merge until grouped backward remains compatible with distributed groups represented by a protocol-bearing leader and plain followers. The new buffer dispatcher checks only the leader for distributed capability but calls grad_buffer on every group member, causing an immediate backward exception for an input shape already accepted by the leader-based dispatcher contract. Files Needing Attention: transformer_engine/pytorch/distributed_weight.py Important Files Changed
Sequence DiagramsequenceDiagram
participant B as Grouped backward
participant D as weight_grad_buffers
participant L as Distributed leader
participant F as Plain follower
B->>D: "weights = [leader, follower]"
D->>L: is_distributed_weight(leader)
L-->>D: true
D->>L: grad_buffer()
L-->>D: buffer
D->>F: grad_buffer()
F--xD: AttributeError
Reviews (1): Last reviewed commit: "[PyTorch] Type the grouped wgrad from ma..." | Re-trigger Greptile |
| if is_distributed_weight(weights[0]): | ||
| buffers = [w.grad_buffer() for w in weights] |
There was a problem hiding this comment.
Leader-only groups break backward
When a distributed weight group uses a protocol-bearing leader with ordinary tensor followers, weight_grad_buffers checks only the leader but calls grad_buffer() on every member, causing backward to fail with AttributeError.
Knowledge Base Used: PyTorch Distributed/Parallel Training Support
|
/te-ci pytorch L1 |
Description
c9a1f5a routed distributed weights into the no-fusion branch, which allocates at the compute dtype -- so under fp32 grad accumulation the reduce-scatter rounded to BF16 on every rank:
Two dispatchers beside finalize_weight_grads:
weight_grad_buffers()GEMM writes into the implementer's buffer (no per-backward wgrad allocation)weight_grad_dtype()fallback for the single-grouped branchesc9a1f5a9 routed distributed weights into the no-fusion branch, which allocates at the compute dtype -- so under fp32 grad accumulation the reduce-scatter rounded to BF16 on every rank:Two dispatchers beside finalize_weight_grads:
weight_grad_buffers()GEMM writes into the implementer's buffer (no per-backward wgrad allocation)weight_grad_dtype()fallback for the single-grouped branchesType of change
Changes
Please list the changes introduced in this PR:
Checklist: