Problems with loading the model with libtorch

I trained a CNN model with libtorch. And I successfully save the model using “torch::save(model,“model.pt”)”. But when I load the model in other project and use it for inference" model->forward(input)", the code throws out error “Method forward is not defined.”. I tried several ways to save model like OutputArchive, but none of them works.
By the way, I know the .pt file can be unzipped. After unzipping it , in “./code/torch.py”, there is no defination for forward.
Any one can give me some help? Thanks!

Thanks! I tried torch::save, but when I load the model with torch::load, there is an error “The operator << should be overloaded.” And I changed the defination of the model from “class” to “struct” and added “TORCH_MODULE”. Everything works well.
As for torch::jit::trace, my compiler asserts "There is no class or namespace trace in torch::jit ". However, i found there is “trace” method in namespace torch::jit::tracer.

I got the same problem. how did you make it work?