pub struct Adam4bit { /* private fields */ }Expand description
4-bit Adam optimizer with advanced quantization
Implementations§
Source§impl Adam4bit
impl Adam4bit
Sourcepub fn new(
learning_rate: f32,
beta1: f32,
beta2: f32,
epsilon: f32,
weight_decay: f32,
) -> Self
pub fn new( learning_rate: f32, beta1: f32, beta2: f32, epsilon: f32, weight_decay: f32, ) -> Self
Create a new 4-bit Adam optimizer
Sourcepub fn with_quantization_config(
optimizer_config: Adam4bitOptimizerConfig,
quantization_config: AdvancedQuantizationConfig,
) -> Self
pub fn with_quantization_config( optimizer_config: Adam4bitOptimizerConfig, quantization_config: AdvancedQuantizationConfig, ) -> Self
Create with custom quantization config
Sourcepub fn memory_savings(&self) -> f32
pub fn memory_savings(&self) -> f32
Get memory savings compared to full precision Adam
Trait Implementations§
Source§impl Optimizer for Adam4bit
impl Optimizer for Adam4bit
Source§fn update(&mut self, parameter: &mut Tensor, grad: &Tensor) -> Result<()>
fn update(&mut self, parameter: &mut Tensor, grad: &Tensor) -> Result<()>
Updates a parameter based on its gradient. Read more
Source§fn accumulate_grad(
&mut self,
parameter: &mut Tensor,
grad: &Tensor,
) -> Result<(), TrustformersError>
fn accumulate_grad( &mut self, parameter: &mut Tensor, grad: &Tensor, ) -> Result<(), TrustformersError>
Accumulates gradients for gradient accumulation. Read more
Source§fn apply_accumulated_grads(
&mut self,
accumulation_steps: usize,
) -> Result<(), TrustformersError>
fn apply_accumulated_grads( &mut self, accumulation_steps: usize, ) -> Result<(), TrustformersError>
Applies accumulated gradients after gradient accumulation. Read more
Source§impl StatefulOptimizer for Adam4bit
impl StatefulOptimizer for Adam4bit
Source§type Config = Adam4bitOptimizerConfig
type Config = Adam4bitOptimizerConfig
The configuration type for this optimizer.
Source§type State = OptimizerState
type State = OptimizerState
The state type used by this optimizer.
Source§fn state_mut(&mut self) -> &mut Self::State
fn state_mut(&mut self) -> &mut Self::State
Gets a mutable reference to the optimizer’s internal state.
Source§fn state_dict(&self) -> Result<HashMap<String, Tensor>>
fn state_dict(&self) -> Result<HashMap<String, Tensor>>
Saves the optimizer state to a dictionary for checkpointing.
Source§fn load_state_dict(&mut self, state: HashMap<String, Tensor>) -> Result<()>
fn load_state_dict(&mut self, state: HashMap<String, Tensor>) -> Result<()>
Loads optimizer state from a dictionary during checkpoint restoration.
Source§fn memory_usage(&self) -> StateMemoryStats
fn memory_usage(&self) -> StateMemoryStats
Gets memory usage statistics for this optimizer.
Source§fn reset_state(&mut self)
fn reset_state(&mut self)
Resets the optimizer state (useful for training restarts).
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Returns the number of parameters being optimized.
Auto Trait Implementations§
impl Freeze for Adam4bit
impl RefUnwindSafe for Adam4bit
impl Send for Adam4bit
impl Sync for Adam4bit
impl Unpin for Adam4bit
impl UnwindSafe for Adam4bit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more