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

Set correct NPU backend and distributed_type when using transfer_to_npu #3021

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

ArthurinRUC
Copy link
Contributor

@ArthurinRUC ArthurinRUC commented Aug 16, 2024

What does this PR do?

When running from torch_npu.contrib import transfer_to_npu, we will find torch.cuda.is_available() is True which leads to incorrect backend and distributed_type. This PR fixes the problem to make sure npu envs check is before CUDA.

Fixes #3020

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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@muellerzr

@BenjaminBossan
Copy link
Member

Let's add a comment that NPU has to be checked before CUDA and why (a reference to the issue). Also, any idea if the same can also happen with other devices, i.e. CUDA should always be the last check?

@ArthurinRUC
Copy link
Contributor Author

Let's add a comment that NPU has to be checked before CUDA and why (a reference to the issue). Also, any idea if the same can also happen with other devices, i.e. CUDA should always be the last check?

Sure, I will add a brief description to my fix. Also I've already open an issue here #3020 :)

@BenjaminBossan
Copy link
Member

Sure, I will add a brief description to my fix. Also I've already open an issue here #3020 :)

Thanks. Yeah, I meant that the comment can reference said issue.

Comment on lines +727 to +729
elif is_npu_available():
backend = "hccl"
distributed_type = DistributedType.MULTI_NPU
Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed with @BenjaminBossan, let's add a comment here and during torch.device("npu") that clarifies (in the code) that these must be done before the cuda check

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

@ArthurinRUC
Copy link
Contributor Author

All right I got it! Thanks :)

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.

Great! Thanks for fixing this!

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!

@muellerzr muellerzr merged commit 5536a3a into huggingface:main Aug 19, 2024
25 checks passed
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.

NPU backend and distributed_type was incorrect when using transfer_to_npu
4 participants