-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
handle batch size correchtly when using split and dispatch batches #3076
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -272,6 +272,20 @@ def _get_dataloader( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_workers=self.args.dataloader_num_workers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rank=self.args.process_index, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.args.accelerator_config is not None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and self.args.accelerator_config.split_batches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and self.args.accelerator_config.dispatch_batches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.args.sample_packing and self.args.pretraining: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not self.args.eval_sample_packing and not is_training: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataloader_params["batch_size"] *= self.accelerator.num_processes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataloader_params["batch_size"] = self.accelerator.num_processes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif not self.args.sample_packing and self.args.pretraining: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataloader_params["batch_size"] *= self.accelerator.num_processes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+276
to
+288
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. Critical: Reintroducing This block can set or mutate Guard against the presence of if (
self.args.accelerator_config is not None
and self.args.accelerator_config.split_batches
and self.args.accelerator_config.dispatch_batches
):
- if self.args.sample_packing and self.args.pretraining:
- if not self.args.eval_sample_packing and not is_training:
- dataloader_params["batch_size"] *= self.accelerator.num_processes
- else:
- dataloader_params["batch_size"] = self.accelerator.num_processes
- elif not self.args.sample_packing and self.args.pretraining:
- dataloader_params["batch_size"] *= self.accelerator.num_processes
+ # Avoid conflicting with BatchSampler: DataLoader forbids both batch_size and batch_sampler.
+ if "batch_sampler" not in dataloader_params:
+ if self.args.sample_packing and self.args.pretraining:
+ if not self.args.eval_sample_packing and not is_training:
+ dataloader_params["batch_size"] *= self.accelerator.num_processes
+ else:
+ dataloader_params["batch_size"] = self.accelerator.num_processes
+ elif not self.args.sample_packing and self.args.pretraining:
+ dataloader_params["batch_size"] *= self.accelerator.num_processesFollow-up: If you actually need different behavior for the multipack case under split/dispatch, the adjustment must be applied inside the 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.args.sample_packing and ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (is_training and not self.args.pretraining) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| or (not is_training and self.args.eval_sample_packing is not False) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Should this only be scaling by the total dp size?
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.
accelerator handles the actual dp sharding, so I don't think so? I'll test.