|
Mila
Deep Neural Network Library
|
Device-agnostic AdamW optimizer. More...
Public Types | |
| using | ExecutionContextType = ExecutionContext<TDeviceType> |
| using | OptimizerType = typename Detail::AdamWImplFor<TDeviceType, TPrecision>::type |
Public Member Functions | |
| AdamWOptimizer (IExecutionContext *exec_context, const AdamWConfig &config) | |
| Construct AdamW optimizer from fluent AdamWConfig. | |
| void | addParameter (ITensor *param, ITensor *grad) override |
| Register a parameter tensor for optimization. | |
| float | getBeta1 () const noexcept |
| float | getBeta2 () const noexcept |
| float | getEpsilon () const noexcept |
| float | getLearningRate () const override |
| Get the current learning rate. | |
| size_t | getParameterCount () const noexcept |
| size_t | getStepCount () const noexcept |
| float | getWeightDecay () const noexcept |
| void | setLearningRate (float learning_rate) override |
| Set the learning rate for future updates. | |
| void | setWeightDecay (float weight_decay) |
| void | step () override |
| Perform one optimization step. | |
Device-agnostic AdamW optimizer.
Dispatches to the appropriate device-specific implementation (CPU or CUDA) based on the TDeviceType template parameter. Uses AdamWConfig for fluent configuration of hyperparameters.
| TDeviceType | Device type (DeviceType::Cpu or DeviceType::Cuda) |
| TPrecision | Tensor precision (TensorDataType::FP32, FP16, BF16) |
|
inlineexplicit |
Construct AdamW optimizer from fluent AdamWConfig.
| exec_context | Execution context for device resources |
| config | Fluent AdamWConfig describing hyperparameters |
| std::invalid_argument | if exec_context is null |
| std::invalid_argument | if config.validate() fails |
|
inlineoverridevirtual |
Register a parameter tensor for optimization.
Adds a parameter-gradient pair to the optimizer's update list. The optimizer will allocate internal state tensors (momentum, variance, etc.) matching the parameter shape and device placement.
| param | Shared pointer to parameter tensor to be optimized |
| grad | Shared pointer to gradient tensor (must match param shape) |
| std::invalid_argument | if param or grad is nullptr |
| std::invalid_argument | if param and grad shapes don't match |
| std::invalid_argument | if param and grad are on different devices |
| std::runtime_error | if state allocation fails |
Example:
Implements Mila::Dnn::Optimizer< TDeviceType, TPrecision >.
|
inlineoverridevirtual |
Get the current learning rate.
Returns the base learning rate used for parameter updates. Some optimizers may apply adaptive per-parameter learning rates internally (Adam, AdamW), but this method returns the global scaling factor.
Implements Mila::Dnn::Optimizer< TDeviceType, TPrecision >.
|
inlineoverridevirtual |
Set the learning rate for future updates.
Updates the base learning rate used by the optimizer. Typically used for learning rate schedules (decay, warmup, cyclic, etc.).
| learning_rate | New learning rate (must be positive) |
| std::invalid_argument | if learning_rate <= 0 |
Example with learning rate decay:
Implements Mila::Dnn::Optimizer< TDeviceType, TPrecision >.
|
inlineoverridevirtual |
Perform one optimization step.
Updates all registered parameters using their accumulated gradients according to the optimizer's update rule (SGD, Adam, AdamW, etc.). This is the HOT PATH method called every training iteration.
For algorithms with state (Adam, AdamW):
| std::runtime_error | if no parameters have been registered |
| std::runtime_error | if gradient data is invalid or null |
Typical sequence:
Implements Mila::Dnn::Optimizer< TDeviceType, TPrecision >.