xpu: support xpu backend from stock pytorch (>=2.4) (#31238)
* xpu: support xpu backend from stock pytorch (>=2.4) Fixes: https://github.com/huggingface/transformers/issues/31237 XPU backend is available in the stock PyTorch starting from version 2.4, see [1]. This commit extends huggingface transformers to support XPU from both IPEX and the stock pytorch. IPEX is being tried first. See: https://github.com/pytorch/pytorch/issues/114842 Requires: https://github.com/huggingface/accelerate/pull/2825 Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com> * xpu: enable gpt2 and decision_transformer tests for xpu pytorch backend Note that running xpu tests requires TRANSFORMERS_TEST_DEVICE_SPEC=spec.py passed to the test runner: import torch DEVICE_NAME = 'xpu' MANUAL_SEED_FN = torch.xpu.manual_seed EMPTY_CACHE_FN = torch.xpu.empty_cache DEVICE_COUNT_FN = torch.xpu.device_count Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com> --------- Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
This commit is contained in:
@@ -813,23 +813,24 @@ def require_torch_multi_npu(test_case):
|
||||
|
||||
def require_torch_xpu(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires XPU and IPEX.
|
||||
Decorator marking a test that requires XPU (in PyTorch).
|
||||
|
||||
These tests are skipped when Intel Extension for PyTorch isn't installed or it does not match current PyTorch
|
||||
version.
|
||||
These tests are skipped when XPU backend is not available. XPU backend might be available either via stock
|
||||
PyTorch (>=2.4) or via Intel Extension for PyTorch. In the latter case, if IPEX is installed, its version
|
||||
must match match current PyTorch version.
|
||||
"""
|
||||
return unittest.skipUnless(is_torch_xpu_available(), "test requires IPEX and an XPU device")(test_case)
|
||||
return unittest.skipUnless(is_torch_xpu_available(), "test requires XPU device")(test_case)
|
||||
|
||||
|
||||
def require_torch_multi_xpu(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires a multi-XPU setup with IPEX and at least one XPU device. These tests are
|
||||
skipped on a machine without IPEX or multiple XPUs.
|
||||
Decorator marking a test that requires a multi-XPU setup (in PyTorch). These tests are skipped on a machine without
|
||||
multiple XPUs.
|
||||
|
||||
To run *only* the multi_xpu tests, assuming all test names contain multi_xpu: $ pytest -sv ./tests -k "multi_xpu"
|
||||
"""
|
||||
if not is_torch_xpu_available():
|
||||
return unittest.skip("test requires IPEX and at least one XPU device")(test_case)
|
||||
return unittest.skip("test requires PyTorch XPU")(test_case)
|
||||
|
||||
return unittest.skipUnless(torch.xpu.device_count() > 1, "test requires multiple XPUs")(test_case)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user