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:
Yao Matrix
2025-05-26 16:18:53 +08:00
committed by GitHub
parent cba279f46c
commit a5a0c7b888
39 changed files with 259 additions and 389 deletions

View File

@@ -19,6 +19,7 @@ import unittest
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, FineGrainedFP8Config, OPTForCausalLM
from transformers.testing_utils import (
backend_empty_cache,
get_device_properties,
require_accelerate,
require_read_token,
require_torch_accelerator,
@@ -254,7 +255,7 @@ class FP8LinearTest(unittest.TestCase):
device = torch_device
@unittest.skipIf(
torch.cuda.is_available() and torch.cuda.get_device_capability()[0] < 9,
get_device_properties()[0] == "cuda" and get_device_properties()[1] < 9,
"Skipping FP8LinearTest because it is not supported on GPU with capability < 9.0",
)
def test_linear_preserves_shape(self):
@@ -270,7 +271,7 @@ class FP8LinearTest(unittest.TestCase):
self.assertEqual(x_.shape, x.shape)
@unittest.skipIf(
torch.cuda.is_available() and torch.cuda.get_device_capability()[0] < 9,
get_device_properties()[0] == "cuda" and get_device_properties()[1] < 9,
"Skipping FP8LinearTest because it is not supported on GPU with capability < 9.0",
)
def test_linear_with_diff_feature_size_preserves_shape(self):