Skip to content
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

[inductor] Fix ops.scan for non-commutative operators #126633

Closed
wants to merge 2 commits into from

Conversation

peterbell10
Copy link
Collaborator

@peterbell10 peterbell10 commented May 19, 2024

Stack from ghstack (oldest at bottom):

tl.associative_scan supports non-commutative combine functions but tl.reduce
doesn't. This effects non-persistent scans, where we use the reduction from
the previous loop iterations as the base for future iterations.

Here I work around this by taking the last element of the scan output and using
that as the reduced value. This is done using a trick where we create a
mask that is 1 at the desired element and 0 elsewhere, then sum over it.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang

[ghstack-poisoned]
Copy link

pytorch-bot bot commented May 19, 2024

🔗 Helpful Links

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

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

✅ You can merge normally! (6 Unrelated Failures)

As of commit e997c79 with merge base failed to retrieve merge base, please contact dev infra:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:

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

peterbell10 added a commit that referenced this pull request May 19, 2024
`tl.associative_scan` supports non-commutative combine functions but `tl.reduce`
doesn't. This effects non-persistent scans, where we use the reduction from
the previous loop iterations as the base for future iterations.

Here I work around this by taking the last element of the scan output and using
that as the reduced value. This is possibly by using a trick where we create a
mask that is 1 at the desired element and 0 elsewhere, then sum over it.

ghstack-source-id: 98756771652cefc61e7367dadf795f7e69d24402
Pull Request resolved: #126633
[ghstack-poisoned]
peterbell10 added a commit that referenced this pull request May 19, 2024
`tl.associative_scan` supports non-commutative combine functions but `tl.reduce`
doesn't. This effects non-persistent scans, where we use the reduction from
the previous loop iterations as the base for future iterations.

Here I work around this by taking the last element of the scan output and using
that as the reduced value. This is possibly by using a trick where we create a
mask that is 1 at the desired element and 0 elsewhere, then sum over it.

ghstack-source-id: 23a6f1b7717633dcf38743aad9d5b6bc937dc935
Pull Request resolved: #126633
@peterbell10 peterbell10 marked this pull request as ready for review May 19, 2024 23:09
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

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

Oh well. We should eventually fix the non-commutativity of tl.reduce, should be quite straightforward. With that fixed, we could pick up the last element reducing with

def last(a, b):
  return b

Of course, the real fix would be to expose 1-element slices over a dimension in triton.

@lezcano
Copy link
Collaborator

lezcano commented May 20, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 20, 2024
@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@lezcano
Copy link
Collaborator

lezcano commented May 20, 2024

@pytorchbot merge

@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

@peterbell10
Copy link
Collaborator Author

peterbell10 commented May 20, 2024

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Can't merge closed PR #126633

@jeffdaily
Copy link
Collaborator

This newly-added test is failing ROCm. Will attempt to skip it for now.

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.

None yet

6 participants