pub struct AdamW4bit { /* private fields */ }Expand description
4-bit AdamW: Adam4bit with decoupled weight decay.
Identical quantized state (NF4 momentum and variance) and identical adaptive step;
the only difference is that λ·w is subtracted from the parameter directly rather
than folded into the gradient, which is what makes AdamW’s decay independent of the
gradient magnitude.
Implementations§
Source§impl AdamW4bit
impl AdamW4bit
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
Creates a 4-bit AdamW 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
Creates a 4-bit AdamW optimizer with a custom quantization configuration.
Sourcepub fn memory_savings(&self) -> f32
pub fn memory_savings(&self) -> f32
Memory saved relative to full-precision AdamW, measured from the live buffers.
Trait Implementations§
Source§impl Optimizer for AdamW4bit
impl Optimizer for AdamW4bit
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 AdamW4bit
impl StatefulOptimizer for AdamW4bit
Source§type Config = <Adam4bit as StatefulOptimizer>::Config
type Config = <Adam4bit as StatefulOptimizer>::Config
The configuration type for 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.
Source§fn load_state(&mut self, path: &Path) -> Result<()>
fn load_state(&mut self, path: &Path) -> Result<()>
Loads the optimizer state written by
Self::save_state. Read moreAuto Trait Implementations§
impl Freeze for AdamW4bit
impl RefUnwindSafe for AdamW4bit
impl Send for AdamW4bit
impl Sync for AdamW4bit
impl Unpin for AdamW4bit
impl UnsafeUnpin for AdamW4bit
impl UnwindSafe for AdamW4bit
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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