Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fsdp checkpoint strategy #1734

Merged
merged 13 commits into from
Nov 18, 2022
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
bcui19 marked this conversation as resolved.
Show resolved Hide resolved
if hasattr(module, '_activation_checkpointing'):
return bool(module._activation_checkpointing)
if hasattr(obj, 'activation_checkpointing_fn') and isinstance(obj.activation_checkpointing_fn,
Expand Down