-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add generic support for Intel Gaudi accelerator (hpu device) #11328
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 5 commits
2c6a028
fd2e7bf
ae3c497
baf75db
04f2f55
15725c4
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -336,6 +336,22 @@ def is_timm_available(): | |||||||||||||||
return _timm_available | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def is_hpu_available(): | ||||||||||||||||
if ( | ||||||||||||||||
importlib.util.find_spec("habana_frameworks") is None | ||||||||||||||||
or importlib.util.find_spec("habana_frameworks.torch") is None | ||||||||||||||||
): | ||||||||||||||||
return False | ||||||||||||||||
|
||||||||||||||||
os.environ["PT_HPU_GPU_MIGRATION"] = "1" | ||||||||||||||||
logger.debug("Environment variable set: PT_HPU_GPU_MIGRATION=1") | ||||||||||||||||
|
||||||||||||||||
import habana_frameworks.torch # noqa: F401 | ||||||||||||||||
import torch | ||||||||||||||||
|
||||||||||||||||
return hasattr(torch, "hpu") and torch.hpu.is_available() | ||||||||||||||||
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.
Suggested change
ohh, the check should just return True or False, indicate if hpu is available or not 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. @yiyixuxu Yes this does return True or False. We need to set migration to True for HPU before |
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
# docstyle-ignore | ||||||||||||||||
FLAX_IMPORT_ERROR = """ | ||||||||||||||||
{0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the | ||||||||||||||||
|
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.
Shouldn't we keep the
device_type
check that was here earlier? e.g. If HPU is available on the machine, and we setpipe.to(torch.float16)
this path would still run and set the device silently right?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.
@DN6 with the new
is_hpu_available()
we dont need explicit device check. Device will silently be set tohpu
withinis_hpu_available()
when all checks for HPU env passThere 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.
ohh this would not be expected by our users and not aligned with our design philosophy: they would need to explicitly set
device_type
if they want to use the non-default oneThere 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.
If
habana_frameworks
is hooked into torch, then HPU would be the default deviceThere 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.
@dsocek So if I understand correctly, if an HPU is available and the pipeline needs to be run on CPU it wont unless it's explicitly moved?
Assuming the following snippet runs on an HPU machine
e.g
To run on CPU you would have to explicitly set
pipe.to(cpu)
?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.
@DN6 @yiyixuxu
Apologies for the earlier confusion - my previous comment was incorrect. 🙇
I was referring to the if statement in the
to()
function of this PR where I originally usedif device == "hpu"
, and after refactoring now useis_hpu_available()
. We don't explicitly have "hpu" check anymore in the if statement.This new check will not change any user expected behavior:
Current PR's behavior is as follows:
pipe.to()
not called: then device used will be (default) CPUpipe.to("cpu")
: then device used will be CPUpipe.to("hpu")
: then device used will be HPUHere we 1st check is if "habana_frameworks" or "habana_frameworks.torch" are in the environment.
If they are, then we set hpu_migration RT var to true, and import habana_frameworks.torch.
We must define this run-time var before importing
habana_frameworks.torch
.All of this will still keep device on CPU unless user explicitly set it to HPU
Finally we also do hard checks hasattr(torch, "hpu") and torch.hpu.is_available()
Let me know if further adjustments are needed :)