-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Add support for ZeRO-2/3 and ZeRO-offload in fairscale #10354
Changes from 2 commits
2ba8601
3fc784b
442e221
1ea56d0
0f20f1d
ab10ada
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ | |||||
is_torch_tpu_available, | ||||||
torch_required, | ||||||
) | ||||||
from .trainer_utils import EvaluationStrategy, LoggingStrategy, SchedulerType | ||||||
from .trainer_utils import EvaluationStrategy, LoggingStrategy, SchedulerType, ShardedDDPType | ||||||
from .utils import logging | ||||||
|
||||||
|
||||||
|
@@ -236,9 +236,24 @@ class TrainingArguments: | |||||
When resuming training, whether or not to skip the epochs and batches to get the data loading at the same | ||||||
stage as in the previous training. If set to :obj:`True`, the training will begin faster (as that skipping | ||||||
step can take a long time) but will not yield the same results as the interrupted training would have. | ||||||
sharded_ddp (:obj:`bool`, `optional`, defaults to :obj:`False`): | ||||||
sharded_ddp (:obj:`bool`, :obj:`str` or :class:`~transformers.trainer_utils.ShardedDDPType`, `optional`, defaults to :obj:`False`): | ||||||
Use Sharded DDP training from `FairScale <https://github.com/facebookresearch/fairscale>`__ (in distributed | ||||||
training only). This is an experimental feature. | ||||||
|
||||||
Can take up to six values: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- :obj:`"no"`: for no sharded DataParallelism (default behavior) | ||||||
- :obj:`"simple"`: to use first instance of sharded DDP released by fairscale (:obj:`ShardedDDP`) similar | ||||||
to ZeRO-2. | ||||||
- :obj:`"zero_2"`: to use the second instance of sharded DPP released by fairscale (:obj:`FullyShardedDDP`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are smashing concepts a bit here. ZeRO is a big territory with many features. the 3 stages belong to ZeRO-DP part of ZeRO, so ideally this should be This is just a suggestion though, if you strongly feel having just the number is clear enough, that's OK too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and that's why they call it DP and not DDP, because it's ZeRO-DP. |
||||||
in Zero-2 mode (with :obj:`reshard_after_forward=False`). | ||||||
- :obj:`"zero_2_offload"`: to use add ZeRO-offload to ZeRO-2. | ||||||
- :obj:`"zero_3"`: to use the second instance of sharded DPP released by fairscale (:obj:`FullyShardedDDP`) | ||||||
in Zero-3 mode (with :obj:`reshard_after_forward=True`). | ||||||
- :obj:`"zero_3_offload"`: to use add ZeRO-offload to ZeRO-3. | ||||||
|
||||||
If a bool is passed, it will be converted to :obj:`"no"` for :obj:`False` and :obj:`"simple"` for | ||||||
:obj:`True`. | ||||||
deepspeed (:obj:`str`, `optional`): | ||||||
Use `Deepspeed <https://github.com/microsoft/deepspeed>`__. This is an experimental feature and its API may | ||||||
evolve in the future. The value is the location of its json config file (usually ``ds_config.json``). | ||||||
|
@@ -443,8 +458,8 @@ class TrainingArguments: | |||||
"help": "When resuming training, whether or not to skip the first epochs and batches to get to the same training data." | ||||||
}, | ||||||
) | ||||||
sharded_ddp: bool = field( | ||||||
default=False, | ||||||
sharded_ddp: ShardedDDPType = field( | ||||||
default="no", | ||||||
metadata={"help": "Whether or not to use sharded DDP training (in distributed training only)."}, | ||||||
) | ||||||
deepspeed: Optional[str] = field( | ||||||
|
@@ -535,6 +550,10 @@ def __post_init__(self): | |||||
"Both warmup_ratio and warmup_steps given, warmup_steps will override any effect of warmup_ratio during training" | ||||||
) | ||||||
|
||||||
if isinstance(self.sharded_ddp, bool): | ||||||
self.sharded_ddp = "simple" if self.sharded_ddp else "no" | ||||||
self.sharded_ddp = ShardedDDPType(self.sharded_ddp) | ||||||
|
||||||
def __repr__(self): | ||||||
# We override the default repr to remove deprecated arguments from the repr. This method should be removed once | ||||||
# those deprecated arguments are removed form TrainingArguments. (TODO: v5) | ||||||
|
@@ -662,7 +681,7 @@ def parallel_mode(self): | |||||
|
||||||
- :obj:`ParallelMode.NOT_PARALLEL`: no parallelism (CPU or one GPU). | ||||||
- :obj:`ParallelMode.NOT_DISTRIBUTED`: several GPUs in one single process (uses :obj:`torch.nn.DataParallel`). | ||||||
- :obj:`ParallelMode.DISTRIBUTED`: several GPUs, each ahving its own process (uses | ||||||
- :obj:`ParallelMode.DISTRIBUTED`: several GPUs, each having its own process (uses | ||||||
:obj:`torch.nn.DistributedDataParallel`). | ||||||
- :obj:`ParallelMode.TPU`: several TPU cores. | ||||||
""" | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may introduce a confusion here, should we stick to DP and not DDP to match the real name? i.e. FullyShardedDP and ShardedDP?
Perhaps change the original flag to reflect that as well?
--sharded_dp
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, made a request to make those names renamed to match DDP here:
facebookresearch/fairscale#413 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Stas. I personally think the distinction between DDP and DP is not going to matter anymore. Even pytorch DDP itself is moving to remove the "device_ids" argument in the future so that there isn't a support for a single process DP (as opposed to distributed/multiprocess DP). Therefore, I think sticking with FSDP is fine within fairscale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your follow up, @min-xu-ai