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

Method run_step

csrc/adam/cpu_adam_impl.cpp:572–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570
571private:
572 void run_step(int now_state, int64_t step, const std::vector<ZenHP>& hps)
573 {
574 auto opt = std::static_pointer_cast<Adam_Optimizer>(s_optimizers[opt_id_]);
575 for (size_t g = 0; g < groups_.size(); ++g) {
576 const ZenHP& hp = hps[g];
577 // Groups share one Adam_Optimizer; advance its bias-correction state for
578 // this group before the pool reads it (pool is idle here -> no race).
579 opt->IncrementStep(step, hp.beta1, hp.beta2);
580 opt->update_state(hp.lr, hp.eps, hp.weight_decay, hp.bias_correction);
581
582 ZenGroup& grp = groups_[g];
583 torch::Tensor& P = grp.param;
584 torch::Tensor& G = grp.grad[now_state];
585 torch::Tensor& M = grp.exp_avg[now_state];
586 torch::Tensor& V = grp.exp_avg_sq[now_state];
587
588 auto it = invokers.find(std::tuple(P.scalar_type(), M.scalar_type()));
589 TORCH_CHECK(it != invokers.end(),
590 "ZenFlowAdam: unsupported param/state dtype combination");
591 auto fn = it->second;
592
593 char* pp = static_cast<char*>(P.data_ptr());
594 char* gp = static_cast<char*>(G.data_ptr());
595 char* mp = static_cast<char*>(M.data_ptr());
596 char* vp = static_cast<char*>(V.data_ptr());
597 char* sp = grp.stale.defined() ? static_cast<char*>(grp.stale.data_ptr()) : nullptr;
598 const size_t pe = P.element_size();
599 const size_t se = M.element_size();
600 const size_t numel = P.numel();
601
602 pool_->parallel_for(numel, kZenAdamAlign, [=](size_t b, size_t e) {
603 const size_t len = e - b;
604 // parallel=false: each pinned thread runs its slice serially.
605 fn(opt, pp + b * pe, gp + b * pe, mp + b * se, vp + b * se, len, false);
606 if (sp) std::memcpy(sp + b * pe, pp + b * pe, len * pe);
607 });
608 }
609 }
610
611 int opt_id_;
612 std::vector<ZenGroup> groups_;

Callers

nothing calls this directly

Calls 6

fnFunction · 0.85
numelMethod · 0.80
parallel_forMethod · 0.80
sizeMethod · 0.45
update_stateMethod · 0.45
data_ptrMethod · 0.45

Tested by

no test coverage detected