Can a model serialized by torch.jit.trace
be used for training? In the documentation it seems the ScriptModule
is intented for inference and only training example is for torch::nn::Module
. I wonder if training with ScriptModule
is officially supported and is there documentation on that.
Related:
opened 01:02PM - 01 Mar 19 UTC
oncall: jit
module: docs
module: cpp
triaged
## 📚 Documentation
I am interested in the following workflow, but my impressi… on is that this use case is not supported (yet?):
1. Prototype a model in **Python**
2. Export model to **C++** via TorchScript (`torch.jit.trace`)
3. Train model in **C++**
Based on the documentation, it is unclear whether this workflow is supported or not. The very first sentence of https://pytorch.org/docs/master/jit.html states
> TorchScript is a way to create serializable and **optimizable models** from PyTorch code
However, it is ambiguous if "**optimizable**" refers to training or the jit compilation process here.
It seems that `torch::jit::script::Module` is treated as a special case which does not share commonality / a base class with `torch::nn::Module`. Is there also a way to access the parameters of a `torch::jit::script::Module` in order to use it for training? At first I thought "**optimizable models**" was referring to this but I am unsure now.
This issue is related to the post: https://discuss.pytorch.org/t/can-scriptmodule-be-used-for-training/35932
cc @suo @yf225