|
Mila
Deep Neural Network Library
|
Public Types | |
| using | NetworkType = Network<TDeviceType, TPrecision> |
Public Member Functions | |
| Model (const Model &)=delete | |
| Model (Model &&)=default | |
| DeviceId | getDeviceId () const noexcept |
| The device this model runs on. | |
| MemoryStats | getMemoryStats () const |
| Current memory allocation breakdown for this model. | |
| RuntimeMode | getRuntimeMode () const noexcept |
| The runtime mode this model was constructed for. | |
| std::size_t | getScratchHighWaterBytes () const |
| Context-owned scratch device memory, in bytes, at its high-water mark. | |
| bool | isEval () const noexcept |
| True if this model is currently in eval sub-state. | |
| bool | isInferenceMode () const noexcept |
| True if this model was constructed for inference. | |
| bool | isTrainingMode () const noexcept |
| True if this model was constructed for training. | |
| Model & | operator= (const Model &)=delete |
| Model & | operator= (Model &&)=default |
| void | setEval (bool eval) |
| Toggle eval sub-state for this model. | |
| virtual std::string | toString () const =0 |
| Human-readable summary of this model's configuration. | |
| void | train () |
| Run the training loop for this model. | |
Protected Member Functions | |
| Model (std::unique_ptr< NetworkType > network, RuntimeMode runtime_mode) | |
| Construct with a fully built network and runtime mode. | |
| virtual void | onTraining ()=0 |
| Training loop hook – derived class owns the implementation. | |
Protected Attributes | |
| std::unique_ptr< NetworkType > | network_ |
| The owned Network instance. | |
|
inlineexplicitprotected |
Construct with a fully built network and runtime mode.
Called by derived class constructors only. The network must already be built and have parameters loaded before this constructor is called.
| network | Fully built and loaded Network. |
| runtime_mode | Inference or Training – immutable after construction. |
|
inlinenoexcept |
The runtime mode this model was constructed for.
Immutable after construction. Governs which public API methods are valid.
|
inline |
Context-owned scratch device memory, in bytes, at its high-water mark.
Deliberately NOT folded into getMemoryStats(): that reports what components allocate, and this buffer belongs to the shared execution context, is allocated lazily during forward passes, and is sized by whichever operation needed the most at any point. Callers wanting the true resident total add the two.
Zero before the first forward pass, and on any backend that allocates no scratch.
|
inlinenoexcept |
True if this model is currently in eval sub-state.
For RuntimeMode::Inference models always returns true – inference models never compute gradients. For RuntimeMode::Training models reflects the last setEval() call.
|
inlinenoexcept |
True if this model was constructed for inference.
The model-family inference API (e.g. generate()) is valid. train() will throw.
|
inlinenoexcept |
True if this model was constructed for training.
train() is valid. The model-family inference API will throw.
|
protectedpure virtual |
Training loop hook – derived class owns the implementation.
Called by train() after precondition enforcement. The derived class has total control over data loading, optimizer construction, loss computation, backward pass, checkpointing, and sampling.
Pure virtual – a model declaring RuntimeMode::Training must provide a training loop.
Implemented in Mila::Dnn::GemmaModel< TDeviceType, TPrecision >, Mila::Dnn::GptModel< TDeviceType, TPrecision >, and Mila::Dnn::LlamaModel< TDeviceType, TPrecision >.
|
inline |
Toggle eval sub-state for this model.
When eval is true, the forward pass runs without gradients, dropout is disabled, and batch norm uses running statistics. When eval is false, the full training pass is restored.
Cascades through Network to every Component and Operation in the graph via their onEvalChanging() hooks.
Only valid on models constructed with RuntimeMode::Training. Inference-mode models are always in eval state by definition.
| eval | true to enter eval sub-state, false to restore training. |
| std::runtime_error | if called on a RuntimeMode::Inference model. |
|
pure virtual |
Human-readable summary of this model's configuration.
Implemented in Mila::Dnn::GemmaModel< TDeviceType, TPrecision >, Mila::Dnn::GptModel< TDeviceType, TPrecision >, and Mila::Dnn::LlamaModel< TDeviceType, TPrecision >.
|
inline |
Run the training loop for this model.
Enforces RuntimeMode::Training precondition then delegates entirely to onTraining(). The derived class owns the loop – data loading, optimizer, loss, checkpointing, and sampling are all derived class concerns.
| std::runtime_error | if called on an Inference-mode model. |
|
protected |
The owned Network instance.
Accessible to derived classes for model-specific operations not covered by the base class API.