pub struct AdamConfig {
pub learning_rate: f32,
pub beta1: f32,
pub beta2: f32,
pub eps: f32,
pub weight_decay: f32,
pub amsgrad: bool,
}Expand description
Configuration for the Adam optimization algorithm
Contains all hyperparameters that control the behavior of Adam optimization. Default values follow PyTorch conventions for maximum compatibility and optimal convergence across a wide range of neural network architectures.
§Fields
learning_rate- Step size for parameter updates (default: 1e-3)beta1- Exponential decay rate for first moment estimates (default: 0.9)beta2- Exponential decay rate for second moment estimates (default: 0.999)eps- Small constant for numerical stability (default: 1e-8)weight_decay- L2 regularization coefficient (default: 0.0)amsgrad- Whether to use AMSGrad variant for improved stability (default: false)
Fields§
§learning_rate: f32Learning rate for parameter updates (default: 1e-3)
beta1: f32Exponential decay rate for first moment estimates (default: 0.9)
beta2: f32Exponential decay rate for second moment estimates (default: 0.999)
eps: f32Small constant for numerical stability (default: 1e-8)
weight_decay: f32Weight decay coefficient for L2 regularization (default: 0.0)
amsgrad: boolWhether to use AMSGrad variant (default: false)
Trait Implementations§
Source§impl Clone for AdamConfig
impl Clone for AdamConfig
Source§fn clone(&self) -> AdamConfig
fn clone(&self) -> AdamConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AdamConfig
impl Debug for AdamConfig
Source§impl Default for AdamConfig
impl Default for AdamConfig
Source§impl FromFieldValue for AdamConfig
impl FromFieldValue for AdamConfig
Source§fn from_field_value(
value: FieldValue,
field_name: &str,
) -> SerializationResult<Self>
fn from_field_value( value: FieldValue, field_name: &str, ) -> SerializationResult<Self>
Create AdamConfig from FieldValue with comprehensive validation
This method reconstructs an AdamConfig instance from a FieldValue::Object, performing type validation and field extraction. It’s designed to handle AdamConfig instances that were embedded as fields within larger serializable structures, ensuring proper error handling and detailed error messages.
§Arguments
value- FieldValue containing configuration data (must be Object variant)field_name- Name of the field being deserialized for error context
§Returns
Reconstructed AdamConfig instance on success, or SerializationError on failure
§Expected FieldValue Structure
The FieldValue must be an Object variant containing:
- “learning_rate”: Numeric field value
- “beta1”: Numeric field value
- “beta2”: Numeric field value
- “eps”: Numeric field value
- “weight_decay”: Numeric field value
- “amsgrad”: Boolean field value
§Errors
Returns SerializationError if:
- FieldValue is not an Object variant
- Any required field is missing from the object
- Any field has incorrect type or invalid value
- Deserialization process fails for any reason
§Performance
- Time Complexity: O(1) - Constant time field extraction and validation
- Memory Usage: Temporary deserializer allocation for field processing
- Error Handling: Detailed error messages with field name context
Source§impl StructSerializable for AdamConfig
impl StructSerializable for AdamConfig
Source§fn to_serializer(&self) -> StructSerializer
fn to_serializer(&self) -> StructSerializer
Convert AdamConfig to StructSerializer for comprehensive serialization
This method serializes all Adam hyperparameters into a structured format suitable for both JSON and binary serialization. Every field is essential for proper optimizer reconstruction and training continuation. The serialization preserves exact floating-point values and boolean flags to ensure identical behavior after deserialization.
§Returns
StructSerializer containing all configuration data with field names and values
§Serialized Fields
- learning_rate: Base learning rate for parameter updates
- beta1: Exponential decay rate for first moment estimates
- beta2: Exponential decay rate for second moment estimates
- eps: Small constant for numerical stability in denominator
- weight_decay: L2 regularization coefficient
- amsgrad: Boolean flag for AMSGrad variant usage
§Performance
- Time Complexity: O(1) - Constant time field serialization
- Memory Usage: Minimal allocation for field storage
- Precision: Full floating-point precision preservation
Source§fn from_deserializer(
deserializer: &mut StructDeserializer,
) -> SerializationResult<Self>
fn from_deserializer( deserializer: &mut StructDeserializer, ) -> SerializationResult<Self>
Create AdamConfig from StructDeserializer with full validation
This method reconstructs an AdamConfig instance from serialized hyperparameters, performing comprehensive validation to ensure all required fields are present and contain valid values. The deserialization process maintains exact floating-point precision and validates that all hyperparameters are within reasonable ranges.
§Arguments
deserializer- StructDeserializer containing configuration field data
§Returns
Reconstructed AdamConfig instance on success, or SerializationError on failure
§Required Fields
All fields must be present in the deserializer:
- learning_rate: Must be a valid f32 value
- beta1: Must be a valid f32 value (typically 0.0-1.0)
- beta2: Must be a valid f32 value (typically 0.0-1.0)
- eps: Must be a valid f32 value (typically small positive)
- weight_decay: Must be a valid f32 value (typically 0.0 or small positive)
- amsgrad: Must be a valid boolean value
§Errors
Returns SerializationError if:
- Any required field is missing from the deserializer
- Any field contains invalid data type
- Field extraction fails for any reason
§Performance
- Time Complexity: O(1) - Constant time field extraction
- Memory Usage: Minimal allocation for configuration structure
- Validation: Comprehensive field presence and type validation
Source§fn save_json<P: AsRef<Path>>(&self, path: P) -> SerializationResult<()>
fn save_json<P: AsRef<Path>>(&self, path: P) -> SerializationResult<()>
Source§fn save_binary<P: AsRef<Path>>(&self, path: P) -> SerializationResult<()>
fn save_binary<P: AsRef<Path>>(&self, path: P) -> SerializationResult<()>
Source§fn load_json<P: AsRef<Path>>(path: P) -> SerializationResult<Self>
fn load_json<P: AsRef<Path>>(path: P) -> SerializationResult<Self>
Source§fn load_binary<P: AsRef<Path>>(path: P) -> SerializationResult<Self>
fn load_binary<P: AsRef<Path>>(path: P) -> SerializationResult<Self>
Source§fn to_json(&self) -> SerializationResult<String>
fn to_json(&self) -> SerializationResult<String>
Source§fn to_binary(&self) -> SerializationResult<Vec<u8>>
fn to_binary(&self) -> SerializationResult<Vec<u8>>
Source§fn from_json(json: &str) -> SerializationResult<Self>
fn from_json(json: &str) -> SerializationResult<Self>
Source§fn from_binary(data: &[u8]) -> SerializationResult<Self>
fn from_binary(data: &[u8]) -> SerializationResult<Self>
Source§impl ToFieldValue for AdamConfig
impl ToFieldValue for AdamConfig
Source§fn to_field_value(&self) -> FieldValue
fn to_field_value(&self) -> FieldValue
Convert AdamConfig to FieldValue for embedding in larger structures
This method converts the AdamConfig into a FieldValue::Object that can be embedded as a field within larger serializable structures. This enables AdamConfig to be serialized as part of more complex training configurations or model checkpoints while maintaining its structured representation.
§Returns
FieldValue::Object containing all configuration data as key-value pairs
§Object Structure
The returned object contains these fields:
- “learning_rate”: f32 value as FieldValue::F32
- “beta1”: f32 value as FieldValue::F32
- “beta2”: f32 value as FieldValue::F32
- “eps”: f32 value as FieldValue::F32
- “weight_decay”: f32 value as FieldValue::F32
- “amsgrad”: bool value as FieldValue::Bool
§Performance
- Time Complexity: O(1) - Constant time field conversion
- Memory Usage: Allocates HashMap for field storage
- Conversion: Direct field-to-FieldValue conversion without copying