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

refactor transforms v2 tests #7562

Merged
merged 53 commits into from
Jun 21, 2023
Merged

refactor transforms v2 tests #7562

merged 53 commits into from
Jun 21, 2023

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented May 8, 2023

While very comprehensive, the transforms v2 (functional) tests are also fairly complicated. Thus, it is hard to ramp up new contributors of the team or OSS contributors. @NicolasHug and I discussed offline and we agreed that we need to tackle this.

The question that remains is: is the complexity that we currently have actually needed or can we live with the easier test setup for transforms v1. Skimming through the v1 tests, we identified quite a few holes in what we have now. Thus, it seems that our current process of enforcing comprehensive tests through code review is not sufficient.

Still, we wondered if we can find a middle ground here. And this PR is a PoC for that.

Basically we want one test class per "operation", where operation here means the actual transform, the corresponding dispatcher, and all kernels. Each test should call one helper that comprehensively performs a number of checks.

cc @vfdev-5

@pytorch-bot
Copy link

pytorch-bot bot commented May 8, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7562

Note: Links to docs will display an error until the docs builds have been completed.

❌ 33 New Failures

As of commit db6b137:

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks for working on this Philip. Made some minor comments but the overall logic / layout looks good to me so far

test/test_transforms_v2_refactored.py Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Show resolved Hide resolved
@pmeier pmeier requested a review from vfdev-5 May 31, 2023 10:08
@pmeier pmeier requested a review from NicolasHug June 19, 2023 12:47
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
Comment on lines 209 to 212
check_scripted_smoke=True,
check_dispatch_simple_tensor=True,
check_dispatch_pil=True,
check_dispatch_datapoint=True,
Copy link
Member

Choose a reason for hiding this comment

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

Do we already know which of the transforms are going to set one of these to False?
I'm not sure about the rest but it sounds at least that check_dispatch_simple_tensor and check_dispatch_datapoint should always be True?

In many places we have parameters that we thought could be useful eventually, but ended up never being used and clutter the API. It' best to be conservative and only expose what we need when we need it (unless we're 100% sure we'll need it very very soon)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we already know which of the transforms are going to set one of these to False?

Yes, there are a few. You can see them by looking at the configs in transforms_v2_dispatcher_infos.py that use the following skip marker.

skip_dispatch_datapoint = TestMark(
("TestDispatchers", "test_dispatch_datapoint"),
pytest.mark.skip(reason="Dispatcher doesn't support arbitrary datapoint dispatch."),
)

I'm not sure about the rest but it sounds at least that check_dispatch_simple_tensor and check_dispatch_datapoint should always be True?

Indeed, the statement above only applies to datapoints. To the best of my knowledge we don't have a dispatcher for that we can't automatically check simple tensor and PIL dispatch.

test/test_transforms_v2_refactored.py Show resolved Hide resolved
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks Philip, made another round but it looks good. We're close

test/test_transforms_v2_refactored.py Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks a lot Philip. I made a few more comments below but they're not super critical. LGTM.

test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved
test/test_transforms_v2_refactored.py Outdated Show resolved Hide resolved

def _make_input(self, input_type, *, dtype=None, device="cpu", **kwargs):
if input_type in {torch.Tensor, PIL.Image.Image, datapoints.Image}:
input = make_image(size=self.INPUT_SIZE, dtype=dtype or torch.uint8, device=device, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Just pointing back to #7562 (comment) to make sure it wasn't missed. But we can leave it out for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It wasn't missed, but we can deal with it along the way. Assuming that contributors are ok with just using these functions for now, I would postpone this in favor of velocity.

@pmeier pmeier marked this pull request as ready for review June 21, 2023 10:29
@pmeier
Copy link
Collaborator Author

pmeier commented Jun 21, 2023

New "benchmark" for this PR at ff4c0ea

❯ pytest -q --co test/test_transforms_v2_refactored.py | tail -n1
707 tests collected in 0.30s
❯ pytest -q --durations=10 test/test_transforms_v2_refactored.py | tail -n12
============================= slowest 10 durations =============================
0.60s call     test/test_transforms_v2_refactored.py::TestResize::test_kernel_image_tensor[cuda-dtype0-True-True-InterpolationMode.NEAREST-17]
0.10s call     test/test_transforms_v2_refactored.py::TestResize::test_kernel_image_tensor[cpu-dtype0-True-True-InterpolationMode.NEAREST-size1]
0.04s call     test/test_transforms_v2_refactored.py::TestResize::test_dispatcher[input_type_and_kernel2-size2]
0.04s call     test/test_transforms_v2_refactored.py::TestResize::test_kernel_image_tensor[cpu-dtype0-True-True-InterpolationMode.NEAREST-size2]
0.03s call     test/test_transforms_v2_refactored.py::TestResize::test_transform[Tensor-cpu-size1]
0.02s call     test/test_transforms_v2_refactored.py::TestResize::test_transform[Tensor-cpu-17]
0.01s setup    test/test_transforms_v2_refactored.py::TestResize::test_kernel_image_tensor[cpu-dtype0-True-True-InterpolationMode.NEAREST-17]
0.01s call     test/test_transforms_v2_refactored.py::TestResize::test_dispatcher[input_type_and_kernel2-size1]
0.01s call     test/test_transforms_v2_refactored.py::TestResize::test_kernel_mask[dtype_and_make_mask1]
0.01s call     test/test_transforms_v2_refactored.py::TestResize::test_kernel_video
707 passed in 3.05s

@pmeier
Copy link
Collaborator Author

pmeier commented Jun 21, 2023

After d5358b9 we can compare the time impact of this PR.

PR

❯ pytest --co test/test_transforms_v2_functional.py test/test_transforms_v2.py -k resize | tail -n1
=========== 9045/111637 tests collected (102592 deselected) in 6.74s ===========
❯ pytest test/test_transforms_v2_functional.py test/test_transforms_v2.py -k resize | tail -n1
= 7318 passed, 1725 skipped, 102592 deselected, 2 xfailed, 5257 warnings in 23.88s =

main

❯ pytest --co test/test_transforms_v2_functional.py test/test_transforms_v2.py -k resize | tail -n1
========== 14630/117222 tests collected (102592 deselected) in 7.14s ===========
❯ pytest test/test_transforms_v2_functional.py test/test_transforms_v2.py -k resize | tail -n1
= 11818 passed, 2690 skipped, 102592 deselected, 122 xfailed, 6410 warnings in 31.97s =

Meaning we are shaving off a solid 8 seconds from the old v2 tests while only gaining 3 seconds.

@pmeier pmeier merged commit 5178a2e into pytorch:main Jun 21, 2023
@pmeier pmeier deleted the refactor-v2-tests branch June 21, 2023 14:36
@pmeier pmeier changed the title [PoC] refactor transforms v2 tests refactor transforms v2 tests Jun 21, 2023
@github-actions
Copy link

Hey @pmeier!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

@NicolasHug NicolasHug mentioned this pull request Jul 3, 2023
facebook-github-bot pushed a commit that referenced this pull request Jul 3, 2023
Reviewed By: vmoens

Differential Revision: D47186580

fbshipit-source-id: b5703d86d716c6eb804076ebb969fa23e20287b4

Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants