switch to device agnostic device calling for test cases (#38247)
* use device agnostic APIs in test cases Signed-off-by: Matrix Yao <matrix.yao@intel.com> * fix style Signed-off-by: Matrix Yao <matrix.yao@intel.com> * add one more Signed-off-by: YAO Matrix <matrix.yao@intel.com> * xpu now supports integer device id, aligning to CUDA behaviors Signed-off-by: Matrix Yao <matrix.yao@intel.com> * update to use device_properties Signed-off-by: Matrix Yao <matrix.yao@intel.com> * fix style Signed-off-by: Matrix Yao <matrix.yao@intel.com> * update comment Signed-off-by: Matrix Yao <matrix.yao@intel.com> * fix comments Signed-off-by: Matrix Yao <matrix.yao@intel.com> * fix style Signed-off-by: Matrix Yao <matrix.yao@intel.com> --------- Signed-off-by: Matrix Yao <matrix.yao@intel.com> Signed-off-by: YAO Matrix <matrix.yao@intel.com> Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ from transformers.generation.configuration_utils import ALL_CACHE_IMPLEMENTATION
|
||||
from transformers.testing_utils import (
|
||||
CaptureStderr,
|
||||
backend_device_count,
|
||||
backend_torch_accelerator_module,
|
||||
cleanup,
|
||||
get_gpu_count,
|
||||
is_torch_available,
|
||||
@@ -430,11 +431,7 @@ class CacheHardIntegrationTest(unittest.TestCase):
|
||||
original = GenerationConfig(**common)
|
||||
offloaded = GenerationConfig(cache_implementation="offloaded", **common)
|
||||
|
||||
torch_accelerator_module = None
|
||||
if device.type == "cuda":
|
||||
torch_accelerator_module = torch.cuda
|
||||
elif device.type == "xpu":
|
||||
torch_accelerator_module = torch.xpu
|
||||
torch_accelerator_module = backend_torch_accelerator_module(device.type)
|
||||
|
||||
torch_accelerator_module.reset_peak_memory_stats(device)
|
||||
model.generate(generation_config=original, **inputs)
|
||||
|
||||
Reference in New Issue
Block a user