@tancl There are a few scenarios that C++/TorchScript serialization supports:

Save as C++ model, load using torch::load() in C++

Requirement: You need to have the same C++ model class definition available when you use torch::save and torch::load. The easiest way to achieve this is to put the model class definition in a common header file.


If you want to be able to debug the model in Python, the suggested way is to define the model in Python (and perform debugging), convert it to TorchScript, and then load the model using torch::jit::load in C++ (for details on this process, see https://pytorch.org/tutorials/advanced/cpp_export.html 40).

These are scenarios that C++/TorchScript serialization doesn’t support:

Save as C++ model using torch::save, load using torch::jit::load in C++
Save as C++ model using torch::save, load using torch.load in Python
Save as C++ model using torch::save, load using torch.jit.load in Python