Skip to content

Conversation

skpark-rh
Copy link
Contributor

@skpark-rh skpark-rh commented Aug 27, 2025

Fixes #161014

This bug fix introduces a fix that is consistent with the exception handling. Outlined in issue #161014, there is an edge case where the negative padding does not make the tensor size negative but still triggers the exception that the size is negative. The fix is simply adding new_dim >=0 to include the zero dim and letting the operator return an empty tensor.

In the PR I have added the edge case where the test will now check the negative padding where the dimension gets reduced to zero. But the sample is only for the constant type of padding. I would like some feedback if it is necessary to put the same sample on the reduce type as well.

This is my first PR to contribute to PyTorch and any help/feedback will be welcome! Thank you!

@malfet @manuelcandales @janeyx99 @ezyang

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @ezyang @msaroufim @dcci @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @Lucaskabela

@skpark-rh skpark-rh requested a review from mruberry as a code owner August 27, 2025 18:38
Copy link

pytorch-bot bot commented Aug 27, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 74a3823 with merge base 264e7f6 (image):
💚 Looks good so far! There are no failures yet. 💚

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

Copy link

linux-foundation-easycla bot commented Aug 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@skpark-rh
Copy link
Contributor Author

@pytorchbot label "topic: bug fixes"

@pytorch-bot pytorch-bot bot added the topic: bug fixes topic category label Aug 27, 2025
@skpark-rh
Copy link
Contributor Author

skpark-rh commented Aug 28, 2025

Hi @manuelcandales
So the only test that is failing doesn't seem to be related to the changes implemented in this fix. It is a torch distributed test... It is a NotImplementedError: Operator aten.linalg_inv_ex.default does not have a sharding strategy registered.

auto pad_idx = pad.size() - ((i + 1) * 2);
auto new_dim = input_sizes[l_diff + i] + pad[pad_idx] + pad[pad_idx + 1];
TORCH_CHECK(new_dim > 0, "The input size ", input_sizes[l_diff + i], ", plus negative padding ",
TORCH_CHECK(new_dim >= 0, "The input size ", input_sizes[l_diff + i], ", plus negative padding ",
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIt: this should probably be TORCH_CHECK_VIEW

Copy link
Contributor Author

@skpark-rh skpark-rh Aug 29, 2025

Choose a reason for hiding this comment

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

I don't see a TORCH_CHECK_VIEW in the repo... Could you point me to it so that I can see it and make appropriate changes?

@ezyang
Copy link
Contributor

ezyang commented Aug 30, 2025

@manuelcandales please shepherd this to land, thanks!

@skpark-rh
Copy link
Contributor Author

Hi just checking in with this PR. Any help landing this will be much appreciated.

@manuelcandales @ezyang

@isuruf
Copy link
Collaborator

isuruf commented Sep 19, 2025

@skpark-rh can you fix the failing test? The failing test was marked as xfail and we can remove it because of your fix.

@skpark-rh
Copy link
Contributor Author

@isuruf Okay I can take a look at the failing test. The new test case, ((5, 3), (-1, -2, 1, 1)), that I put in torch/testing/_internal/common_methods_invocations.py may be causing the distributed tensor test to fail. Although I don't know how that is possible. Any pointers will be much appreciated!

@isuruf
Copy link
Collaborator

isuruf commented Sep 19, 2025

@skpark-rh the new test you added has nothing to do with it. The test test_dtensor_op_db_linalg_multi_dot_cpu_float32 failed with RuntimeError: The input size 0, plus negative padding 0 and 0 resulted in a negative output size, which is invalid. Check dimension 1 of your input. and therefore it was marked as a expected failure. With your PR, the test passes and therefore we just need to remove the xfail marker from the test.

@skpark-rh
Copy link
Contributor Author

@isuruf Okay that makes sense. I removed the xfail linalg.multi_dot.

@isuruf
Copy link
Collaborator

isuruf commented Sep 19, 2025

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 19, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@skpark-rh skpark-rh deleted the bugfix/constant_pad_nd branch September 19, 2025 21:06
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Fixes pytorch#161014

This bug fix introduces a fix that is consistent with the exception handling. Outlined in issue pytorch#161014, there is an edge case where the negative padding does not make the tensor size negative but still triggers the exception that the size is negative. The fix is simply adding `new_dim >=0` to include the zero dim and letting the operator return an empty tensor.

In the PR I have added the edge case where the test will now check the negative padding where the dimension gets reduced to zero.  But the sample is only for the `constant` type of padding. I would like some feedback if it is necessary to put the same sample on the `reduce` type as well.

This is my first PR to contribute to PyTorch and any help/feedback will be welcome! Thank you!

@malfet @manuelcandales @janeyx99 @ezyang

Pull Request resolved: pytorch#161639
Approved by: https://github.com/manuelcandales
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Fixes pytorch#161014

This bug fix introduces a fix that is consistent with the exception handling. Outlined in issue pytorch#161014, there is an edge case where the negative padding does not make the tensor size negative but still triggers the exception that the size is negative. The fix is simply adding `new_dim >=0` to include the zero dim and letting the operator return an empty tensor.

In the PR I have added the edge case where the test will now check the negative padding where the dimension gets reduced to zero.  But the sample is only for the `constant` type of padding. I would like some feedback if it is necessary to put the same sample on the `reduce` type as well.

This is my first PR to contribute to PyTorch and any help/feedback will be welcome! Thank you!

@malfet @manuelcandales @janeyx99 @ezyang

Pull Request resolved: pytorch#161639
Approved by: https://github.com/manuelcandales
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Fixes pytorch#161014

This bug fix introduces a fix that is consistent with the exception handling. Outlined in issue pytorch#161014, there is an edge case where the negative padding does not make the tensor size negative but still triggers the exception that the size is negative. The fix is simply adding `new_dim >=0` to include the zero dim and letting the operator return an empty tensor.

In the PR I have added the edge case where the test will now check the negative padding where the dimension gets reduced to zero.  But the sample is only for the `constant` type of padding. I would like some feedback if it is necessary to put the same sample on the `reduce` type as well.

This is my first PR to contribute to PyTorch and any help/feedback will be welcome! Thank you!

@malfet @manuelcandales @janeyx99 @ezyang

Pull Request resolved: pytorch#161639
Approved by: https://github.com/manuelcandales
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue open source release notes: inductor (aoti) release notes: releng release notes category topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent constant_pad_nd behavior with negative padding

7 participants