Create an instance of AdamParamState
I need to create an instance of AdamParamState. I looked through the adam.cpp code as an example, and accordingly copied the following code from there. But, with the provided headers, it still does not recognize AdamParamState.
I appreciate any help or comment on this matter.
#include &lt;torch/optim/adam.h&gt;
#include &lt;torch/csrc/autograd/variable.h&gt;
#include &lt;torch/nn/module.h&gt;
#include &lt;torch/serialize/archive.h&gt;
#include &lt;torch/utils.h&gt;

#include &lt;ATen/ATen.h&gt;

void get_state(torch::optim::Optimizer *optimizer){
    for (auto&amp; group : optimizer-&gt;param_groups()) {
        for (auto &amp;p : group.params()) {
            if (!p.grad().defined()) {
                continue;
            }

            auto grad = p.grad();
            TORCH_CHECK(!grad.is_sparse(),
                        &quot;Adam does not support sparse gradients&quot;/*, please consider SparseAdam instead*/);
            ska::flat_hash_map&lt;std::string, std::unique_ptr&lt;torch::optim::OptimizerParamState&gt;&gt;&amp; state_ = optimizer-&gt;state();
            auto param_state = state_.find(c10::guts::to_string(p.unsafeGetTensorImpl()));
            auto tmp_ = p.dim();
            int tmp_0;
            int tmp_1;
            if (tmp_ &gt; 0)
                tmp_0  = p.size(0);
            if (tmp_ &gt; 1)
                tmp_1  = p.size(1);

            std::cout &lt;&lt; tmp_ &lt;&lt; tmp_0 &lt;&lt; tmp_1 &lt;&lt; std::endl;
//                auto&amp; options = static_cast&lt;AdamOptions&amp;&gt;(group.options());
            auto&amp; state = static_cast&lt;AdamParamState&amp;&gt;(*state_[c10::guts::to_string(p.unsafeGetTensorImpl())]);
        }
    }

}


I found that this works:
auto&amp; state = static_cast&lt;torch::optim::AdamParamState&amp;&gt;(*state_[c10::guts::to_string(p.unsafeGetTensorImpl())]);
very simple and juicy!
