nemo_automodel.components.distributed.fsdp2
nemo_automodel.components.distributed.fsdp2
Module Contents
Classes
Functions
API
Deprecated compatibility wrapper for FSDP2 parallelization.
.. deprecated:: 0.7
Pass FSDP2Config through the config-driven infrastructure and
provide model-specific behavior with ModelParallelizer. This
compatibility class is scheduled for removal in 0.8.
This manager applies parallelization to the model using a prescribed TP sharding plan. It supports mixed precision and CPU offloading options.
The device mesh must be created externally and passed in.
Parameters:
Configuration for FSDP2 distributed training.
Device mesh for distributed operations.
Optional device mesh for expert parallelism.
Optional expert-parallel policy included in the model’s
MeshContext.
Apply per-layer compile after sharding, alongside whole-model compile_model().
Parallelizes the given model using FSDP2 and TP sharding strategies.
Parameters:
The model to be parallelized.
Optional callback that re-resolves parameter trainability after model surgery and before FSDP construction.
Returns: nn.Module
The parallelized model.
Eliminate CPU-GPU sync from flash attention for standard (non-packed) training.
transformers._is_packed_sequence() returns a GPU bool scalar when batch_size==1,
which causes Python’s if to call aten::is_nonzero — a CPU-GPU sync — once per
attention layer per forward pass. With FSDP+TP+gradient-checkpointing this fires
hundreds of times per iteration.
For standard (non-packed) training sequences are never packed, so returning the Python False immediately is both correct and avoids the sync. Do NOT apply this patch when using packed-sequence training (multiple sequences concatenated into one tensor with position_ids that reset to 0 mid-sequence).
Report whether ModelParallelizer shards the model for this mesh.
Parallelization is skipped on a single-rank world or a single-element mesh, which
also skips every side effect of fully_shard — most importantly the
MixedPrecisionPolicy cast of parameters to the compute dtype. Callers that
depend on that cast must check this instead of assuming FSDP2 is active.
Parameters:
Device mesh from the model’s parallelization context.
Returns: bool
True when fully_shard is applied, False when parallelization is skipped.