Skip to content

Fix/8877 elastic transform negative sigma - #9627

Open
AayushMainali-Github wants to merge 2 commits into
pytorch:mainfrom
AayushMainali-Github:fix/8877-elastic-transform-negative-sigma
Open

Fix/8877 elastic transform negative sigma#9627
AayushMainali-Github wants to merge 2 commits into
pytorch:mainfrom
AayushMainali-Github:fix/8877-elastic-transform-negative-sigma

Conversation

@AayushMainali-Github

Copy link
Copy Markdown

Summary

  • Reject negative sigma when constructing v1 and v2 ElasticTransform, matching the existing “sigma should be positive/non-negative” expectation.
  • Keep sigma=0 valid so smoothing can still be disabled along an axis.
  • Add regression tests for scalar negatives, all-negative sequences, and mixed-sign sequences.

Fixes #8877

Problem

ElasticTransform only runs gaussian_blur when sigma[i] > 0. All-negative inputs such as sigma=-100 or sigma=[-100, -100] therefore skip the blur and never hit the kernel’s positivity check. Mixed-sign values still fail later, which made the constructor validation look inconsistent.

Fix

After sigma is normalized to a two-element sequence, both constructors raise ValueError if any component is negative. Zero remains allowed because the displacement code already treats sigma == 0 as “do not smooth.”

Testing

  • python -m pytest test/test_transforms.py::test_elastic_transformation test/test_transforms_v2.py::TestElastic::test_transform_negative_sigma -q (6 passed)
  • python -m pytest test/test_transforms_v2.py::TestElastic -q -k "not test_kernel and not test_functional" (33 passed, 21 skipped on CPU-only)
  • Confirmed the new tests fail with DID NOT RAISE ValueError on unmodified constructors
  • ufmt check on the changed files passed

@pytorch-bot

pytorch-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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

@meta-cla

meta-cla Bot commented Aug 25, 2026

Copy link
Copy Markdown

Hi @AayushMainali-Github!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Aug 25, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the cla signed label Aug 25, 2026
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.

Setting a single negative value or a couple of negative values to sigma argument of ElasticTransform() doesn't get error against the error message

1 participant