Rust SDK

The modgrad SDK (modular gradient) is a Cargo workspace of Rust crates for building and training Continuous Thought Machines (CTMs): recurrent networks that think over internal ticks instead of stacked layers. It is a library, not a framework. You write the training loop; optimizer state, traces and sync buffers are ordinary structs.

The source is on GitHub. The CTM is a port of Sakana AI’s design; see the CTM. To watch training runs in the app, see log to modgrad from Rust.

What is published

These pages describe the public main branch. Newer work, including the code behind the results, is on our development branch and not published yet. The crates use the Rust 2024 edition.

It does not build from a clean clone yet

main (last updated 2026-07-01) does not build from a clean clone: modgrad-compute depends on a candle checkout outside the repository, the penumbra_arena example has absolute path dependencies, and the isis/benchmarks/fusion-blossom submodule has no URL.

A first brain

The published code composes CTMs into a graph of regions. A preset, a training loop you write, and a NeuralComputer to run it:

use modgrad_ctm::graph::{RegionalConfig, RegionalWeights, RegionalAdamW,
    RegionalGradients, regional_train_token, NeuralComputer};

// obs_dim, out_dims, ticks
let cfg = RegionalConfig::eight_region_small(128, 256, 16);

let mut w   = RegionalWeights::new(cfg);
let mut opt = RegionalAdamW::new(&w).with_lr(3e-4);

let mut grads = RegionalGradients::zeros(&w);
for (token, target) in your_data {
    let (loss, _pred) = regional_train_token(&w, &mut grads, token, target);
    opt.step(&mut w, &mut grads);
    grads.zero();
}

let mut nc = NeuralComputer::new(w);
let reply = nc.chat("hello", 100, 0.8);

regional_train_token runs one token forward and backward and adds to the gradients; opt.step applies them. Other presets: four_region, eight_region, eight_region_medium, eight_region_large, eight_region_billion.

The shortest whole program is examples/minictm. It trains on a text file and saves minictm.bin; with --chat and no --data it loads that file and chats. It needs ROCm to build.

Which packages need ROCm

ROCm is linked at build time, so a package that turns it on needs ROCm installed. CUDA is loaded at run time and builds without CUDA installed.

package GPU backends on by default builds without ROCm
the library crates (modgrad-ctm, modgrad-compute, modgrad-training, …) none (CPU) yes
the root package modgrad (what a bare cargo build builds) CUDA, loaded at run time yes
isis-runtime ROCm only with --no-default-features
isis ROCm, and CUDA (through modgrad) no
minictm, modgrad-debugger, lm_validate, qwen_chat ROCm, through isis-runtime no
multimodal_smoke, cortex_cerebellum_reader, eight_region_v2_brain_smoke, qwen_cerebellum_smoke, and the six blt_* examples ROCm, through modgrad-compute no
the whole workspace (--workspace) all of the above no, not even with --no-default-features

See compute backends.

Known issues in the published code

Two bugs on main are fixed on the development branch:

  • Batched maze training dropped most gradients. The maze trainer’s batch accumulator copied only the major projections, so the synapse U-Net, the second NLM stage, start states, decays and exit gates never trained. Gradients were also summed without averaging, and the clip norm covered only some tensors.
  • Synchronization pairs were self-pairs. For power-of-two widths, every region’s left and right pair lists were the same permutation, so the read-out saw squared activations, not synchronization between neurons. Brains with the learned router also ignored their observation.

Results that depend on these paths, including the README’s 21×21 maze table, predate the fixes.

Where the work has moved

New work uses a single CTM block instead of the region graph: a graph of three blocks did no better than one at matched parameters (results). The single block, its tooling and the per-neuron inspection tool are not published yet.

Next: the Continuous Thought Machine →