Matlab Deploy Ai Model logo

Matlab Deploy Ai Model

OrganizationPopular
matlab
matlab-deploy-ai-model

Generate 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.

Overview

Publishermatlab
Repositorymatlab-agentic-toolkit
Skill namematlab-deploy-ai-model
Stars
1.2K
Forks
138
Bundled files
15
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 15 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by matlab on GitHub. Read the source before you install it.

Installation

Install the Matlab Deploy Ai Model AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/code-generation/matlab-deploy-ai-model
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-ai-model .claude/skills/matlab-deploy-ai-model
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Matlab Deploy Ai Model in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Matlab Deploy Ai Model on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Matlab Deploy Ai Model is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Generate C/C++/CUDA Code from an AI Model

Generate deployable C/C++ or CUDA code from an AI model using MATLAB Coder or GPU Coder. The workflow follows a common pattern regardless of model framework: load, inspect, write entry-point, generate MEX, verify, then generate production code.

When to Use

  • User wants to generate C/C++/CUDA code from an AI model (PyTorch, LiteRT)
  • User has a model file (.pt2, .tflite) and wants to load it into MATLAB
  • User wants MEX acceleration for an AI model
  • User wants to generate CUDA code or GPU-accelerated MEX from an AI model
  • User wants to deploy an AI model to hardware
  • User wants to use a PyTorch or LiteRT model in Simulink (simulation or code generation)
  • User wants to verify AI model numerics between the source framework and MATLAB

When NOT to Use

  • General MATLAB Coder usage (codegen syntax, config tuning, writing codegen-ready code)
  • Editable dlnetwork for Deep Learning Toolbox workflows (quantization, compression, transfer learning) — use importNetworkFromPyTorch (PyTorch), importNetworkFromTensorFlow (SavedModel), or importNetworkFromKeras (.keras/.h5) which return a dlnetwork. For deployment of an editable dlnetwork with model compression (INT8 quantization via dlquantizer, pruning, projection) or exportNetworkToSimulink workflows — use matlab-deploy-embedded-ai (Pattern 1).
  • Training or fine-tuning — this skill is for inference code generation only

Supported Frameworks

FrameworkModel formatLoad functionStatus
PyTorch.pt2loadPyTorchExportedProgramSupported (R2026a+)
LiteRT / TFLite.tfliteloadLiteRTModelSupported (R2026a+)

For PyTorch-specific details (API routing, entry-point pattern, export workflow, data layout, common mistakes): see references/pytorch-workflow.md.

For LiteRT-specific details (API routing, entry-point pattern, variable-size inputs, Simulink integration, conventions): see references/litert-workflow.md. For converting TensorFlow/Keras/.h5 to .tflite: see references/tensorflow-to-litert-conversion.md.

Generic Workflow

The code generation workflow follows the same steps for any framework:

1. Load and Inspect

Load the model and check its input/output specifications to determine expected shapes and types.

2. Write Entry-Point Function

Create a codegen-compatible entry-point function that:

  • Loads the model from a file path
  • Runs inference on an input
  • Returns the output

The model file path must be wrapped with coder.Constant so it's known at compile time.

3. Verify Numerics

Compare MATLAB inference output against the source framework to confirm correct loading. Use the same input data in both environments and compare with tolerance.

4. Generate MEX (First!)

Always generate MEX before lib/exe to verify on the host machine:

CPU MEX:

matlab
cfg = coder.config("mex");
codegen -config cfg -args {coder.Constant("model_file"), input} entryPoint

CUDA MEX (GPU acceleration):

matlab
cfg = coder.gpuConfig("mex");
codegen -config cfg -args {coder.Constant("model_file"), input} entryPoint

For CPU MEX SIMD acceleration (SIMDAcceleration = 'Full' for AVX2 on Intel/AMD), see the matlab-generate-code skill. For the DNN- inference-specific MEX AVX2 ceiling, see references/dnn-codegen-options.md.

5. Verify MEX Output

Compare MEX output against MATLAB reference using matlab.unittest with tolerance:

matlab
refOut = entryPoint("model_file", input);
mexOut = entryPoint_mex("model_file", input);
testCase = matlab.unittest.TestCase.forInteractiveUse;
testCase.verifyThat(mexOut, matlab.unittest.constraints.IsEqualTo(refOut, ...
    'Within', matlab.unittest.constraints.AbsoluteTolerance(single(1e-5))));

6. Generate Library/Executable

Once MEX is verified, generate production code:

matlab
cfgLib = coder.config("lib");
cfgLib.TargetLang = "C++";  % set to "C++" for C++ output; default is "C"
codegen -config cfgLib -args {coder.Constant("model_file"), input} entryPoint

For DLL: coder.config("dll"). For executable: coder.config("exe").

CUDA variants: Replace coder.config with coder.gpuConfig.

Performance tuning:

  • Generic knobs (SIMD instruction sets, reduction-loop vectorization, multithreaded loops): see the matlab-generate-code skill.
  • MATLAB Coder ↔ Simulink Coder property naming duality and slbuild set_param patterns: see the matlab-deploy-embedded-code skill.
  • DNN-inference-specific knobs (DLTargetLibrary / DeepLearningConfig to disable third-party DL libraries, LargeConstantGeneration to serialize weights to data files): see references/dnn-codegen-options.md.

7. Use in Simulink

For Simulink integration, use the dedicated PyTorch ExportedProgram block from dlosslib — set ModelFilePath to the .pt2 file and it auto-detects input/output shapes. No entry-point function or coder.Constant needed.

Pre/post-processing can be done with Simulink blocks around the dedicated block. If you need everything in a single block, use a MATLAB Function block with loadPyTorchExportedProgram + invoke (same pattern as the entry-point, but the model path is a string literal — no coder.Constant).

Both paths support slbuild code generation (requires fixed-step solver + ERT or GRT target). See references/simulink-workflow.md for full details.

8. Deploy to Hardware (Optional — requires Embedded Coder)

For embedded deployment, use the same entry-point function with an Embedded Coder configuration. See the matlab-deploy-embedded-code skill for ERT config, hardware settings, PIL/SIL verification, and target-specific options. Ask the user to install the skill if it is not installed

Key Functions

FunctionPurposePackageSince
coder.ConstantMake argument a compile-time constantMATLAB CoderR2011a
coder.gpuConfigCreate GPU (CUDA) code generation configGPU CoderR2017b
codegenGenerate codeMATLAB CoderR2011a
loadPyTorchExportedProgramLoad .pt2 into MATLABMATLAB Coder Support Package for PyTorch and LiteRT ModelsR2026a
loadLiteRTModelLoad .tflite into MATLABMATLAB Coder Support Package for PyTorch and LiteRT ModelsR2026a

Conventions

  • Always check the model's input specifications for correct input shape and type
  • Always generate MEX first, verify, then proceed to lib/exe
  • Always use coder.Constant for the model file path argument
  • Input data is typically single-precision (check model input specs to confirm)
  • Do NOT use importNetworkFromPyTorch, importNetworkFromTensorFlow, or importNetworkFromKeras in this skill — they return a dlnetwork on a different path. If the user needs a dlnetwork for quantization, projection, pruning, or exportNetworkToSimulink before code generation, route to matlab-deploy-embedded-ai instead

References

  • references/pytorch-workflow.md — Full PyTorch-specific workflow: API routing, entry-point pattern, export guidance, common mistakes, and conventions. Consult for any PyTorch/.pt2 model code generation task. Links to deeper PyTorch references (API signatures, data layout, numeric verification, supported models).
  • references/export-pytorch-models.md — Exporting an eager-mode PyTorch model to .pt2 with torch.export (upstream of loading). Consult when the user has a PyTorch model but no .pt2 file yet, or hits torch.export SerializeError / kwarg-mismatch errors. Links to pytorch-export-patterns.md (per-source templates) and pytorch-export-gotchas.md (torch 2.11 serialization fixes).
  • references/simulink-workflow.md — Simulink integration: dedicated PyTorch ExportedProgram block (Path A) vs MATLAB Function block (Path B), block mask parameters, code generation config, and key differences from command-line codegen.
  • references/litert-workflow.md — Full LiteRT-specific workflow: API routing (loadLiteRTModel → inputSpecifications → invoke), entry-point pattern, variable-size input handling, Simulink integration, and conventions. Consult for any LiteRT/.tflite model code generation task.
  • references/tensorflow-to-litert-conversion.md — Converting TensorFlow SavedModel/Keras/.h5 to .tflite via the Python tf.lite.TFLiteConverter API. Consult when the user has a TensorFlow model but no .tflite file yet.
  • references/litert-numeric-verification.md — Verifying MEX numerics against MATLAB reference for LiteRT models (tolerance guidance, common mismatches).
  • references/codegen-workflow.md — Shared code generation steps for both PyTorch and LiteRT: MEX generation, MEX verification, library/executable targets, coder.Constant usage, and coder.DeepLearningConfig notes.
  • references/dnn-codegen-options.md — DNN-INFERENCE-SPECIFIC codegen options: DLTargetLibrary / DeepLearningConfig('none') for the plain-C DL path, LargeConstantGeneration for serializing large DNN weights to data files, and MEX SIMD ceiling in a DNN-inference context. Read this when the generic file's knobs need DNN-specific framing (e.g., "the MEX SIMD cap matters because inference is the target").

See Also

  • matlab-generate-code — Generic MATLAB Coder tuning (SIMD instruction sets, OpenMP multi-threading, reduction-loop vectorization). Consult for performance options not specific to DNN inference.
  • matlab-deploy-embedded-ai — dlnetwork-based codegen with model compression (quantization, pruning, projection) and exportNetworkToSimulink workflows (Pattern 1). Use it when the source is an editable dlnetwork in MATLAB rather than a .pt2 / .tflite file.
  • matlab-optimize-gpu-codegen — CUDA-target codegen tuning (coder.gpuConfig, kernel fusion, memory-hierarchy options) when the deployment target is an NVIDIA GPU rather than CPU or embedded hardware.

Copyright 2026 The MathWorks, Inc.


Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Matlab Deploy Ai Model AI skill do?

Generate 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 m...

Why use Matlab Deploy Ai Model on TypingMind?

Because you install it once and use it with any model. Matlab Deploy Ai Model is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Matlab Deploy Ai Model in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/code-generation/matlab-deploy-ai-model. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Matlab Deploy Ai Model?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Matlab Deploy Ai Model?

As many as you like. As long as a model supports skills, you can use Matlab Deploy Ai Model with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Matlab Deploy Ai Model AI skill free?

It is published on GitHub by matlab. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇