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

Add non_device_test pytest mark to filter out non-device tests #29213

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

fxmarty
Copy link
Contributor

@fxmarty fxmarty commented Feb 22, 2024

As per title.

Many tests in transformers do not use torch_device, .to(0), .to("cuda"), etc. and are always run on CPU. These tests are irrelevant for people who would like to run Transformers tests on their device.

With this proposed PR, one can now run pytest tests/ -m "not not_device_test" --collect-only to filter out non-device tests. We use pytest_collection_modifyitems in order to both capture the tests defined in test_modeling_common.py and in subclasses as well (no need to @pytest.mark.not_gpu_test everywhere) which does not add a significant overhead after tests collection.

We prefer a mark non_device_test rather than device_test, as people adding new tests may forget to add the device tests in the list. It is safer to be greedy (in a reasonable extent).

This now gives

================================================= 34914/54481 tests collected (19567 deselected) in 10.58s ==================================================

instead of the previous 54481 tests selected.

This is requested by AMD.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@fxmarty
Copy link
Contributor Author

fxmarty commented Feb 22, 2024

Actually now getting =========== 27353/54481 tests collected (27128 deselected) in 9.77s ============ skipping all the pipelinemixin tests that are run always on CPU.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this makes sense!
Do you think having a regex based marker would help? --regex ".*test_[a-bA-B]+$"

@fxmarty fxmarty merged commit 2a7746c into huggingface:main Feb 26, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants