AdamConfig

Struct AdamConfig 

Source
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: f32

Learning rate for parameter updates (default: 1e-3)

§beta1: f32

Exponential decay rate for first moment estimates (default: 0.9)

§beta2: f32

Exponential decay rate for second moment estimates (default: 0.999)

§eps: f32

Small constant for numerical stability (default: 1e-8)

§weight_decay: f32

Weight decay coefficient for L2 regularization (default: 0.0)

§amsgrad: bool

Whether to use AMSGrad variant (default: false)

Trait Implementations§

Source§

impl Clone for AdamConfig

Source§

fn clone(&self) -> AdamConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AdamConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AdamConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FromFieldValue for AdamConfig

Source§

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

Source§

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>

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<()>

Saves the struct to a JSON file Read more
Source§

fn save_binary<P: AsRef<Path>>(&self, path: P) -> SerializationResult<()>

Saves the struct to a binary file Read more
Source§

fn load_json<P: AsRef<Path>>(path: P) -> SerializationResult<Self>

Loads the struct from a JSON file Read more
Source§

fn load_binary<P: AsRef<Path>>(path: P) -> SerializationResult<Self>

Loads the struct from a binary file Read more
Source§

fn to_json(&self) -> SerializationResult<String>

Converts the struct to a JSON string Read more
Source§

fn to_binary(&self) -> SerializationResult<Vec<u8>>

Converts the struct to binary data Read more
Source§

fn from_json(json: &str) -> SerializationResult<Self>

Creates the struct from a JSON string Read more
Source§

fn from_binary(data: &[u8]) -> SerializationResult<Self>

Creates the struct from binary data Read more
Source§

impl ToFieldValue for AdamConfig

Source§

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.