Skip to content

Refactor autoaugment: extract _AutoAugmentBase to deduplicate fill logic#9447

Open
sunnycho100 wants to merge 2 commits intopytorch:mainfrom
sunnycho100:refactor-autoaugment-base-class
Open

Refactor autoaugment: extract _AutoAugmentBase to deduplicate fill logic#9447
sunnycho100 wants to merge 2 commits intopytorch:mainfrom
sunnycho100:refactor-autoaugment-base-class

Conversation

@sunnycho100
Copy link

Closes #9446

Motivation

There is a FIXME at line 103 of torchvision/transforms/autoaugment.py asking to eliminate copy-pasted fill standardization code. Four classes (AutoAugment, RandAugment, TrivialAugmentWide, AugMix) all duplicate the same fill-processing block in their forward() methods and independently set interpolation/fill in their init. The v2 version already solved this with _AutoAugmentBase - this brings the same pattern to v1.

Changes

  • Added _AutoAugmentBase(torch.nn.Module) with common init for interpolation/fill and a _get_fill() helper
  • Updated all 4 classes to inherit from _AutoAugmentBase instead of torch.nn.Module
  • Each class delegates interpolation/fill to super().init() and calls self._get_fill(img) in forward()
  • Removed the FIXME comment

Not changed

  • _augmentation_space() is left per-class (different signatures and contents)
  • No public API changes, no behavior changes - pure internal refactor

Backward-compatible: yes, no public API surface is affected.

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 18, 2026

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 2dcef64 with merge base b358d66 (image):

NEW FAILURES - The following jobs have failed:

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

@meta-cla meta-cla bot added the cla signed label Mar 18, 2026
@sunnycho100 sunnycho100 marked this pull request as ready for review March 18, 2026 07:24
@zy1git
Copy link
Contributor

zy1git commented Mar 19, 2026

@sunnycho100 Thanks a lot for opening this PR and for your willingness to contribute to TorchVision!
We won’t be merging the changes in this PR as-is, since we’re focusing on V2 going forward and aren’t planning to make further changes to V1. Also, it looks like this PR includes commits from another PR (#9444).
If you update this PR to only remove the FIXME comment and adjust the PR description accordingly, I’m happy to approve and merge it.

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.

Refactor autoaugment.py: extract _AutoAugmentBase to eliminate duplicated fill logic

2 participants