-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
enable average tokens across devices #34373
Changes from 3 commits
590a522
647203b
8fd583d
190d534
ae9fbe9
4c8d02f
70919a1
8ca8c4d
1eab209
cdbb3d3
bd8ae99
588a80e
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 |
---|---|---|
|
@@ -1530,6 +1530,13 @@ class TrainingArguments: | |
}, | ||
) | ||
|
||
average_tokens_across_devices: Optional[bool] = field( | ||
default=False, | ||
metadata={ | ||
"help": "Whether or not to average tokens across devices." | ||
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. Maybe we could share a bit more why this arg could be useful ? 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. Done, please review my code. |
||
} | ||
) | ||
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. During the This then simplifies it earlier to just be 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. Thanks, already fixed it, please check. |
||
|
||
def __post_init__(self): | ||
# Parse in args that could be `dict` sent in from the CLI as a string | ||
for field in _VALID_DICT_FIELDS: | ||
|
@@ -1763,6 +1770,10 @@ def __post_init__(self): | |
if self.framework == "pt" and is_torch_available(): | ||
self.device | ||
|
||
# Disable average tokens when using single device | ||
if self.world_size == 1: | ||
self.average_tokens_across_devices = False | ||
|
||
if self.torchdynamo is not None: | ||
warnings.warn( | ||
"`torchdynamo` is deprecated and will be removed in version 5 of 🤗 Transformers. Use" | ||
|
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.
We modified a lot how loss is computed, are we sure that this is loss is the same as the one applied ?
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.
Good catch, it should be
loss.detach() / self.args.gradient_accumulation_steps / self.accelerator.num_processes
(dividing by num processes if and only if we did our loss function num tokens logic)