Skip to content

Commit

Permalink
First update for FSDP pytorch librispeech deepspeech
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtweedle committed Dec 5, 2024
1 parent 11676d6 commit dbfd233
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from typing import Optional
import functools

import torch
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
from torch.distributed.fsdp.wrap import (
size_based_auto_wrap_policy,
enable_wrap,
wrap,
)

from algorithmic_efficiency import param_utils
from algorithmic_efficiency import spec
Expand Down Expand Up @@ -58,7 +65,15 @@ def init_model_fn(
self.requires_sync_before_eval = False
if N_GPUS > 1:
if USE_PYTORCH_DDP:
model = DDP(model, device_ids=[RANK], output_device=RANK)
auto_wrap_policy = functools.partial(
size_based_auto_wrap_policy, min_num_params=2 ** 10
)
model = FSDP(
model,
use_orig_params=True,
auto_wrap_policy=auto_wrap_policy,
device_id=RANK
)
else:
model = torch.nn.DataParallel(model)
return model, None
Expand Down

0 comments on commit dbfd233

Please sign in to comment.