pub struct ZeROOptimizer<T: Optimizer> { /* private fields */ }Expand description
Main ZeRO optimizer that wraps an underlying optimizer
Implementations§
Source§impl<T: Optimizer> ZeROOptimizer<T>
impl<T: Optimizer> ZeROOptimizer<T>
Sourcepub fn new(
base_optimizer: T,
config: ZeROConfig,
mp_context: Arc<ModelParallelContext>,
) -> Result<Self>
pub fn new( base_optimizer: T, config: ZeROConfig, mp_context: Arc<ModelParallelContext>, ) -> Result<Self>
Create a new ZeRO optimizer
Sourcepub fn register_parameters(
&mut self,
parameters: HashMap<String, Tensor>,
) -> Result<()>
pub fn register_parameters( &mut self, parameters: HashMap<String, Tensor>, ) -> Result<()>
Register parameters with ZeRO optimizer
Sourcepub fn update_gradients(
&mut self,
gradients: HashMap<String, Tensor>,
) -> Result<()>
pub fn update_gradients( &mut self, gradients: HashMap<String, Tensor>, ) -> Result<()>
Update gradients for ZeRO optimization
Sourcepub fn gather_parameters(
&mut self,
parameter_names: &[String],
) -> Result<HashMap<String, Tensor>>
pub fn gather_parameters( &mut self, parameter_names: &[String], ) -> Result<HashMap<String, Tensor>>
Gather parameters for forward pass (Stage 3 only)
Sourcepub fn release_parameters(&mut self, parameter_names: &[String]) -> Result<()>
pub fn release_parameters(&mut self, parameter_names: &[String]) -> Result<()>
Release gathered parameters to save memory (Stage 3 only)
Sourcepub fn get_memory_stats(&self) -> &ZeROMemoryStats
pub fn get_memory_stats(&self) -> &ZeROMemoryStats
Get memory statistics
Sourcepub fn check_memory_usage(&self) -> bool
pub fn check_memory_usage(&self) -> bool
Check if memory usage exceeds threshold
Sourcepub fn base_optimizer(&self) -> &T
pub fn base_optimizer(&self) -> &T
Get the underlying base optimizer
Sourcepub fn base_optimizer_mut(&mut self) -> &mut T
pub fn base_optimizer_mut(&mut self) -> &mut T
Get mutable reference to base optimizer
Sourcepub fn mp_context(&self) -> &Arc<ModelParallelContext>
pub fn mp_context(&self) -> &Arc<ModelParallelContext>
Get model parallel context
Sourcepub fn optimizer_step(&mut self) -> Result<()>
pub fn optimizer_step(&mut self) -> Result<()>
Perform optimizer step with ZeRO optimizations
Trait Implementations§
Source§impl<T: Optimizer> Optimizer for ZeROOptimizer<T>
impl<T: Optimizer> Optimizer for ZeROOptimizer<T>
Auto Trait Implementations§
impl<T> Freeze for ZeROOptimizer<T>where
T: Freeze,
impl<T> !RefUnwindSafe for ZeROOptimizer<T>
impl<T> Send for ZeROOptimizer<T>
impl<T> Sync for ZeROOptimizer<T>
impl<T> Unpin for ZeROOptimizer<T>where
T: Unpin,
impl<T> !UnwindSafe for ZeROOptimizer<T>
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