Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] add accelerate marker #21743

Merged
merged 5 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/source/en/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ If you want to include only tests that include both patterns, `and` is to be use
```bash
pytest -k "test and ada" tests/test_optimization.py
```

### Run `accelerate` tests

Sometimes you need yo run `accelerate` on your models you can just add `-m accelerate_tests` to your command, if let's say you want to run these tests on `OPT` run:
younesbelkada marked this conversation as resolved.
Show resolved Hide resolved
```bash
RUN_SLOW=1 pytest -m accelerate_tests tests/models/opt/test_modeling_opt.py
```


### Run documentation tests

In order to test whether the documentation examples are correct, you should check that the `doctests` are passing.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_modeling_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import numpy as np
from huggingface_hub import HfFolder, delete_repo, set_access_token
from huggingface_hub.file_download import http_get
from pytest import mark
from requests.exceptions import HTTPError

import transformers
Expand Down Expand Up @@ -2455,6 +2456,7 @@ def check_device_map_is_respected(self, model, device_map):
self.assertEqual(param.device, torch.device(param_device))

@require_accelerate
@mark.accelerate_tests
@require_torch_gpu
def test_disk_offload(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
Expand Down Expand Up @@ -2490,6 +2492,7 @@ def test_disk_offload(self):
self.assertTrue(torch.allclose(base_output[0], new_output[0]))

@require_accelerate
@mark.accelerate_tests
@require_torch_gpu
def test_cpu_offload(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
Expand Down Expand Up @@ -2525,6 +2528,7 @@ def test_cpu_offload(self):
self.assertTrue(torch.allclose(base_output[0], new_output[0]))

@require_accelerate
@mark.accelerate_tests
@require_torch_multi_gpu
def test_model_parallelism(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
Expand Down Expand Up @@ -3164,6 +3168,7 @@ def test_checkpoint_variant_save_load(self):
self.assertIsNotNone(model)

@require_accelerate
@mark.accelerate_tests
def test_from_pretrained_low_cpu_mem_usage_functional(self):
# test that we can use `from_pretrained(..., low_cpu_mem_usage=True)` with normal and
# sharded models
Expand All @@ -3177,6 +3182,7 @@ def test_from_pretrained_low_cpu_mem_usage_functional(self):

@require_usr_bin_time
@require_accelerate
@mark.accelerate_tests
def test_from_pretrained_low_cpu_mem_usage_measured(self):
# test that `from_pretrained(..., low_cpu_mem_usage=True)` uses less cpu memory than default

Expand Down Expand Up @@ -3216,6 +3222,7 @@ def test_from_pretrained_low_cpu_mem_usage_measured(self):
# cuda memory tracking and then we should be able to do a much more precise test.

@require_accelerate
@mark.accelerate_tests
@require_torch_multi_gpu
@slow
def test_model_parallelism_gpt2(self):
Expand All @@ -3233,6 +3240,7 @@ def test_model_parallelism_gpt2(self):
self.assertEqual(text_output, "Hello, my name is John. I'm a writer, and I'm a writer. I'm")

@require_accelerate
@mark.accelerate_tests
@require_torch_gpu
def test_from_pretrained_disk_offload_task_model(self):
model = AutoModel.from_pretrained("hf-internal-testing/tiny-random-gpt2")
Expand Down