loadPyTorchExportedProgram
Syntax
Description
Add-On Required: This feature requires the MATLAB Coder Support Package for PyTorch and LiteRT Models add-on.
loads a pretrained PyTorch® ExportedProgram model file.model = loadPyTorchExportedProgram(modelFileName)
Note
This function takes a PyTorch ExportedProgram model file as input. You must first export a PyTorch model to a torch.export.ExportedProgram in PyTorch
2.8.0, and save it as a PyTorch ExportedProgram file. For more information, see Prepare PyTorch Models for MATLAB and Simulink Code Generation.
loads a pretrained PyTorch ExportedProgram model file using the specified execution mode.model = loadPyTorchExportedProgram(modelFileName,ExecutionMode=ExecutionMode)
Examples
Input Arguments
Output Arguments
Limitations
You must first export a PyTorch model to a torch.export.ExportedProgram in PyTorch 2.8.0, and
save it as a PyTorch ExportedProgram file. loadPyTorchExportedProgram does not support
loading:
Models saved in MAT-files.
Quantized models.
Models with complex data types.
Models exported using CUDA tensors. You must move both the model parameters and tensor inputs to CPU before exporting the model.
Models that return custom output classes. If the model has a custom output class, wrap it in a custom
nn.Moduleso that it returns only native tensors or standard Python containers. This removes any external class dependencies from the exported graph.
Extended Capabilities
Version History
Introduced in R2026a