All examples
Neural networks

Train a CNN with native CPU replicas

Run one canonical global batch through two local CPU workers with synthetic images, frozen batch normalization and retained partial batches.

cnn_parallel.aner
// Native CPU replicas share one global batch and one canonical optimizer update.
import aner.nn
import aner.tensor
import aner.parallel
import aner.dev

let model = nn.cnn(1, 8, 8).conv2d(outputs: 4, padding: 1)
    .batch_norm().relu().head(classes: 2)
    .freeze_batch_norm().on("cpu")
let images = tensor.reshape(nn.random(12, 64, seed: 2026, scale: 1.0), List(12, 1, 8, 8))
let targets = nn.zeros(12, 1)
dev.capture("Parallel CNN architecture", model)
let fitted = model.fit(images, targets, epochs: 3, batch: 5, rate: 0.001,
    execution: parallel.local(workers: 2))
print(fitted.updates()) // 9 updates: every final partial global batch is retained.
print(fitted.accuracy(images, targets)) // API demonstration; these are training inputs.

Make it your experiment.

With Aner 0.0.3 or newer installed, save this program as examples/cnn_parallel.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/cnn_parallel.aner
aner run examples/cnn_parallel.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires Aner 0.0.4 or newer and matching editor integration. Uses synthetic tensors with no external dataset, credentials or network connection. Supported Mac packages include Metal/MPS; current Linux and Windows packages do not include CUDA or MPI/NCCL. Optional source backends require a compatible runtime and hardware.

Credential setup
aner check examples/cnn_parallel.aner
aner examples/cnn_parallel.aner

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner