Tutorial

Fashion-MNIST classification

The current implicit-autograd classifier over the complete Fashion-MNIST training and held-out test splits.

oa::MatrixImplicit autogradCheckpoint manager
ContractValue
Dataset60,000 train and 10,000 held-out test images
Model784 → Linear(128, ReLU) → Linear(10)
Training5 epochs, batch 64, AdamW lr=0.001
Pass criteriaLoss decreases; test accuracy >70%; checkpoint accuracy within 0.5 points

Model

1class MnistClassifier : public oa::Module {
2public:
3 MnistClassifier() {
4 fc1_ = oa::makeShared<oa::Linear>(784, 128);
5 fc1_->setActivation(oa::Activation::Relu);
6 fc2_ = oa::makeShared<oa::Linear>(128, 10);
7 registerModule("fc1", fc1_);
8 registerModule("fc2", fc2_);
9 }
10
11 oa::Matrix forward(const oa::Matrix& input) override {
12 auto normalized = oa::FnMatrix::scale(input, 1.0F / 255.0F);
13 return fc2_->forward(fc1_->forward(normalized));
14 }
15};
16

Training

The batch ring is sized from MaxAsyncSubmissions(), allowing GPU work to overlap CPU sampling while preserving matrix lifetimes.

1while (not training.loop.isDone()) {
2 oa::Matrix batchX;
3 oa::Matrix batchY;
4 if (not trainLoader.nextBatch(batchX, batchY)) {
5 trainLoader.reset();
6 trainLoader.nextBatch(batchX, batchY);
7 }
8
9 optimizer->zeroGrad();
10 oa::GradientTape tape;
11 auto logits = model->forward(batchX);
12 auto loss = oa::FnLoss::crossEntropy(logits, batchY);
13 tape.backward(loss);
14 training.loop.next(loss);
15}
16training.loop.finish();
17
01

Real held-out evaluation

Accuracy is computed over all 10,000 test images, not the final training minibatch.
02

Capability-aware precision

Weight initialization follows the active OA weight dtype; execution remains selected by device capability.
03

Measured training loop

oa::ItTraining owns progress, wall/GPU timing, optimizer completion, and summary metrics.
04

Artifact verification

oa::CheckpointManager saves model and AdamW state, reloads the best checkpoint, and re-runs evaluation.

Build and run

cmake --build build/release --target TutorialMnistClassifierAg -j
OA_MNIST_DATA=/path/to/FashionMNIST/raw ./bin/release/sdk/tutorials/ml/tuMnistClassifierAg

C++ source Python source