- Make it possible to load and run models in C++ without a Python environment
- JITs the model, making it faster.
- Tutorials
- Tracing looks at actual code flow and generates the IR
- Use scripting to eliminate redundant code / constant checks and speed them up
- Script compiler converts the code into the IR
- script = TorchScript compiler returning a ScriptModule/ScriptFunction
- direct analysis fo python to create torchscript
- trace = traces functions to return ScriptFunction
- calls to trace accept sample inputs
- .graph property on traces to see what it looks like – aten functions
- .code property to see syntax
- better to capture constants as constants instead of dynamic values
- torchscript compatible python is converted and the rest is discarded
- scripted functions can call traced functions & vice versa
- torchscripted code runs on a restricted python interpreter without the gil
- Torchscript supports
- functions with single static type
- Any, lambda are not supported
- default argument type is a Tensor
- empty list is a list of tensors
- empty dict is [str, Tensor]
- (somewhat limited)
- simple classes that have been annotated with torch.jit.script
- Torch.fx
- symbolic tracer
- python to python transformation of code
- produces a different IR
- also supports .code and .graph