Browse documentation
aner.nn · Reference

Convolutional neural networks

Build native CNNs and model zoo architectures, choose explicit AMP and collective policies, inspect diagrams and resume training snapshots.

Implemented

Implemented in development. CNN models, AMP and GPU collective APIs require the CNN enabled development runtime and matching editor. The published 0.0.3 downloads predate these APIs. Documentation availability does not announce new binary packages.

aner
import aner.nn

let model = nn.cnn(channels: 3, height: 32, width: 32)
    .conv2d(outputs: 16, padding: 1).relu().max_pool2d()
    .conv2d(outputs: 32, padding: 1).relu().head(classes: 10)
    .on("auto")
let fitted = model.fit(images, labels, epochs: 5, batch: 32)
let prediction = fitted.predict(images)

Images are preprocessed NCHW [samples,channels,height,width] tensors. Targets are zero based IDs [samples,1] or one hot [samples,classes]. Keep preprocessing and label mappings with the experiment. Split before fitting transforms, use validation data for model selection and reserve held out test data for evaluation. The arbitrary Tensor interface does not attach protected Dataset roles automatically. See the complete synthetic example.

Build or select an architecture

Shapes are inferred after the input declaration. Builders return immutable models; training returns a new retained snapshot. head(classes) adds global average pooling when needed and the terminal raw class projection. .summary(), .diagram() and .parameter_count() inspect the architecture without a forward pass. .prepare() initializes a reusable resident inference snapshot.

aner
let resnet = nn.vision("resnet50", classes: 10).on("cuda")

Available native graphs include ResNet-18/34/50/101/152, ResNeXt 50 32×4d, DenseNet 121, EfficientNet B0, ConvNeXt Tiny and InceptionV3. Inspect nn.architectures() for canonical names. Construction downloads no weights. Import compatible local weights explicitly with .load_weights(path) and retain the required preprocessing and class mapping. .head(classes) can replace a terminal classifier; .freeze_backbone() restricts fine tuning to that head. Checkpoint restoration preserves optimizer state; a weight import starts a separate training run.

Operators include grouped/dilated convolution, max/average/global pooling, BatchNorm, ReLU/GELU, flattening, dense projection and training only dropout. .budget(tensor_elements, graph_elements) bounds numeric storage and the differentiation graph. Inputs are complete tensors, not an automatic streaming image loader. .read_images(path, samples) accepts exact size preprocessed little endian raw Float32/Float64 NCHW data; it does not decode JPEG/PNG or infer normalization.

CUDA precision and collectives

aner
import aner.parallel

let tuned = resnet.performance(amp: "fp16", collectives: "auto")
let fitted = tuned.fit(images, labels, execution: parallel.local())

AMP packs eligible GEMM operands into FP16/BF16 while retaining FP32 master weights, gradients, moments and output storage. amp: "fp16" requires supported Tensor Core hardware; BF16 and matmul: "tf32" require Ampere or newer. Strict FP32 is the default. FP16 loss scaling skips a whole optimizer update when gradients overflow. .performance_summary(), .attempts(), .skipped_updates() and .loss_scale() expose retained policy and counters.

Native MPI sessions coordinate ranks and NCCL can sum resident GPU gradient buffers. collectives: "nccl" requires a CUDA/MPI/NCCL build and a configured rank to GPU assignment. "mpi" selects the MPI reduction path; "auto" chooses a supported session path. Use one process per physical GPU, consistent architecture/data/settings across ranks and a global batch large enough for useful shards. Local CPU replica contexts also work. There is no automatic cluster provisioning. See parallel computing.

CUDA supports Float32/Float64; Metal/MPS supports Float32. Unsupported explicit placement fails. Intel and AMD GPU providers remain reserved without a validated backend. Small models and small matrices can run slower on a GPU or under AMP. Time the whole training step with warm up and synchronization; Tensor Core availability alone does not establish end to end speedup or scaling efficiency.

Validation covers numerical agreement, resident gradients, optimizer continuation and overflow handling. Hardware correctness tests do not establish accuracy on a production dataset, peak GPU utilization or linear multi server scaling. Architecture construction is separate from pretrained weight compatibility.

Checkpoints and development

aner
fitted.save("vision.anercnn")
let resumed = nn.load_cnn("vision.anercnn").on("auto")

Save to a new path. Versioned snapshots retain model parameters, BatchNorm state, optimizer moments, training continuation and precision/scaler policy. Preserve preprocessing separately. Use .prepare() and the same .predict() in inference.

aner
import aner.dev

dev.capture("CNN architecture", model)

Run with --dev reports/cnn-first to record bounded diagrams and training progress; use a fresh directory. --prod runs the same kernels, checks, limits and seeds without automatic development recording. See development mode and recurrent networks.

See the Neural networks module reference for the shared API.

Aner documentation · Reference and guides