-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Enable v1 vs. v2 consistency in refactored tests #7882
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ace839
implement consistency check in refactored tests
pmeier bdef271
remove superseded consistency tests
pmeier bdb5bce
Merge branch 'main' into v2-consistency
pmeier 941cba7
cleanup
pmeier 8bb2cbd
fix signature
pmeier 67511a6
remove scripted v1 vs v2 check
pmeier 70f086e
remove multi input
pmeier 5cf0c4a
properly freeze RNG
pmeier ae59246
cleanup
pmeier 0c6d01c
Merge branch 'main' into v2-consistency
pmeier 79b1f49
more cleanup
pmeier ab4d41e
Merge branch 'main' into v2-consistency
pmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import enum | ||
import importlib.machinery | ||
import importlib.util | ||
import inspect | ||
|
@@ -83,35 +82,6 @@ def __init__( | |
supports_pil=False, | ||
make_images_kwargs=dict(DEFAULT_MAKE_IMAGES_KWARGS, dtypes=[torch.float]), | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.Resize, | ||
legacy_transforms.Resize, | ||
[ | ||
NotScriptableArgsKwargs(32), | ||
ArgsKwargs([32]), | ||
ArgsKwargs((32, 29)), | ||
ArgsKwargs((31, 28), interpolation=v2_transforms.InterpolationMode.NEAREST), | ||
ArgsKwargs((30, 27), interpolation=PIL.Image.NEAREST), | ||
ArgsKwargs((35, 29), interpolation=PIL.Image.BILINEAR), | ||
NotScriptableArgsKwargs(31, max_size=32), | ||
ArgsKwargs([31], max_size=32), | ||
NotScriptableArgsKwargs(30, max_size=100), | ||
ArgsKwargs([31], max_size=32), | ||
ArgsKwargs((29, 32), antialias=False), | ||
ArgsKwargs((28, 31), antialias=True), | ||
], | ||
# atol=1 due to Resize v2 is using native uint8 interpolate path for bilinear and nearest modes | ||
closeness_kwargs=dict(rtol=0, atol=1), | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.Resize, | ||
legacy_transforms.Resize, | ||
[ | ||
ArgsKwargs((33, 26), interpolation=v2_transforms.InterpolationMode.BICUBIC, antialias=True), | ||
ArgsKwargs((34, 25), interpolation=PIL.Image.BICUBIC, antialias=True), | ||
], | ||
closeness_kwargs=dict(rtol=0, atol=21), | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.CenterCrop, | ||
legacy_transforms.CenterCrop, | ||
|
@@ -187,20 +157,6 @@ def __init__( | |
# Use default tolerances of `torch.testing.assert_close` | ||
closeness_kwargs=dict(rtol=None, atol=None), | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.ConvertImageDtype, | ||
legacy_transforms.ConvertImageDtype, | ||
[ | ||
ArgsKwargs(torch.float16), | ||
ArgsKwargs(torch.bfloat16), | ||
ArgsKwargs(torch.float32), | ||
ArgsKwargs(torch.float64), | ||
ArgsKwargs(torch.uint8), | ||
], | ||
supports_pil=False, | ||
# Use default tolerances of `torch.testing.assert_close` | ||
closeness_kwargs=dict(rtol=None, atol=None), | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.ToPILImage, | ||
legacy_transforms.ToPILImage, | ||
|
@@ -226,22 +182,6 @@ def __init__( | |
# images given that the transform does nothing but call it anyway. | ||
supports_pil=False, | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomHorizontalFlip, | ||
legacy_transforms.RandomHorizontalFlip, | ||
[ | ||
ArgsKwargs(p=0), | ||
ArgsKwargs(p=1), | ||
], | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomVerticalFlip, | ||
legacy_transforms.RandomVerticalFlip, | ||
[ | ||
ArgsKwargs(p=0), | ||
ArgsKwargs(p=1), | ||
], | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomEqualize, | ||
legacy_transforms.RandomEqualize, | ||
|
@@ -367,30 +307,6 @@ def __init__( | |
], | ||
closeness_kwargs={"atol": 1e-5, "rtol": 1e-5}, | ||
), | ||
*[ | ||
ConsistencyConfig( | ||
v2_transforms.ElasticTransform, | ||
legacy_transforms.ElasticTransform, | ||
[ | ||
ArgsKwargs(), | ||
ArgsKwargs(alpha=20.0), | ||
ArgsKwargs(alpha=(15.3, 27.2)), | ||
ArgsKwargs(sigma=3.0), | ||
ArgsKwargs(sigma=(2.5, 3.9)), | ||
ArgsKwargs(interpolation=v2_transforms.InterpolationMode.NEAREST), | ||
ArgsKwargs(interpolation=v2_transforms.InterpolationMode.BICUBIC), | ||
ArgsKwargs(interpolation=PIL.Image.NEAREST), | ||
ArgsKwargs(interpolation=PIL.Image.BICUBIC), | ||
ArgsKwargs(fill=1), | ||
], | ||
# ElasticTransform needs larger images to avoid the needed internal padding being larger than the actual image | ||
make_images_kwargs=dict(DEFAULT_MAKE_IMAGES_KWARGS, sizes=[(163, 163), (72, 333), (313, 95)], dtypes=[dt]), | ||
# We updated gaussian blur kernel generation with a faster and numerically more stable version | ||
# This brings float32 accumulation visible in elastic transform -> we need to relax consistency tolerance | ||
closeness_kwargs=ckw, | ||
) | ||
for dt, ckw in [(torch.uint8, {"rtol": 1e-1, "atol": 1}), (torch.float32, {"rtol": 1e-2, "atol": 1e-3})] | ||
], | ||
ConsistencyConfig( | ||
v2_transforms.GaussianBlur, | ||
legacy_transforms.GaussianBlur, | ||
|
@@ -402,26 +318,6 @@ def __init__( | |
], | ||
closeness_kwargs={"rtol": 1e-5, "atol": 1e-5}, | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomAffine, | ||
legacy_transforms.RandomAffine, | ||
[ | ||
ArgsKwargs(degrees=30.0), | ||
ArgsKwargs(degrees=(-20.0, 10.0)), | ||
ArgsKwargs(degrees=0.0, translate=(0.4, 0.6)), | ||
ArgsKwargs(degrees=0.0, scale=(0.3, 0.8)), | ||
ArgsKwargs(degrees=0.0, shear=13), | ||
ArgsKwargs(degrees=0.0, shear=(8, 17)), | ||
ArgsKwargs(degrees=0.0, shear=(4, 5, 4, 13)), | ||
ArgsKwargs(degrees=(-20.0, 10.0), translate=(0.4, 0.6), scale=(0.3, 0.8), shear=(4, 5, 4, 13)), | ||
ArgsKwargs(degrees=30.0, interpolation=v2_transforms.InterpolationMode.NEAREST), | ||
ArgsKwargs(degrees=30.0, interpolation=PIL.Image.NEAREST), | ||
ArgsKwargs(degrees=30.0, fill=1), | ||
ArgsKwargs(degrees=30.0, fill=(2, 3, 4)), | ||
ArgsKwargs(degrees=30.0, center=(0, 0)), | ||
], | ||
removed_params=["fillcolor", "resample"], | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomCrop, | ||
legacy_transforms.RandomCrop, | ||
|
@@ -456,21 +352,6 @@ def __init__( | |
], | ||
closeness_kwargs={"atol": None, "rtol": None}, | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.RandomRotation, | ||
legacy_transforms.RandomRotation, | ||
[ | ||
ArgsKwargs(degrees=30.0), | ||
ArgsKwargs(degrees=(-20.0, 10.0)), | ||
ArgsKwargs(degrees=30.0, interpolation=v2_transforms.InterpolationMode.BILINEAR), | ||
ArgsKwargs(degrees=30.0, interpolation=PIL.Image.BILINEAR), | ||
ArgsKwargs(degrees=30.0, expand=True), | ||
ArgsKwargs(degrees=30.0, center=(0, 0)), | ||
ArgsKwargs(degrees=30.0, fill=1), | ||
ArgsKwargs(degrees=30.0, fill=(1, 2, 3)), | ||
], | ||
removed_params=["resample"], | ||
), | ||
ConsistencyConfig( | ||
v2_transforms.PILToTensor, | ||
legacy_transforms.PILToTensor, | ||
|
@@ -514,23 +395,6 @@ def __init__( | |
] | ||
|
||
|
||
def test_automatic_coverage(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was useful in the beginning, to ensure we are not missing something. But now that we start to remove configs here, we need to remove this check as well. |
||
available = { | ||
name | ||
for name, obj in legacy_transforms.__dict__.items() | ||
if not name.startswith("_") and isinstance(obj, type) and not issubclass(obj, enum.Enum) | ||
} | ||
|
||
checked = {config.legacy_cls.__name__ for config in CONSISTENCY_CONFIGS} | ||
|
||
missing = available - checked | ||
if missing: | ||
raise AssertionError( | ||
f"The prototype transformations {sequence_to_str(sorted(missing), separate_last='and ')} " | ||
f"are not checked for consistency although a legacy counterpart exists." | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("config", CONSISTENCY_CONFIGS, ids=lambda config: config.legacy_cls.__name__) | ||
def test_signature_consistency(config): | ||
legacy_params = dict(inspect.signature(config.legacy_cls).parameters) | ||
|
@@ -708,15 +572,9 @@ def test_call_consistency(config, args_kwargs): | |
(v2_transforms.RandomResizedCrop, ArgsKwargs(make_image(), scale=[0.3, 0.7], ratio=[0.5, 1.5])), | ||
(v2_transforms.RandomErasing, ArgsKwargs(make_image(), scale=(0.3, 0.7), ratio=(0.5, 1.5))), | ||
(v2_transforms.ColorJitter, ArgsKwargs(brightness=None, contrast=None, saturation=None, hue=None)), | ||
(v2_transforms.ElasticTransform, ArgsKwargs(alpha=[15.3, 27.2], sigma=[2.5, 3.9], size=[17, 31])), | ||
(v2_transforms.GaussianBlur, ArgsKwargs(0.3, 1.4)), | ||
( | ||
v2_transforms.RandomAffine, | ||
ArgsKwargs(degrees=[-20.0, 10.0], translate=None, scale_ranges=None, shears=None, img_size=[15, 29]), | ||
), | ||
(v2_transforms.RandomCrop, ArgsKwargs(make_image(size=(61, 47)), output_size=(19, 25))), | ||
(v2_transforms.RandomPerspective, ArgsKwargs(23, 17, 0.5)), | ||
(v2_transforms.RandomRotation, ArgsKwargs(degrees=[-20.0, 10.0])), | ||
(v2_transforms.AutoAugment, ArgsKwargs(5)), | ||
] | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these configs are now obsolete. Going forwards, whenever we port a new test to
test_*_refactored.py
, we can also remove the configs here.