pub struct CPUOffloadedOptimizer<T: Optimizer> { /* private fields */ }Expand description
A wrapper that enables CPU offloading for any optimizer.
Implementations§
Source§impl<T: Optimizer + StatefulOptimizer> CPUOffloadedOptimizer<T>
impl<T: Optimizer + StatefulOptimizer> CPUOffloadedOptimizer<T>
Sourcepub fn new(base_optimizer: T, config: CPUOffloadConfig) -> Self
pub fn new(base_optimizer: T, config: CPUOffloadConfig) -> Self
Creates a new CPU-offloaded optimizer wrapper.
Sourcepub fn with_default_config(base_optimizer: T) -> Self
pub fn with_default_config(base_optimizer: T) -> Self
Creates a CPU-offloaded optimizer with default configuration.
Sourcepub fn get_memory_stats(&self) -> &CPUOffloadStats
pub fn get_memory_stats(&self) -> &CPUOffloadStats
Get the current memory statistics.
Sourcepub fn get_memory_savings_bytes(&self) -> usize
pub fn get_memory_savings_bytes(&self) -> usize
Get the total memory savings (GPU memory freed).
Sourcepub fn get_memory_savings_percent(&self) -> f32
pub fn get_memory_savings_percent(&self) -> f32
Get the memory savings as a percentage of total optimizer memory.
Sourcepub fn prefetch_states(&mut self, keys: &[String], device: &str) -> Result<()>
pub fn prefetch_states(&mut self, keys: &[String], device: &str) -> Result<()>
Prefetch tensors that will be needed soon.
Sourcepub fn evict_unused_states(&mut self, keep_keys: &[String]) -> Result<()>
pub fn evict_unused_states(&mut self, keep_keys: &[String]) -> Result<()>
Clean up GPU cache of states that won’t be needed soon.
Sourcepub fn get_config(&self) -> &CPUOffloadConfig
pub fn get_config(&self) -> &CPUOffloadConfig
Get the configuration.
Sourcepub fn set_config(&mut self, config: CPUOffloadConfig)
pub fn set_config(&mut self, config: CPUOffloadConfig)
Update the configuration.
Trait Implementations§
Source§impl<T: Optimizer> Optimizer for CPUOffloadedOptimizer<T>
impl<T: Optimizer> Optimizer for CPUOffloadedOptimizer<T>
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
Auto Trait Implementations§
impl<T> Freeze for CPUOffloadedOptimizer<T>where
T: Freeze,
impl<T> RefUnwindSafe for CPUOffloadedOptimizer<T>where
T: RefUnwindSafe,
impl<T> Send for CPUOffloadedOptimizer<T>
impl<T> Sync for CPUOffloadedOptimizer<T>
impl<T> Unpin for CPUOffloadedOptimizer<T>where
T: Unpin,
impl<T> UnwindSafe for CPUOffloadedOptimizer<T>where
T: UnwindSafe,
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