New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizer support via Libtorch C++ on Android #42665
Comments
I suppose you could YOLO removing the relevant line at
in |
We have already tried this option before. /home/atibrewal/work/hielibs_android/lib/libtorch_cpu.a(output-archive.cpp.o): In function |
cc @ann-ss who is working on a different project to remove dependence on InputArchive/OutputArchive from samplers |
We got this to work along with on device training support on Android by tweaking the cmakefiles to basically allow both options (Torch Script and CAFFE2_MOBILE modes) simultaneosly. To summarize, we did the following adaptations in the make file : The changes are part of this commit on a fork : Can someone please review and let us know if you foresee major issues with this change ? |
Your changes look reasonable. We'd probably be interested in taking them upstream, but if guarded as a flag (as not everyone is going to want on-device training). Thanks for the work! |
@ezyang Thank You ! I will cleanup the changes and raise a pull request. |
馃悰 Bug
We are building libtorch using ./scripts/build_anroid.sh.
We need the support for Aten Ops and TorchScript, so building without the BUILD_CAFFE2_MOBILE option.
The build is successful, but the library does not link ${TORCH_SRC_DIR}/csrc/api/src/optim/adam.cpp and dependencies because of NO_API being set for Mobile Builds.
Because of this I am unable to train the model and instantiate Adam Optimizer instance from the code.
torch::optim::Adam optimizer(parameters, lr); //Linker Error
optimizer.zero_grad(); //Linker Error
optimizer.step(); //Linker Error
Following is the Linker error:
/home/atibrewal/work/apprecommender/src/RNNRecommender.cpp:374: undefined reference to
torch::optim::AdamOptions::AdamOptions(double)' /home/atibrewal/work/apprecommender/src/RNNRecommender.cpp:375: undefined reference to
torch::optim::Optimizer::zero_grad()'/home/atibrewal/work/apprecommender/src/RNNRecommender.cpp:395: undefined reference to
torch::optim::Adam::step(std::__ndk1::function<at::Tensor ()>)' CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
OptimizerParamGroup':/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:68: undefined reference to
torch::optim::OptimizerParamGroup::params() const' /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:68: undefined reference to
torch::optim::OptimizerParamGroup::has_options() const'/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:68: undefined reference to
torch::optim::OptimizerParamGroup::options() const' CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
AdamOptions':/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/adam.h:21: undefined reference to
vtable for torch::optim::AdamOptions' /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/adam.h:21: undefined reference to
vtable for torch::optim::AdamOptions'CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
Adam': /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/adam.h:52: undefined reference to
vtable for torch::optim::Adam'/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/adam.h:52: undefined reference to
vtable for torch::optim::Adam' CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
OptimizerOptions':/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:49: undefined reference to
vtable for torch::optim::OptimizerOptions' /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:49: undefined reference to
vtable for torch::optim::OptimizerOptions'CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
Optimizer': /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:91: undefined reference to
vtable for torch::optim::Optimizer'/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:91: undefined reference to
vtable for torch::optim::Optimizer' /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:93: undefined reference to
torch::optim::Optimizer::add_param_group(torch::optim::OptimizerParamGroup const&)'CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o: In function
~Optimizer': /home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:103: undefined reference to
vtable for torch::optim::Optimizer'/home/atibrewal/work/hielibs_android/include/torch/csrc/api/include/torch/optim/optimizer.h:103: undefined reference to
vtable for torch::optim::Optimizer' CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o:(.data.rel.ro._ZTVN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE[_ZTVN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE]+0x18): undefined reference to
torch::optim::OptimizerOptions::serialize(torch::serialize::InputArchive&)'CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o:(.data.rel.ro._ZTVN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE[_ZTVN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE]+0x20): undefined reference to
torch::optim::OptimizerOptions::serialize(torch::serialize::OutputArchive&) const' CMakeFiles/hxRecommenderEngine.dir/src/RNNRecommender.cpp.o:(.data.rel.ro._ZTIN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE[_ZTIN5torch5optim25OptimizerCloneableOptionsINS0_11AdamOptionsEEE]+0x10): undefined reference to
typeinfo for torch::optim::OptimizerOptions'Environment
conda
,pip
, source): sourcecc @yf225 @glaringlee @vincentqb
The text was updated successfully, but these errors were encountered: