matlab/matlab-agentic-toolkit / skills-catalog/code-generation/matlab-deploy-ai-model
matlab-deploy-ai-model
VerifiedGenerate C/C++ or CUDA code from an AI model (PyTorch, LiteRT) using MATLAB Coder or GPU Coder. Use when the user wants to integrate an AI model into an application with code generation as the end goal — generating MEX, CUDA MEX, static library, dynamic library, or executable — or using the model in Simulink for simulation and code generation. Covers PyTorch ExportedProgram (.pt2) via loadPyTorchExportedProgram and LiteRT (.tflite) via loadLiteRTModel (R2026a+). Keywords: PyTorch, torch, .pt2, ExportedProgram, loadPyTorchExportedProgram, invoke, codegen, MEX, CUDA, GPU, C, C++, deploy, AI model, deep learning model, LiteRT, TFLite, TensorFlow Lite, Simulink, slbuild, PyTorch ExportedProgram block, MATLAB Function block, dlosslib, loadLiteRTModel.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.8 KB |
| manifest.yaml | config | 617 B |
| references/codegen-workflow.md | markdown | 4.0 KB |
| references/dnn-codegen-options.md | markdown | 6.9 KB |
| references/export-pytorch-models.md | markdown | 4.6 KB |
| references/litert-numeric-verification.md | markdown | 3.8 KB |
| references/litert-workflow.md | markdown | 14.7 KB |
| references/pytorch-api-reference.md | markdown | 2.6 KB |
| references/pytorch-data-layout.md | markdown | 4.1 KB |
| references/pytorch-export-gotchas.md | markdown | 4.7 KB |
| references/pytorch-export-patterns.md | markdown | 5.2 KB |
| references/pytorch-numeric-verification.md | markdown | 2.6 KB |
| references/pytorch-supported-models.md | markdown | 3.4 KB |
| references/pytorch-workflow.md | markdown | 5.7 KB |
| references/simulink-workflow.md | markdown | 12.7 KB |
| references/tensorflow-to-litert-conversion.md | markdown | 5.8 KB |
references/pytorch-api-reference.md
View on GitHub# PyTorchExportedProgram API Reference
## loadPyTorchExportedProgram
Loads a PyTorch ExportedProgram (.pt2) file into MATLAB.
```matlab
model = loadPyTorchExportedProgram(modelFileName)
model = loadPyTorchExportedProgram(modelFileName, ExecutionMode=mode)
```
**Arguments:**
| Argument | Type | Description |
|----------|------|-------------|
| `modelFileName` | char vector or string | Path to the `.pt2` file |
| `ExecutionMode` (name-value) | `"JIT"` or `"MEX"` | Simulation behavior. `"JIT"`: faster load, no OpenMP. `"MEX"`: slower initial compile, requires a host C compiler, OpenMP parallelization for better performance. Default: `"JIT"` |
**Returns:** `PyTorchExportedProgram` object
**Introduced:** R2026a
## PyTorchExportedProgram Object
### Properties
| Property | Type | Description |
|----------|------|-------------|
| `ModelPath` | char vector | Absolute path to the loaded .pt2 file |
| `FcnNames` | cell array of char vectors | Function names defined in the model |
### Methods
| Method | Signature | Description |
|--------|-----------|-------------|
| `invoke` | `out = invoke(model, input)` | Run forward inference |
| `inputSpecifications` | `specs = model.inputSpecifications` | Return input specs struct (Name, Size, Type) |
| `outputSpecifications` | `specs = model.outputSpecifications` | Return output specs struct (Name, Size, Type) |
| `summary` | `summary(model)` | Display input/output specifications to command window |
### invoke
Performs forward inference on the model.
```matlab
output = invoke(model, input);
```
- Input must match the shape and type reported by `inputSpecifications`
- Data layout is preserved from PyTorch — see `pytorch-data-layout.md` for details
- Output shape and type match `outputSpecifications`
- Supports C/C++ code generation (MATLAB Coder) and GPU code generation (GPU Coder)
### inputSpecifications / outputSpecifications
Returns a struct with fields:
| Field | Type | Description |
|-------|------|-------------|
| Name | cell array of char vectors | Tensor names from the PyTorch model |
| Size | cell array of numeric arrays | Dimensions of each tensor |
| Type | cell array of char vectors | MATLAB data type (e.g., `'single'`) |
Example:
```matlab
model = loadPyTorchExportedProgram("resnet18.pt2");
inSpecs = model.inputSpecifications;
% inSpecs.Size{1} might be [1 3 224 224]
% inSpecs.Type{1} might be 'single'
```
## Requirements
- MATLAB Coder Support Package for PyTorch and LiteRT Models (add-on)
- PyTorch 2.7.0–2.8.0 for R2026a
- The `.pt2` file must be accessible at the path specified during codegen
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |