Running Pytorch without Python
TorchScript enables users to load Pytorch models in processes where there is no python dependency. Instead of running the process in Python runtime, it converts the model to be able to run in an independent “Torchsript” runtime.
Built-in Functions
It has 2 modes; “Eager Mode” which runs models in Python runtime and “Script Mode” which runs models in Torchscript runtime.
There are 2 ways to convert a Pytorch model to a Torchscript Module.
- TORCH.JIT.TRACE
Records all tensor operations and converts to a Torchscript Module by passing down a dummy variable. Since it only records tensor operations, processes such as logging and other non-tensor-operation-related processes won’t be recognized(check image for example). -
TORCH.JIT.SCRIPT
Has full visibility to all python code.