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

[functorch] Prevent using for-loop for out-of-place index_fill batch rule #99229

Closed
wants to merge 6 commits into from

Conversation

qqaatw
Copy link
Collaborator

@qqaatw qqaatw commented Apr 15, 2023

@pytorch-bot
Copy link

pytorch-bot bot commented Apr 15, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit b77fce9:
💚 Looks good so far! There are no failures yet. 💚

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

qqaatw added a commit that referenced this pull request Apr 15, 2023
…rule

ghstack-source-id: 2d2ba335785096dd17779c48fa8b991624739822
Pull Request resolved: #99229
@qqaatw qqaatw added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 15, 2023
@qqaatw qqaatw added the release notes: functorch release notes category; Pertaining to torch.func or pytorch/functorch label Apr 15, 2023
@qqaatw qqaatw marked this pull request as ready for review April 15, 2023 16:55
…fill batch rule"


A follow-up PR for #91364 (comment)


[ghstack-poisoned]
qqaatw added a commit that referenced this pull request Apr 17, 2023
…rule

ghstack-source-id: f31f7166b41d8dca2c6b3bdb94bba4478600ad2b
Pull Request resolved: #99229
…fill batch rule"


A follow-up PR for #91364 (comment)


[ghstack-poisoned]
qqaatw added a commit that referenced this pull request Apr 17, 2023
…rule

ghstack-source-id: d7ebf37f89f9117de99198475794f78963aa93ce
Pull Request resolved: #99229
@qqaatw qqaatw added the module: functorch Pertaining to torch.func or pytorch/functorch label Apr 17, 2023
self_slice.index_fill_(
dim,
index_slice,
value_bdim.has_value() ? value_.select(0, i) : value_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we write this for-loop such that we won't have to check value_bdim every iteration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel this is the most concise version, and checking value_bdim would not be costly.

Here are the ways I came up:

  1. Always ensure value has a batch dim and do select in every iteration - costly.
  2. Make copies of the for-loop statement and separate the work out. There are four combinations for inplace and value_bdim.has_value() - not concise.
  3. Determine value_bdim.has_value() before for-loop and use lambdas to wrap either value_ or value_.select(0, i) - I feel unnecessary tbh. Would it be better?

Or maybe I'm missing something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, makes sense, plus I would assume that most of the time would be spent in index_fill so this should be good.

…fill batch rule"


A follow-up PR for #91364 (comment)


cc zou3519 Chillee samdow soumith kshitij12345 janeyx99

[ghstack-poisoned]
qqaatw added a commit that referenced this pull request Apr 18, 2023
…rule

ghstack-source-id: b5feebe0e0d028dac696482ef77c2a5dcc00a6c1
Pull Request resolved: #99229
…fill batch rule"


A follow-up PR for #91364 (comment)


cc zou3519 Chillee samdow soumith kshitij12345 janeyx99

[ghstack-poisoned]
qqaatw added a commit that referenced this pull request Apr 18, 2023
…rule

ghstack-source-id: ad2b76877d4d788d9e5b77bc8c2e40c853d6a331
Pull Request resolved: #99229
…fill batch rule"


A follow-up PR for #91364 (comment)


cc zou3519 Chillee samdow soumith kshitij12345 janeyx99

[ghstack-poisoned]
qqaatw added a commit that referenced this pull request Apr 19, 2023
…rule

ghstack-source-id: 60b5301fc7ae924142a16b044b21a2b90dd1cf24
Pull Request resolved: #99229
Copy link
Collaborator

@kshitij12345 kshitij12345 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @qqaatw

@kshitij12345
Copy link
Collaborator

@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

@facebook-github-bot facebook-github-bot deleted the gh/qqaatw/9/head branch June 8, 2023 18:32
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 merging module: functorch Pertaining to torch.func or pytorch/functorch open source release notes: functorch release notes category; Pertaining to torch.func or pytorch/functorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants