Inference
Running trained models for prediction is straightforward in AodhML. The same model code works for both training and inference.
Prototype Status: Inference mode (no gradient tracking) is planned for v0.3.0.
Basic Inference
fn predict(model: Model, input: Tensor<f32>) -> Tensor<f32> {
// In inference mode, gradients are not computed
with no_grad {
let output = model.forward(input)
return softmax(output)
}
}
Batch Inference
fn predict_batch(model: Model, inputs: [Tensor<f32>]) -> [Tensor<f32>] {
let batch = stack(inputs)
with no_grad {
let outputs = model.forward(batch)
return unstack(softmax(outputs))
}
}
Model Serialization
// Save model weights
model.save("model.aodh")
// Load model weights
let loaded = MLP::new()
loaded.load("model.aodh")
// Save full checkpoint (weights + optimizer state)
checkpoint.save("checkpoint.aodh", model, optimizer, epoch)
Quantization
Planned for v0.5.0:
// Quantize model to int8 for faster inference
let quantized = model.quantize(QuantConfig {
dtype: i8,
scheme: "per_channel",
})
// Run quantized inference
let result = quantized.forward(input)