Tracing

Tracing records operations, scripting parses Python

Image: 世書 名付, CC-BY-2.0, via Wikimedia Commons

Tracing

Tracing records operations, scripting parses Python

Tracing in TorchScript involves recording the operations performed by a PyTorch model during execution. This process creates a serialized representation of the model that can be run independently of the original Python code. Scripting, on the other hand, involves translating the PyTorch model into a TorchScript format that can be executed in a different environment, such as C++.

Example

Suppose you have a PyTorch model for image classification. By tracing this model with a sample input, TorchScript records the operations performed. Later, you can convert the traced model into TorchScript code, which can then be deployed in a C++ application for inference.

Understanding the difference between tracing and scripting is crucial for optimizing model deployment and ensuring compatibility across different programming environments. Tracing captures the model's behavior, while scripting transforms it for execution in other languages.

Related concepts

One email a day: 5 concepts + the 5 stories that matter →

Swipe through 100 ML concepts daily

Open TickerNews