pub struct FsdpState { /* private fields */ }Expand description
FSDP state tracking for one training step.
Implementations§
Source§impl FsdpState
impl FsdpState
Sourcepub fn new(config: FsdpConfig) -> Self
pub fn new(config: FsdpConfig) -> Self
Create a new FSDP state with the given configuration.
Sourcepub fn wrap_unit(
&mut self,
param_names: Vec<String>,
param_values: HashMap<String, Vec<f64>>,
) -> Result<usize, FsdpError>
pub fn wrap_unit( &mut self, param_names: Vec<String>, param_values: HashMap<String, Vec<f64>>, ) -> Result<usize, FsdpError>
Register a group of parameters as one FSDP unit.
Returns the unit_id of the newly created unit.
Sourcepub fn allgather_unit(&mut self, unit_id: usize) -> Result<Vec<f64>, FsdpError>
pub fn allgather_unit(&mut self, unit_id: usize) -> Result<Vec<f64>, FsdpError>
AllGather parameters for a unit (before forward pass).
Simulates reconstruction by tiling the shard world_size times,
then truncating to total_params length.
Sourcepub fn discard_unit_params(&mut self, unit_id: usize) -> Result<(), FsdpError>
pub fn discard_unit_params(&mut self, unit_id: usize) -> Result<(), FsdpError>
Discard gathered parameters for a unit (after forward pass, to save memory).
Sourcepub fn reduce_scatter_grads(
&mut self,
unit_id: usize,
grads: Vec<f64>,
) -> Result<Vec<f64>, FsdpError>
pub fn reduce_scatter_grads( &mut self, unit_id: usize, grads: Vec<f64>, ) -> Result<Vec<f64>, FsdpError>
ReduceScatter gradients for a unit (after backward pass).
Simulates by averaging grads / world_size and returning the local shard.
Sourcepub fn memory_saving_ratio(&self) -> f64
pub fn memory_saving_ratio(&self) -> f64
Total memory saved vs DDP (replicated params) as a ratio.
Returns world_size since each rank holds 1/world_size of total params.
Sourcepub fn per_rank_memory_bytes(&self) -> usize
pub fn per_rank_memory_bytes(&self) -> usize
Per-rank memory footprint in bytes across all units.
Sourcepub fn unit_count(&self) -> usize
pub fn unit_count(&self) -> usize
Number of FSDP units registered.
Sourcepub fn total_params(&self) -> usize
pub fn total_params(&self) -> usize
Total parameter count across all units.
Auto Trait Implementations§
impl Freeze for FsdpState
impl RefUnwindSafe for FsdpState
impl Send for FsdpState
impl Sync for FsdpState
impl Unpin for FsdpState
impl UnsafeUnpin for FsdpState
impl UnwindSafe for FsdpState
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
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>
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>
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