In Python one can get the the underlying data of an optimizer by calling the optimizer.state_dict()
. For example for the Adam optimizer, it returns the number of steps, exponential moving average of gradient values, and exponential moving average of squared gradient values. I was trying to access the same values in the C++ version of torch, but it seems that it is not straight-forward to get them. I looked into the Adam optimizer implementation at:
But, still it is not clear to me how to get those.
I looked into optimizer->state()
which can be obtained by:
ska::flat_hash_map<std::string, std::unique_ptr<torch::optim::OptimizerParamState>>& state_ = optimizer->state();
and it does not look like what I was expecting.
Does anyone know how can I access the number of steps, exponential moving average of gradient values, and exponential moving average of squared gradient values in C++ API?