RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • adamupdate
    • analyzeNetwork
    • bilstmLayer
    • classificationLayer
    • combvec
    • convolution1dLayer
    • crossentropy
    • dlarray
    • dlfeval
    • dlgradient
    • dlnetwork
    • dlupdate
    • eluLayer
    • exportONNXNetwork
    • featureInputLayer
    • forward
    • fullyConnectedLayer
    • globalAveragePooling1dLayer
    • layerGraph
    • layerNormalizationLayer
    • lstmLayer
    • padsequences
    • regressionLayer
    • reluLayer
    • sequenceInputLayer
    • softmaxLayer
    • trainingOptions
    • trainnet
    • trainNetwork

dlgradient — Differentiate a traced scalar dlarray loss.

dlgradient(loss, targets...) backpropagates through the bounded automatic-differentiation tape installed by dlfeval.

Syntax

gradients = dlgradient(loss, targets...)
[g1,g2] = dlgradient(loss, target1, target2)

How dlgradient works

  • dlgradient must be called inside a dlfeval callback and loss must be a scalar traced dlarray value.
  • Host dlarray elementwise plus, minus, times, rdivide, matrix mtimes, and scalar sum(...,'all') participate in the tape.
  • Supported dlnetwork forward passes trace fully-connected, ReLU, ELU, and softmax layers and return gradients for matching Learnables trees.
  • Learnables structs, tables, cells, and dlnetwork objects preserve Layer and Parameter metadata while replacing Value entries with gradient dlarray values.
  • Implicit-expansion gradients are supported for scalar broadcasts; higher-rank broadcast-gradient reductions, custom layers, recurrent/stateful layers, and complex/autodiff over sparse data are unsupported.

GPU memory and residency

GPU-backed dlarray autodiff is rejected with an explicit provider-gap error. Plain GPU array math remains available outside the Deep Learning tape where the relevant builtin/provider hooks support it.

Example

Differentiate a custom loss

[loss,gradients] = dlfeval(@modelLoss, net, X, T)
function [loss,gradients] = modelLoss(net,X,T)
    Y = forward(net,X);
    loss = sum((Y - T).^2,'all');
    gradients = dlgradient(loss, net.Learnables);
end

Expected output:

gradients matches the learnables tree shape.

Using dlgradient with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how dlgradient changes the result.

Run a small dlgradient example, explain the result, then change one input and compare the output.

Related Deep Learning functions

adamupdate · analyzeNetwork · bilstmLayer · classificationLayer · combvec · convolution1dLayer · crossentropy · dlarray · dlfeval · dlnetwork · dlupdate · eluLayer · exportONNXNetwork · featureInputLayer · forward · fullyConnectedLayer · globalAveragePooling1dLayer · layerGraph · layerNormalizationLayer · lstmLayer · padsequences · regressionLayer · reluLayer · sequenceInputLayer · softmaxLayer · trainingOptions · trainnet · trainNetwork

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how dlgradient is executed, line by line, in Rust.

  • View the source for dlgradient in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • How dlgradient works
  • GPU memory and residency
  • Example
  • Differentiate a custom loss
  • Using dlgradient with coding agents
  • Related Deep Learning functions
  • Open-source implementation
  • About RunMat