| 964 | }; |
| 965 | |
| 966 | class pyAdam : public py::class_<graphvite::Adam, graphvite::Optimizer> { |
| 967 | public: |
| 968 | typedef graphvite::Adam Adam; |
| 969 | typedef py::class_<Adam, graphvite::Optimizer> Base; |
| 970 | using Base::def_readonly; |
| 971 | using Base::def; |
| 972 | |
| 973 | template<class... Args> |
| 974 | pyAdam(py::handle scope, const char *name, const Args &...args) : |
| 975 | Base(scope, name, args...) { |
| 976 | attr("__doc__") = "Adam(lr=1e-4, weight_decay=0, beta1=0.999, beta2=0.99999, epsilon=1e-8, schedule='linear')" |
| 977 | R"( |
| 978 | Adam optimizer. |
| 979 | |
| 980 | Parameters: |
| 981 | lr (float, optional): initial learning rate |
| 982 | weight_decay (float, optional): weight decay (L2 regularization) |
| 983 | beta1 (float, optional): coefficient for moving average of gradient |
| 984 | beta2 (float, optional): coefficient for moving average of squared gradient |
| 985 | epsilon (float, optional): smooth term for numerical stability |
| 986 | schedule (str or callable, optional): learning rate schedule |
| 987 | )"; |
| 988 | |
| 989 | // data members |
| 990 | def_readonly("beta1", &Adam::beta1); |
| 991 | def_readonly("beta2", &Adam::beta2); |
| 992 | def_readonly("epsilon", &Adam::epsilon, ""); |
| 993 | |
| 994 | // member functions |
| 995 | def(py::init<float, float, float, float, float, graphvite::LRSchedule>(), py::no_gil(), |
| 996 | py::arg("lr") = 1e-4, py::arg("weight_decay") = 0, py::arg("beta1") = 0.999, py::arg("beta2") = 0.99999, |
| 997 | py::arg("epsilon") = 1e-8, py::arg("schedule") = "linear"); |
| 998 | } |
| 999 | }; |
| 1000 | |
| 1001 | std::function<py::object(const std::string &, py::args, py::kwargs)> optimizer_helper(const py::module &module) { |
| 1002 | return [module](const std::string &type, py::args args, py::kwargs kwargs) { |
nothing calls this directly
no outgoing calls
no test coverage detected