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

Method prefetchParamsFused

csrc/compile/z3.cpp:166–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 }
165
166 void prefetchParamsFused(const std::vector<long>& ds_ids,
167 const std::optional<std::vector<at::ScalarType>> dtypes,
168 c10::intrusive_ptr<c10d::symmetric_memory::SymmetricMemory> symm_mem)
169 {
170 std::vector<std::tuple<long, std::optional<at::ScalarType>>> invalid_params;
171 for (int i = 0; i < ds_ids.size(); i++) {
172 if (!param_registry_->isValid(ds_ids[i])) {
173 auto dtype = dtypes ? dtypes.value()[i] : std::optional<at::ScalarType>();
174 invalid_params.push_back(std::make_tuple(ds_ids[i], dtype));
175 }
176 }
177
178 std::unordered_map<long, at::Tensor> output_bufs;
179 for (const auto& [ds_id, dtype] : invalid_params) {
180 const DSParam& param = param_registry_->getParam(ds_id);
181 const at::Tensor& ds_tensor = param.getDSTensor();
182 const int world_size = process_group_->getSize();
183 const int64_t shard_elems = ds_tensor.numel();
184 const int64_t padded_numel = static_cast<int64_t>(world_size) * shard_elems;
185
186 if (param_registry_->hasGatheredParam(ds_id)) {
187 auto existing = param_registry_->getGatheredParam(ds_id);
188 if (existing.defined() && existing.numel() == padded_numel) {
189 output_bufs[ds_id] = existing;
190 continue;
191 }
192 }
193 auto target_dtype = dtype ? dtype.value() : ds_tensor.scalar_type();
194 at::cuda::CUDAStreamGuard guard(ag_stream_);
195 output_bufs[ds_id] =
196 torch::empty({padded_numel}, ds_tensor.options().dtype(target_dtype));
197 }
198
199 for (const auto& [ds_id, _] : invalid_params) {
200 ag_comp_done_events_[ds_id]->record();
201 ag_comp_done_events_[ds_id]->block(ag_stream_);
202 }
203
204 ncclGroupStart();
205 for (const auto& [ds_id, _] : invalid_params) {
206 assert(hasKey(output_bufs, ds_id));
207 launchAllGather(output_bufs.at(ds_id), ds_id, symm_mem);
208 }
209 ncclGroupEnd();
210
211 for (const auto& [ds_id, _] : invalid_params) {
212 ag_comm_done_events_[ds_id]->record(ag_stream_);
213 }
214 }
215
216 void releaseParam(long ds_id, long n_users)
217 {

Callers 1

prefetch_params_fusedFunction · 0.80

Calls 9

hasKeyFunction · 0.85
isValidMethod · 0.80
getDSTensorMethod · 0.80
getSizeMethod · 0.80
hasGatheredParamMethod · 0.80
sizeMethod · 0.45
numelMethod · 0.45
dtypeMethod · 0.45
recordMethod · 0.45

Tested by

no test coverage detected