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

[data_loader] expand the error message #2221

Merged
merged 2 commits into from
Dec 7, 2023
Merged

Conversation

stas00
Copy link
Contributor

@stas00 stas00 commented Dec 5, 2023

What does this PR do?

When using deepspeed with a DL that doesn't have a .batch_size (e.g. due to using a batch sampler) it fails with:

[...]
[:0]:    ) = self.accelerator.prepare(
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/accelerator.py", line 1209, in prepare
[:0]:    result = self._prepare_deepspeed(*args)
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/accelerator.py", line 1419, in _prepare_deepspeed
[:0]:    result = [
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/accelerator.py", line 1420, in <listcomp>
[:0]:    self._prepare_one(obj, first_pass=True) if isinstance(obj, torch.utils.data.DataLoader) else obj
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/accelerator.py", line 1092, in _prepare_one
[:0]:    return self.prepare_data_loader(obj, device_placement=device_placement)
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/accelerator.py", line 1791, in prepare_data_loader
[:0]:    prepared_data_loader = prepare_data_loader(
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/data_loader.py", line 863, in prepare_data_loader
[:0]:    new_batch_sampler = BatchSamplerShard(
[:0]:  File "/mnt/nvme0/code/huggingface/accelerate-ds-bs-auto/src/accelerate/data_loader.py", line 155, in __init__
[:0]:    raise ValueError("You need to use `even_batches=False` when the batch sampler has no batch size.")
[:0]:ValueError: You need to use `even_batches=False` when the batch sampler has no batch size.

It's impossible to act on the error message's suggestion, since the deepspeed plugin doesn't expose this parameter to the user. But instead it uses accelerator.even_batches.

So I expanded the error message to suggest to do that.

Of course @pacman100 may consider to do the work for the user and if .batch_size isn't available then to set the correct flag automatically.

Who can review?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the error message, LGTM.

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @stas00 for clarifying the error message!

@muellerzr muellerzr merged commit 5296419 into huggingface:main Dec 7, 2023
23 checks passed
@stas00 stas00 deleted the patch-2 branch December 7, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants