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

Remove out-dated xpu device check code in get_balanced_memory #2826

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Jun 5, 2024

What does this PR do?

This PR removes the outdated and unnecessary code of xpu device check in the following code snippet

if (
                    d != "cpu"
                    and (torch.device(d).type == "xpu" or torch.xpu.get_device_properties(d).dev_type == "gpu")
                )

The reasons are

  • If torch.xpu.get_device_properties(d) works, torch.device(d).type will always be "xpu"
  • If torch.device(d).type == "xpu", d will definitively not be "cpu"

torch.device(d).type == "xpu" is enough to check xpu device just like the case in MLU and NPU.

Who can review?

@SunMarc and @muellerzr

@faaany
Copy link
Contributor Author

faaany commented Jun 5, 2024

@abhilash1910

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! Love the simplification 😍

Could we actually take this a bit further now that the logic is aligned?

Perhaps getting the device type expected under the is_xxx_available() and then only calling the

num_devices = len([d for d in max_memory if torch.device(d).type == expected_device_type and max_memory[d] > 0])

section once? WDYT

@abhilash1910
Copy link
Contributor

Yes @muellerzr looks like a good abstraction, We are internally validating the "gpu" predicate of the validation logic .
If it is no longer required then new design LGTM.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM !

@faaany
Copy link
Contributor Author

faaany commented Jun 5, 2024

@muellerzr PR updated with expected_device_type, pls review, thx!

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

@abhilash1910 abhilash1910 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Beautiful 😍

Nice work!

@muellerzr muellerzr merged commit 30cb7ec into huggingface:main Jun 5, 2024
23 checks passed
@faaany faaany deleted the xpu-device branch November 4, 2024 06:09
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