MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / flushReduceBucket

Method flushReduceBucket

csrc/compile/z1.cpp:49–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 }
48
49 void flushReduceBucket(at::ScalarType scalar_type) override
50 {
51 if (!hasKey(reduce_tasks_, scalar_type)) { return; }
52
53 blockCopyEvents(scalar_type);
54 applyPreDivision(scalar_type);
55
56 // NCCL AllReduce operation
57 ncclGroupStart();
58 for (const ReduceTask& t : reduce_tasks_.at(scalar_type)) {
59 ncclResult_t result = ncclAllReduce(t.getSendBuf().data_ptr(),
60 t.getSendBuf().data_ptr(),
61 t.getSendBuf().numel(),
62 get_nccl_data_type(scalar_type),
63 getReductionOp(),
64 nccl_comm_,
65 rs_stream_);
66 if (result != ncclSuccess) { throw std::runtime_error("NCCL AllReduce failed"); }
67 }
68 ncclGroupEnd();
69
70 // Copy results to gradient buffers
71 {
72 at::cuda::CUDAStreamGuard guard(rs_stream_);
73 for (const ReduceTask& t : reduce_tasks_.at(scalar_type)) {
74 auto param = param_registry_->getParam(t.getDSId());
75 auto grad_buf = param.getGradBuffer().flatten();
76
77 if (grad_buf.numel() == 0) { continue; }
78
79 int64_t offset = param.getOffset();
80 auto recv_buf = t.getSendBuf().flatten().index(
81 {torch::indexing::Slice(offset, offset + grad_buf.numel())});
82 grad_buf.copy_(recv_buf);
83 }
84 }
85
86 performCleanup(scalar_type);
87 }
88
89protected:
90 std::unordered_map<long, at::Tensor> grad_tensors_;

Callers

nothing calls this directly

Calls 9

hasKeyFunction · 0.85
get_nccl_data_typeFunction · 0.85
getSendBufMethod · 0.80
numelMethod · 0.80
getDSIdMethod · 0.80
getGradBufferMethod · 0.80
copy_Method · 0.80
data_ptrMethod · 0.45
getOffsetMethod · 0.45

Tested by

no test coverage detected