Skip to content

Commit

Permalink
Fix fsdp checkpoint strategy (#1734)
Browse files Browse the repository at this point in the history
* Adding in performance registration

* clearing optimizer param groups before FSDP wrapping

* fixing comments

* Adding a conditional to ignore checkpointing FSDP and FlattenedWrappers

* removing print comments

* Adding in print for my own sanity

* removing extraneous print statement

* removing duplicate code due to a merge

Co-authored-by: Brandon Cui <bcui@Brandons-MBP.hsd1.ca.comcast.net>
  • Loading branch information
bcui19 and Brandon Cui authored Nov 18, 2022
1 parent 7c2125c commit a571bf9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer/trainer/dist_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def prepare_fsdp_module(model: torch.nn.Module, optimizers: Optional[Union[torch
raise RuntimeError('To use FSDP with Composer, you must use torch>=1.12.0.')
from torch.distributed.fsdp import (BackwardPrefetch, CPUOffload, FullyShardedDataParallel, MixedPrecision,
ShardingStrategy)
from torch.distributed.fsdp.flatten_params_wrapper import FlattenParamsWrapper

if optimizers:
optimizers_tuple = ensure_tuple(optimizers)
Expand Down Expand Up @@ -261,6 +262,8 @@ def _auto_wrap_policy(module: torch.nn.Module, recurse: bool, unwrapped_params:
# If module has attribute `module._activation_checkpointing = ...`, always respect it
# Otherwise checkpoint if root object `obj.activation_checkpointing_fn(module)` is true
def _check_fn(module: torch.nn.Module) -> bool:
if isinstance(module, (FullyShardedDataParallel, FlattenParamsWrapper)):
return False
if hasattr(module, '_activation_checkpointing'):
return bool(module._activation_checkpointing)
if hasattr(obj, 'activation_checkpointing_fn') and isinstance(obj.activation_checkpointing_fn,
Expand Down

0 comments on commit a571bf9

Please sign in to comment.