pub struct MemoryOptimizer { /* private fields */ }Expand description
Memory optimization manager
Implementations§
Source§impl MemoryOptimizer
impl MemoryOptimizer
pub fn new(config: MemoryOptimizationConfig) -> Self
Sourcepub fn create_checkpoint(
&mut self,
layer_index: usize,
activations: Vec<Tensor>,
) -> Result<()>
pub fn create_checkpoint( &mut self, layer_index: usize, activations: Vec<Tensor>, ) -> Result<()>
Create a checkpoint for gradient checkpointing
Sourcepub fn get_checkpoint_activations(
&self,
layer_index: usize,
) -> Option<Vec<Tensor>>
pub fn get_checkpoint_activations( &self, layer_index: usize, ) -> Option<Vec<Tensor>>
Retrieve activations from checkpoint
Sourcepub fn offload_to_cpu(&mut self, name: String, tensor: Tensor) -> Result<()>
pub fn offload_to_cpu(&mut self, name: String, tensor: Tensor) -> Result<()>
Offload tensor to CPU to free GPU memory
Sourcepub fn retrieve_from_cpu(&mut self, name: &str) -> Option<Tensor>
pub fn retrieve_from_cpu(&mut self, name: &str) -> Option<Tensor>
Retrieve tensor from CPU offloading
Sourcepub fn update_memory_usage(&self, delta: isize)
pub fn update_memory_usage(&self, delta: isize)
Update memory usage tracking
Sourcepub fn get_memory_usage(&self) -> usize
pub fn get_memory_usage(&self) -> usize
Get current memory usage
Sourcepub fn should_cleanup(&self) -> bool
pub fn should_cleanup(&self) -> bool
Check if memory cleanup is needed
Sourcepub fn store_for_rematerialization(
&mut self,
key: String,
tensors: Vec<Tensor>,
) -> Result<()>
pub fn store_for_rematerialization( &mut self, key: String, tensors: Vec<Tensor>, ) -> Result<()>
Store tensor for rematerialization
Sourcepub fn retrieve_for_rematerialization(
&mut self,
key: &str,
) -> Option<Vec<Tensor>>
pub fn retrieve_for_rematerialization( &mut self, key: &str, ) -> Option<Vec<Tensor>>
Retrieve tensor for rematerialization
Sourcepub fn get_stats(&self) -> MemoryOptimizationStats
pub fn get_stats(&self) -> MemoryOptimizationStats
Get memory optimization statistics
Auto Trait Implementations§
impl Freeze for MemoryOptimizer
impl RefUnwindSafe for MemoryOptimizer
impl Send for MemoryOptimizer
impl Sync for MemoryOptimizer
impl Unpin for MemoryOptimizer
impl UnsafeUnpin for MemoryOptimizer
impl UnwindSafe for MemoryOptimizer
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