Embodied AI Glossary中文

TorchScript (torch.jit) / LibTorch

TorchScript / LibTorch(策略导出与 C++ 部署)Advanced

Exports a PyTorch model to a file that runs without Python, then loads it from C++.

TorchScript is PyTorch's built-in model serialization format: torch.jit.trace (records the computation by running one example input through the model) or torch.jit.script (parses the code directly) converts a model into a .pt file that stores both its structure and its weights. LibTorch is the C++ distribution of PyTorch, letting a C++ program load that file with torch::jit::load and run inference. Robot control software is mostly written in C++ and needs a stable real-time loop, and this path lets a trained reinforcement learning policy run on the robot without depending on a Python environment. PyTorch officially now considers TorchScript to be in maintenance mode and recommends newer options such as torch.export or ONNX for new projects, but a large amount of open-source locomotion-control code still uses it.

Examplelegged_gym's play script can export a trained walking policy as a JIT-format policy.pt; the deployment code loads it inside a C++ control loop, feeding in observations and reading out joint targets every control cycle.

Also called
torch.jit, JIT export, LibTorch
Related
PyTorch · Open Neural Network Exchange (ONNX) · Inference Deployment · legged_gym · On-Device / Edge Deployment · Python and C++
Sources
TorchScript — PyTorch documentation
Loading a TorchScript Model in C++

See it in the full glossary →