Skip to content

Commit

Permalink
fix hpu device count and skip tests requiring hpu:x
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil committed Feb 6, 2025
1 parent 00cc283 commit 97081da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/accelerate/test_utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_backend():
elif is_xpu_available():
return "xpu", torch.xpu.device_count(), torch.xpu.memory_allocated
elif is_hpu_available():
return "hpu", torch.xpu.device_count(), torch.xpu.memory_allocated
return "hpu", torch.hpu.device_count(), torch.hpu.memory_allocated
else:
return "cpu", 1, lambda: 0

Expand Down
8 changes: 8 additions & 0 deletions tests/test_big_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
require_multi_device,
require_multi_gpu,
require_non_cpu,
require_non_hpu,
require_non_torch_xla,
slow,
torch_device,
Expand Down Expand Up @@ -612,6 +613,7 @@ def forward(self, x):
assert (free_memory_bytes_after_infer - free_memory_bytes_after_dispatch) * 1e-6 < 130

@require_multi_device
@require_non_hpu
def test_dispatch_model_multi_devices(self):
model = BiggerModelForTest()
device_map = {"linear1": "cpu", "linear2": "disk", "batchnorm": "cpu", "linear3": 0, "linear4": 1}
Expand Down Expand Up @@ -653,6 +655,7 @@ def test_dispatch_model_move_offloaded_model(self):
model.to(0)

@require_multi_device
@require_non_hpu
def test_dispatch_model_move_model_warning(self):
model = ModelForTest()
device_map = {"linear1": 0, "batchnorm": 0, "linear2": 1}
Expand All @@ -668,6 +671,7 @@ def test_dispatch_model_move_model_warning(self):

@slow
@require_multi_device
@require_non_hpu
def test_dispatch_model_gpt2_on_two_devices(self):
tokenizer = AutoTokenizer.from_pretrained("gpt2")
inputs = tokenizer("Hello world! My name is", return_tensors="pt").to(torch_device)
Expand Down Expand Up @@ -724,6 +728,7 @@ def test_dispatch_model_with_unused_submodules(self):
torch.testing.assert_close(expected, output.cpu(), atol=ATOL, rtol=RTOL)

@require_multi_device
@require_non_hpu
def test_dispatch_model_with_unused_submodules_multi_device(self):
model = ModelWithUnusedSubModulesForTest()
device_map = {"linear1": "cpu", "linear2": "disk", "batchnorm": "cpu", "linear3": 0, "linear4": 1}
Expand Down Expand Up @@ -773,6 +778,7 @@ def test_load_checkpoint_and_dispatch(self):
torch.testing.assert_close(expected, output.cpu(), atol=ATOL, rtol=RTOL)

@require_multi_device
@require_non_hpu
def test_load_checkpoint_and_dispatch_multi_device(self):
model = BiggerModelForTest()
device_map = {"linear1": "cpu", "linear2": "cpu", "batchnorm": 0, "linear3": 0, "linear4": 1}
Expand Down Expand Up @@ -823,6 +829,7 @@ def test_load_checkpoint_and_dispatch_with_unused_submodules(self):
torch.testing.assert_close(expected, output.cpu(), atol=ATOL, rtol=RTOL)

@require_multi_device
@require_non_hpu
def test_load_checkpoint_and_dispatch_multi_device_with_unused_submodules(self):
model = ModelWithUnusedSubModulesForTest()
device_map = {"linear1": "cpu", "linear2": "cpu", "batchnorm": 0, "linear3": 0, "linear4": 1}
Expand Down Expand Up @@ -882,6 +889,7 @@ def test_cpu_offload_with_hook(self):
@slow
@require_bnb
@require_multi_device
@require_non_hpu
def test_dispatch_model_bnb(self):
"""Tests that `dispatch_model` quantizes int8 layers"""
from huggingface_hub import hf_hub_download
Expand Down

0 comments on commit 97081da

Please sign in to comment.