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

Use torch.xpu.mem_get_info for XPU #3275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/accelerate/utils/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,19 @@ def get_xpu_available_memory(device_index: int):
from intel_extension_for_pytorch.xpu import mem_get_info

return mem_get_info(device_index)[0]
elif version.parse(torch.__version__).release >= version.parse("2.6").release:
SunMarc marked this conversation as resolved.
Show resolved Hide resolved
# torch.xpu.mem_get_info API is available starting from PyTorch 2.6
# It further requires PyTorch built with the SYCL runtime which supports API
# to query available device memory. If not available, exception will be
# raised. Version of SYCL runtime used to build PyTorch is being reported
# with print(torch.version.xpu) and corresponds to the version of Intel DPC++
# SYCL compiler. First version to support required feature is 20250001.
try:
return torch.xpu.mem_get_info(device_index)[0]
except Exception:
pass

warnings.warn(
"The XPU `mem_get_info` API is available in IPEX version >=2.5. The current returned available memory is incorrect. Please consider upgrading your IPEX version."
"The XPU `mem_get_info` API is available in IPEX version >=2.5 or PyTorch >=2.6. The current returned available memory is incorrect. Please consider upgrading your IPEX or PyTorch version."
)
return torch.xpu.max_memory_allocated(device_index)
Loading