Fix: [Inductor] Enforce strict negative index check for index_select (fixes #169779)#169788
Fix: [Inductor] Enforce strict negative index check for index_select (fixes #169779)#169788dumko2001 wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/169788
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 52e4b24 with merge base 3e026f2 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "bug" "release notes: inductor" |
|
@pytorchbot label "release notes: inductor" "topic: not user facing" |
|
Didn't find following labels among repository labels: bug |
malfet
left a comment
There was a problem hiding this comment.
This would work, but IMO this is a wrong approach, one should just add support for exception in torch.compile for MPS
d70da5f to
af6cb6d
Compare
|
@malfet Thank you for the feedback. I agree that a custom Inductor lowering is the wrong approach and have updated the PR to rely on decomposition:
The fix now ensures the strict semantics of For the check itself, I used I agree that improving systemic exception propagation for Please let me know if this updated approach looks better for merging. |
|
@malfet I have updated the PR based on the findings.
|
3cadd4a to
52e4b24
Compare
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Summary
Fixes #169779.
This PR fixes an inconsistency where
torch.compile(Inductor) handled negative indices inindex_selectincorrectly (silently wrapping them or producing wrong results), whereas Eager mode strictly raises aRuntimeError.The Fix
torch/_refs/__init__.py: Added a strict_assert_asynccheck for non-negative indices in the reference implementation.aten.index_selectis already defined in the Reference implementation. Adding a separate decomposition caused registry conflicts. Modifying_refsensures that Inductor (and any other backend using Refs) adheres to PyTorch's strict non-negative index semantics.decompositions.pyorlowering.pyhave been reverted in favor of this cleaner Reference fix.)Testing
InductorIndexSelectTeststotest/inductor/test_torchinductor.py.index_selectnow raisesRuntimeErroron negative indices.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @mlazos