Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Model.ixx File Reference
module Dnn.Model

Abstract base class for all Mila models. More...

#include <cstddef>
#include <memory>
#include <string>
#include <stdexcept>
#include <format>
import Compute.DeviceType;
import Dnn.TensorDataTypeTraits;
import Dnn.TensorDataType;
import Compute.DeviceId;
import Dnn.TensorTypes;
import Dnn.RuntimeMode;
import Dnn.Component;
import Dnn.Network;

Classes

class  Mila::Dnn::Model< TDeviceType, TPrecision >

Namespaces

namespace  Mila
 Mila main API namespace.

Detailed Description

Abstract base class for all Mila models.

Model defines the universal contract across all model families – language models, image classifiers, regression models, and any future model type.

Architecture

Model sits at the top of the Mila DNN pipeline:

Component – leaf node, shape-driven buffer allocation CompositeComponent – structural aggregation, cascades BuildConfig Network – graph topology, forward/backward Model – RuntimeMode, lifecycle, universal API boundary LanguageModel – generate(), sampling, EOS, vocabulary GptModel – GPT-specific factory and config LlamaModel – LLaMA-specific factory and config ImageClassifier– classify(), top-k predictions

RuntimeMode

A Model is constructed for either Inference or Training – immutable after construction. The mode governs which public API methods are valid:

Mode Valid
Inference model-family inference API
Training train() -> onTraining() hook

Training

train() enforces the RuntimeMode::Training precondition then delegates entirely to the pure virtual onTraining() hook. The derived class owns the training loop – data loading, optimizer, loss, backward pass, checkpointing, and sampling are all derived class concerns.

Threading

Not thread-safe. External synchronization required if shared.