A machine-learning library in Rust, on Burn.
Dashmag is a general machine-learning library in Rust. Burn beneath it supplies tensors, autodiff and devices; Dashmag adds the compute layer that applications build on, and inference. Together they are meant to do for Rust what PyTorch does for Python.
Dashmag is two families of crates. dash is the operations, the same on every platform: the
dash- crates are the library, on the hardware of one machine. mag is the pathway from one
algorithm to whatever devices are there, on every platform: the mag- crates, young, make one
pool of the machines a person has and run work across them, so far small jobs of the units built
into its program. Three crates make it (below).
dash + mag = Dashmag.
The compute layer is the operations Burn does not have, in forward, backward and decoding-step forms with kernels for Burn's backends; layers, such as LoRA; autodiff utilities, such as activation checkpointing; and the modules training uses (losses, optimisers, learning-rate schedules). Each is built for a family of models (transformers for language, convolutional networks), not shaped to one, and each operation is benchmarked on its own, at the shapes its workload gives it. Inference runs trained models, a whole model in one forward call, tensors in and tensors out, on whatever hardware is at hand, with exits to the compilers of accelerators Burn cannot drive. Each part is held to values recorded from the implementation it replaces (PyTorch, torchvision, Pillow, transformers, PEFT), and each test says where its recording comes from.
What sits above both is the application's, written on top of Dashmag: modules and training code shaped to its own model, its training loop and training algorithms (PPO, GRPO and their kind), the generation loop that calls a model step by step, samples, keeps each sequence's state and decides when to stop, and its task harness. For a generation loop Dashmag gives the decoding-step operations, such as attention against a key-value cache and the gated delta rule's recurrent step.
Status: pre-alpha, moving fast. APIs will change.
| Crate | What it is | Status |
|---|---|---|
dash-models |
model architectures over dash-mag's tensor, one source for every device it builds for, named so that published PyTorch weights load unchanged, with PyTorch checkpoints read directly; MobileNetV3-Small with any number of heads, for inference and training |
torchvision's weights give torch's answer on Flex, on CUDA and on MLX; on Flex the logits of the Burn module it replaced, bit for bit, and one training step's gradients within 87.9 roundings of that module's, the widest of three CPUs measured, held when it was removed |
dash-ops |
operations Burn lacks, for training and decoding, each with a reference, a written-out backward pass and CubeCL kernels for any runtime whose device offers what they ask: attention with the masks models train with, keeping no T x T scores; the gated delta rule and causal depthwise conv1d, over packed sequences and from given states; chosen-token log-probabilities and cross-entropy fused with the output layer over a large vocabulary; the low-rank product LoRA's layers use; activation checkpointing; and 2-D convolution, Burn's own under the contract's checks | agrees with PyTorch, transformers and fla on the CPU, on CUDA, on ROCm, through wgpu and on CubeCL's CPU runtime; 2-D convolution with torch on Flex, CUDA and ROCm |
dash-contract |
the contract of dash-ops' operations, written once for every implementation of them: what each computes and matches, its shapes, layouts, dtypes, masks and states, and its options as plain data, with no framework beneath it |
— |
dash-conformance |
the operation-level tests of dash-contract's operations, written once for every implementation of them and run through a thin adapter: the recorded fixtures, the error measures and the bounds; conv1d, 2-D convolution, the gated delta rule, the chosen-token log-probability and attention so far (not published) |
dash-ops passes them on Flex, on CUDA, through wgpu and on CubeCL's CPU runtime; 2-D convolution's on Flex, CUDA and ROCm |
dash-mlx |
dash-ops' operations on MLX, with their contracts, for Apple silicon: attention, conv1d, 2-D convolution (MLX's own, from torch's layout), the gated delta rule, chosen-token log-probabilities, the fused linear cross-entropy, the low-rank product, recompute and sampling, with Metal kernels where MLX's operations fall short | conv1d, the gated delta rule, the log-probability and attention pass dash-conformance's tests; the others are held to dash-ops' tests by ports of them; 2-D convolution held to torch's on an Apple M5; not published |
dash-mag |
the one crate an application names, the gateway to dash and, as they are built, to the mag- crates (it does not reach mag-by yet): a tensor, its array operations, a vector-Jacobian product, the operations' entry points, LoRA's layer and PEFT's adapter files (dash_mag::peft, host data only), rotary embeddings, AdamW and clipping, a multi-head classifier's loss and the losses of heads that output continuous values (L1, MSE, Huber and binned regression), batch normalisation, relu, hard_sigmoid and hard_swish, OneCycleLR, macro-F1 and calibration, over dash-ops or dash-mlx, the side chosen at compile time, and the device by its index before the first tensor. |
on Burn and on MLX: every entry point the same bits as dash-ops or dash-mlx, one training step from one source held to one recording; LoRA's layer and AdamW held to PEFT's and torch's recordings; PEFT's files written back byte for byte; AdamW under OneCycleLR and clipping held to torch's on Flex; 2-D convolution and batch normalisation held to torch's on Flex, CUDA, ROCm and MLX; the regression heads' losses held to torch's on Flex and CUDA |
mag-by |
the words the mag- crates share: the graph of a job's parts, its checks with typed refusals, the level of trust each part's data is kept at, and the pool's words (offers, arrangements, records, a pool's description and its ledger, the host's stamp on a job, taking a machine back, and a member's start file); with the graph feature, the files in JSON (the graph, the pool, the ledger's lines and the start file; version 1 files still read) with their JSON Schemas, and DOT for a person to look at; no_std with no dependencies unless graph is on |
its tests hold the checks, the levels of trust, each file's refusals and the kept schemas and DOT to the code; CI builds the default for a no_std target with an empty dependency tree |
mag-mortar |
the placement library of a pool: the loop, which on each event lists the ways to place the waiting jobs, removes those that break a constraint (memory, tolerance, dtypes, a pin, a job's need, the devices the host's stamp allows, the guard on the levels of trust), scores the rest from the devices' measured costs and the jobs' priorities, commits the best and records every candidate; describe and plan for an author; what the pool asks of its host, which the host polls (asks: the kind of device it most wants while jobs wait, and the members idle past the host's idle time, never the coordinator); the pool's state as a ledger its host saves and replays; mag plan, a command over files. It does no I/O, and runs on offers given as data; mag-mar's coordinator runs it |
its tests hold each constraint, the guard, priorities and the record, a part only on a member that carries its unit, the plan against the submit, the replay of every prefix of a run, and the command's kept output; trying candidates on a job's own steps is not built |
mag-mar |
the program every member of a pool runs, the same on each: it joins the pool at the coordinator, offers its one device, runs the parts placed on it one item at a time, sends what an edge carries to the member of the next part, and gives its device back on SIGTERM; on the member the host names, the coordinator, which runs mag-mortar's loop, writes the pool's ledger and takes it up again after a stop, and serves the door, where a command submits a job with its data, ends one, asks the pool's status, takes a device back by need and writes a job's results out; the units it carries, split and sum, and built for a backend, linear, relu and add over dash-mag; the link between members, one channel per job over TCP with TLS 1.3, both ends holding certificates from the pool's own authority; certs, the command that makes the authority and the members' certificates |
its tests run members, the coordinator and the door over loopback, in CI: two members running a job's parts, each result counted once, a member leaving mid-job and its part placed again once a member joins, running only the items without a result, a coordinator killed and started on its ledger, and a job of linear and relu handed in at the door on Flex, its results bit for bit; by hand, three containers on CPU (last on 2026-12-04), and one job across a CUDA, a ROCm and an MLX machine (once, 2026-12-03) |
dash-image |
image preprocessing: JPEG decode, Pillow's luma for a gray model, Pillow-exact bilinear resize, normalisation | byte-exact with Pillow's resize and luma |
dash-core |
the inference trait: tensors, capability negotiation, dispatch across runtimes; its heads class heads or heads of continuous values; with the model-json feature, model.json, a model's description as its trainer writes it and dash --meta reads it, and the training set and predictions files beside it |
each file read, written and read again to the bit; predictions of class heads byte for byte as before |
dash-burn |
the models that are code behind that trait: a dash-models architecture built from its weights and run on dash-mag's device, one a build: Flex (pure-Rust CPU), CUDA or ROCm, or MLX on macOS |
runs on x86-64 (Flex), on CUDA and on MLX |
dash-tract |
pure-Rust CPU runtime (tract) | runs on x86 and aarch64 |
dash-iree |
compiled artifacts via IREE (CPU, CUDA) | runs on CPU and CUDA GPUs |
dash-tensorrt |
NVIDIA TensorRT (Jetson GPUs) | runs on Jetson |
dash-edgetpu |
Coral Edge TPU | not yet run on hardware |
dash-cli |
dash, a command-line runner over every runtime above |
— |
PROGRESS.md says what has been measured, on which hardware, and what has not run yet.
- As code. A model is a Rust type over
dash-mag's tensor (dash-models), trained by the application that uses it, with Dashmag's operations and training modules, and run bydash-burn, or bydash --backend burn, on the devicedash-magis built for. Published PyTorch weights for adash-modelsarchitecture load directly, anddash-importconverts a PyTorch checkpoint into the safetensors filedash-burnreads. - As an artifact. tract and TensorRT run an ONNX file, IREE a module compiled from one
(
tools/compile_iree.sh), the Edge TPU an int8 TFLite file. Today the ONNX files are exported from PyTorch (tools/export_*.py); writing them in Rust, a writer per architecture from the model's type and its weights, is planned, so that both ways start from the same model.
The inference seam is whole-model inference — load a model, tensors in, tensors out — so runtimes of very different shapes sit behind one trait. Each runtime advertises its real capabilities, and a registry selects the best admissible one per target, refusing rather than guessing when nothing fits. Runtimes are feature-gated crates, so every target compiles only what it can build, and a conformance test holds them to each other.
The IREE, TensorRT and Edge TPU runtimes are currently spikes that drive their vendor tool as a subprocess; each crate's docs name the in-process FFI shim that replaces it. They are labelled as such in the source rather than presented as finished.
People who train and run models at home or in a small lab usually have several unequal machines: a workstation with one GPU, a second box with another vendor's card, a laptop with its own accelerator, now and then a rented cloud GPU for a night. Each is too small for some job, and most of them are idle most of the time. mag makes them one pool. A cluster under Slurm is the same problem with more machines.
The work is divided as it is between Slurm and an MPI library:
- The author of an algorithm, often an AI agent, writes each part's function with dash's operations, and a graph of the job, which names no device. The graph says what the parts are (a function, the weights it holds, the memory it needs, where it can stop), what flows between them and how large it is, which parts may run as many copies, where a model may be divided between devices, and what the job needs: a rate or a deadline, and how much it weighs against other jobs.
- A host gives the pool its machines and starts the same program on each: a person with a list of machines, Slurm on a cluster, or a home system. It decides which machines are in the pool, and when one is taken back. It never reads a graph.
- The pool, which is mag, places every job submitted to it against the others: it queues them, weighs their priorities, decides which device each part runs on, which job yields when a more urgent one arrives, and places again when the host takes a machine back. One of the pool's machines coordinates; the host names it and starts it like any other.
- dash runs the operations on each device.
mag does not decide which machines it gets, does not wake them, and does not take them back:
that is the host's, as it is Slurm's and not MPI's. mag-mortar is the placement library the
coordinator runs; mag-mar is the program on every machine, the coordinator's too. mag keeps
no server of its own, and is the same code under every host.
A pool of a few machines, listed by hand, runs jobs whose parts are the units built into
mag-mar. With Docker, bash and python3, from the repository's root,
examples/machine-list/three-containers.sh
builds the program, starts it in three containers on CPU, one of them the coordinator, and
submits three jobs at its door: two of split then sum, and a small MLP of linear and relu,
3000 items each. It sends one member SIGTERM while they run, and checks every result against
the one Python works out, bit for bit, and the pool's ledger: each result once. On your own
machines you write the pool file and a start file for each, make the pool's certificates with
mag-mar's certs, start MAG_START=start.json mag-mar on each, and at the coordinator's door
submit a job with its data, follow it and write its results out:
MAG_START=start.json mag-mar door submit mlp.json --item numbers item-0 --weight w1 ...
MAG_START=start.json mag-mar door status
MAG_START=start.json mag-mar door result mlp results
The list-of-machines recipe gives every command and file, and what each
printed. Each member runs the parts the pool places on its device, one item at a time, and sends
what an edge carries to the member of the next part on the job's own channel, over TLS 1.3 with
certificates from the pool's own authority; the coordinator counts each result once. A member
sent SIGTERM stops its parts at their next step, gives its device back within its
give_back_seconds and exits 0; the pool places the job again on what is left, or holds it until
a device it needs joins, and the items without a result run again from their first part.
What has run, and how:
- In CI, on every pull request:
mag-mar's tests, which run members, the coordinator and the door over loopback, and a job ofsplit,linear,reluandsumhanded in at the door with its items and weights, on Flex, its results bit for bit what the test works out (crates/mag-mar/tests/backend.rs). - By hand, three containers on CPU (recipe 1c,
three-containers.shabove), last on 2026-12-04. - By hand, three machines, once (recipe 1d, on 2026-12-03): one with a CUDA card, one with a ROCm card and a Mac with MLX, a small MLP with each of its three layers pinned to one of them, the Mac taken back while it ran and started again. Each of the 2000 results was within a bound worked out for it of the same graph run on a CPU, and in the ledger once.
The placement algorithm is not yours to write: it is mag-mortar's. Which machines are in the
pool is not mag's: it is the host's. What you write is each part's function, with dash's
operations, and the graph; on a list of machines, the pool file and the start files as well. In
this table "is to" marks what is not built.
| thing | whose | on a list of machines | under Slurm | in a home system |
|---|---|---|---|---|
| each part's function | yours to write, with dash's operations; the graph names it as a Unit (a name and a version), and the program each machine runs carries it, built in: mag-mar carries split and sum, and built for a backend, linear, relu and add over dash-mag. A member says the units it carries as it joins, and the pool places a part only on a member that carries its unit. A unit of your own goes into a program of your own: mag-mar's program over its library (mag_mar::program), given its units with yours registered besides, as examples/own_units.rs is, and started in place of mag-mar on each member that is to run your parts; a new unit is a new build on those machines. Handing a running pool a unit's code is not built, nor decided |
the same | the same | the same |
| the job's graph | yours to write; mag-by reads and checks it (Graph::from_json, Graph::check, schemas/mag-graph.schema.json) |
the same | the same | the same |
| which machines are in the pool | the host's | you write the pool file; the list-of-machines recipe has one for three machines, and says where each field comes from | the allocation, one Slurm job per machine; turning it into a pool description is not built | that system's |
the pool's description: its members, the level each is trusted at (outside, site or owner), how soon it gives a device back, and each device's backend, memory, tolerance classes, dtypes and costs; a member built for a backend is one device of it, so each other device of a machine is a member of its own |
the format is mag-by's (Description, the pool file, schemas/mag-pool.schema.json) |
yours, by hand | is to come from the allocation; not built | is to come from that system; not built |
| the costs in an offer: seconds per step of each part's unit on each device | the format is mag-by's (Cost) |
you time one step of each unit on each device yourself, at the batch its memory allows, after warm-up and on an idle device, and write it with a band, how far a later measurement may fall from it; a cost you leave out is taken as the slowest any other device measured for that unit, or 1 s if none did, flagged estimate with a band of 100% |
is to be measured by mag-mar; not built |
is to be measured by mag-mar; not built |
| the placement loop: list the arrangements, remove those that break a constraint, score, commit, record | mag-mortar's Pool, public; a running job moves only on a join, onto the device that joined, when the seconds it would save on its items left are more than the seconds the move stops it (J6), the edges it makes cross between members counted, tried where the prediction cannot tell and going back if it loses; measured costs in the loop beyond a trial, the time of edges otherwise and dividing a chain are not built |
mag plan shows its decision on your two files |
the same library | the same library |
| the queue of jobs and the priority between them | the pool's: mag-mortar's, every job submitted to the pool placed against the others; a job is submitted to a running pool, and ended, at the coordinator's door (mag-mar door), and written to its ledger; its parts run on the members it places them on |
the pool's: you submit and end each job at the door, on the coordinator's machine | the pool's; Slurm queues only the machines' allocations; the door's command is to run as a step in the coordinator's job, not tried | the pool's; that system's agent is to ask at the door |
| which machines a job may use | the host's, given to mag as data: the pool it is handed, a member's trust, the level an input or weights are kept at (keep), the devices and priority ceiling of a job's stamp, a part's pin |
the pool file is your policy: list only the machines you allow, and trust a rented one at outside |
Slurm's accounts and partitions decide the allocation | that system's own authorization decides the pool before mag sees it |
| starting the program on each machine | the host's; the program is mag-mar |
you, by hand or over ssh | sbatch, not tried |
that system's |
| taking a machine back | the host's: by name, it sends the member's program SIGTERM, and the member gives its devices back within its give_back_seconds and the coordinator writes their leave to the ledger; by need, at the coordinator's door (mag-mar door take-back), the pool chooses the device of the kind it loses least by, writes its leave, and its member gives it back; the member stops its parts at their next step, and the pool places their jobs again, each item without a result running again from its first part, since a part keeps no state between items |
you, with kill -TERM or at the door |
Slurm's preemption, with a grace time, not tried; by need, at the door, not tried | that system's |
| coordinating: running the loop over time and keeping its ledger | one of the pool's machines, named by the host; mag-mortar does no I/O and hands its state over (Pool::apply, Pool::ledger, Ledger::line, Pool::replay, Pool::follow); mag-mar's coordinator writes each entry before it acknowledges it, and one started on the ledger of one that stopped takes it up, its members joining again |
the same | the same | the same |
| carrying a placement out on the machines | mag-mar's: each member runs the parts placed on its device, one item at a time, and sends what an edge carries to the member of the next part; the coordinator holds the data handed in at the door, counts each result once and writes the results out at the door. Copies of a part sharing a job's items are built for a part that reads the job's inputs and makes its results; a member other than the coordinator holding data for others is not built |
the same | the same, not tried | the same |
| finding machines, waking a sleeping one, keeping it awake | the host's | yours: they must be on | the cluster's | that system's |
It is designed for:
- many copies of one worker (rollouts, batch inference, labelling), one on every device that can take it;
- a model that no single card holds, divided along a chain across two or three;
- a teacher and a student sharing the pool's memory;
- a long-running service in the pool that yields a card when a more urgent job arrives, and spreads back afterwards; and placing again when the host takes a machine back;
- data that must not leave: data is kept at a level of trust (
outside < site < owner), and what is computed from it is never placed on a machine trusted below that level, unless a part of the graph releases it to a lower one.
Of these, what has run is jobs placed against each other, and placed again when the host takes a machine back (recipes 1c and 1d). The loop's tests hold it to the rest as it plans them, but none has run as a job: a part's copies are placed, and share the items only if the part reads the job's inputs and makes its results, else the first works through them all; dividing a chain is not built. When a job runs, the coordinator, which holds the data handed in at the door, gives it only to a member it named that data's reader, trusted at its level.
Planning, before anything runs. mag-by reads a graph file, refuses one
that is wrong with a reason that names what is wrong, works out the level of trust each part's
data is kept at, and writes the graph as Graphviz DOT:
That is graphs/example.json. Red is data kept at owner and
everything it reaches, here from the frames and from the classifier's weights; orange would be
site; the dashed edge is where a part releases its output, a count of labels, to outside. To
draw your own, with Graphviz installed:
cargo run -p mag-by --features graph --example dot -- your-graph.json | dot -Tsvg > graph.svg
mag-mortar holds the placement loop, run on what each device offers given as
data: on every arrival, end, join or leave it lists the ways to place the jobs waiting, and on a
join the ways to move a running job onto the device that joined, removes those that break memory,
a part's tolerance and dtypes, a pin, a job's need, the devices the job's stamp allows, or the
guard that keeps data off machines trusted below its level, scores the rest from the devices'
measured costs and the jobs' priorities, commits the best, and records every candidate with why
any was left out. A running job moves only when the seconds it would save on its items left are
more than the seconds the move stops it, which the record gives with their bands. Its tests hold
it to the cases it is designed for: a job on the fastest device that holds it, copies wherever they fit, a pinned job waiting for its backend, the
higher priority of two first, a stamped job only on its devices, and no data on a machine trusted
below its level.
To see it decide, plan the example graph on a pool of four devices described in a file,
pools/example.json, one of them a fast rented card:
cargo run -p mag-mortar --features files --example mag -- plan \
crates/mag-by/pools/example.json crates/mag-by/graphs/example.json
label-frames would be placed: of 65 candidates, 58 were removed and 7 scored.
The best scores 2.000, band ±5%.
decode copies on server/0, workstation/0
b0 on server/0, with chain model
b1 on server/0, with chain model
head on workstation/0
count on workstation/0
Kept off a device, and why:
laptop/0's measured bounds do not meet decode's tolerance class
the guard: decode carries data kept at owner, and rented/0's member is trusted only at outside
...
The rented card is the fastest and gets nothing: every part reads the frames kept at owner. head
is pinned to CUDA, and the chain's two blocks stay together. The whole output is
plans/example.txt; --json prints the loop's record.
The command plans and keeps nothing.
A pool keeps its state as a ledger of what it was told, with the record made each time.
mag-mortar writes nothing itself: mag-mar's coordinator appends each entry as a line, synced
before it answers, and a coordinator started again on it replays them, each record checked against
the one logged, and goes on; its members join it again.
Not built yet, as plainly as what is:
- Measuring. A device's costs and tolerance classes are the pool file's, written by hand; no member measures its own, and the loop does not try candidates on a job's own steps. Throughput has not been measured: the parts of the jobs that ran are too small to say anything of a real unit's.
- Your own unit, at run time. A unit of yours is compiled into a program of your own, so a new unit is a new build on each machine that is to run it; handing a running pool a unit's code is not built, nor decided.
- Placing. Dividing a chain between devices; copies sharing the items of a part with an edge from or to another part; moving a running job with its parts' state (a part keeps none between items, so a job placed again runs its items without a result from their first part).
- Data. A member other than the coordinator holding a job's data for others; fetching a blob in pieces, so a weight larger than a member's memory cannot be; a tensor kept on its device from one part to the next (each unit over tensors moves its inputs to the device and its output back at every step).
- Hosts. The recipes for Slurm and Kubernetes; the door taking back a single device by name, which SIGTERM cannot say.
mag-mar's README lists the rest of the program's.
The graph file is at version 2 (version 1 files still read) and will change. If your job cannot be said in it, that is what we most want to hear: please open an issue.
Licensed under the Apache License, Version 2.0.
Pre-alpha and moving fast — issues and design discussion welcome. Please open an issue before large PRs.