add ascend npu accelerator support (#24879)
* Add Ascend NPU accelerator support * fix style warining
This commit is contained in:
@@ -91,6 +91,7 @@ from .utils import (
|
||||
is_torch_bf16_cpu_available,
|
||||
is_torch_bf16_gpu_available,
|
||||
is_torch_neuroncore_available,
|
||||
is_torch_npu_available,
|
||||
is_torch_tensorrt_fx_available,
|
||||
is_torch_tf32_available,
|
||||
is_torch_tpu_available,
|
||||
@@ -587,6 +588,26 @@ def require_torch_neuroncore(test_case):
|
||||
)
|
||||
|
||||
|
||||
def require_torch_npu(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires NPU (in PyTorch).
|
||||
"""
|
||||
return unittest.skipUnless(is_torch_npu_available(), "test requires PyTorch NPU")(test_case)
|
||||
|
||||
|
||||
def require_torch_multi_npu(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires a multi-NPU setup (in PyTorch). These tests are skipped on a machine without
|
||||
multiple NPUs.
|
||||
|
||||
To run *only* the multi_npu tests, assuming all test names contain multi_npu: $ pytest -sv ./tests -k "multi_npu"
|
||||
"""
|
||||
if not is_torch_npu_available():
|
||||
return unittest.skip("test requires PyTorch NPU")(test_case)
|
||||
|
||||
return unittest.skipUnless(torch.npu.device_count() > 1, "test requires multiple NPUs")(test_case)
|
||||
|
||||
|
||||
if is_torch_available():
|
||||
# Set env var CUDA_VISIBLE_DEVICES="" to force cpu-mode
|
||||
import torch
|
||||
|
||||
Reference in New Issue
Block a user