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

Support skip_first_batches for XLA #2966

Merged
merged 3 commits into from
Aug 8, 2024

Conversation

yitongh
Copy link
Contributor

@yitongh yitongh commented Jul 29, 2024

What does this PR do?

At present, when using the resume_from_checkpoint feature in the Transformers Trainer, it results in an error because skip_first_batches does not support MpDeviceLoaderWrapper of XLA. This PR supports this feature.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@muellerzr

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks! Overall this looks fine, just one suggestion :)

@@ -1083,6 +1088,12 @@ def skip_first_batches(dataloader, num_batches=0):
"""
Creates a `torch.utils.data.DataLoader` that will efficiently skip the first `num_batches`.
"""
is_xla_dataloader = False
if is_torch_xla_available() and isinstance(dataloader, MpDeviceLoaderWrapper):
Copy link
Collaborator

Choose a reason for hiding this comment

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

At this point I believe we can use PartialState().distributed_type == DistributedType.XLA

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I change to AcceleratorState because this class has already been imported and it aligns with the usage of the prepare_data_loader method. I believe that the distributed_type of these two states is shared.

Copy link
Collaborator

Choose a reason for hiding this comment

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

PartialState is safer and better for these types of situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your correction. I have already changed it to PartialState. I'm not very familiar with these states :)

@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
Collaborator

@muellerzr muellerzr 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 enabling!

@yitongh
Copy link
Contributor Author

yitongh commented Aug 7, 2024

hi, @muellerzr , can you merge this pr? The error in tests seems unrelated to this PR.

@muellerzr
Copy link
Collaborator

@yitongh yes indeed!

@muellerzr muellerzr merged commit 79ca85c into huggingface:main Aug 8, 2024
23 of 25 checks passed
@yitongh yitongh deleted the fix_xla_skip_data branch August 9, 2024 01:54
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.

3 participants