pub struct MemoryEfficientTraining;Expand description
Memory-efficient training utilities.
Implementations§
Source§impl MemoryEfficientTraining
impl MemoryEfficientTraining
Sourcepub fn optimal_batch_size(
available_memory: usize,
sample_size: usize,
model_memory: usize,
overhead_factor: f64,
) -> usize
pub fn optimal_batch_size( available_memory: usize, sample_size: usize, model_memory: usize, overhead_factor: f64, ) -> usize
Calculate optimal batch size for available memory.
§Arguments
available_memory- Available memory in bytessample_size- Size of a single sample in bytesmodel_memory- Model memory footprint in bytesoverhead_factor- Overhead multiplier (typically 2-4 for gradients)
Sourcepub fn estimate_model_memory(
num_parameters: usize,
with_gradients: bool,
with_optimizer_state: bool,
) -> usize
pub fn estimate_model_memory( num_parameters: usize, with_gradients: bool, with_optimizer_state: bool, ) -> usize
Estimate memory for a model with given parameter count.
§Arguments
num_parameters- Number of model parameterswith_gradients- Whether to include gradient storagewith_optimizer_state- Whether to include optimizer state (e.g., Adam moments)
Sourcepub fn gradient_accumulation_steps(
target_batch_size: usize,
actual_batch_size: usize,
) -> usize
pub fn gradient_accumulation_steps( target_batch_size: usize, actual_batch_size: usize, ) -> usize
Calculate gradient accumulation steps for target batch size.
§Arguments
target_batch_size- Desired effective batch sizeactual_batch_size- Batch size that fits in memory
Sourcepub fn recommended_settings(gpu_memory_gb: f64) -> MemorySettings
pub fn recommended_settings(gpu_memory_gb: f64) -> MemorySettings
Get recommended memory settings for a given GPU memory.
Auto Trait Implementations§
impl Freeze for MemoryEfficientTraining
impl RefUnwindSafe for MemoryEfficientTraining
impl Send for MemoryEfficientTraining
impl Sync for MemoryEfficientTraining
impl Unpin for MemoryEfficientTraining
impl UnwindSafe for MemoryEfficientTraining
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> 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