Skip to content

Commit

Permalink
[tests] add accelerate marker (huggingface#21743)
Browse files Browse the repository at this point in the history
* add `accelerate` marker

* add to docs

* Update docs/source/en/testing.mdx
  • Loading branch information
younesbelkada authored Feb 27, 2023
1 parent c51dc4f commit 831f314
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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 to run `accelerate` tests on your models. For that you can just add `-m accelerate_tests` to your command, if let's say you want to run these tests on `OPT` run:
```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 @@ -2463,6 +2464,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 @@ -2498,6 +2500,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 @@ -2533,6 +2536,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 @@ -3172,6 +3176,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 @@ -3185,6 +3190,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 @@ -3224,6 +3230,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 @@ -3241,6 +3248,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

0 comments on commit 831f314

Please sign in to comment.