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

[dtensor] remove torchgen function schema and parse manually #90106

Closed
wants to merge 2 commits into from

Conversation

wanchaol
Copy link
Contributor

@wanchaol wanchaol commented Dec 3, 2022

Stack from ghstack (oldest at bottom):

This PR get rids of torchgen FunctionSchema parsing and parse
it manually, it should resolve torchgen package issue and also
provide some perf wins when running DTensor eagerly

This PR get rids of torchgen FunctionSchema parsing and parse
it manually, it should resolve torchgen package issue and also
provide some perf wins when running DTensor eagerly

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 3, 2022

🔗 Helpful Links

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

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

❌ 1 Failures

As of commit fa891ef:

The following jobs have failed:

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

wanchaol added a commit that referenced this pull request Dec 3, 2022
This PR get rids of torchgen FunctionSchema parsing and parse
it manually, it should resolve torchgen package issue and also
provide some perf wins when running DTensor eagerly

ghstack-source-id: df45231ebe398f97bdfe75de05adecae1faed1ab
Pull Request resolved: #90106
@wanchaol wanchaol added the release notes: distributed (dtensor) release notes category label Dec 3, 2022
self.is_out_variant = (
schema_kind == SchemaKind.out # pyre-ignore [16] pyre bad at enum
)
# simple analysis of function schema to determine
Copy link
Contributor

Choose a reason for hiding this comment

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

Conceptual: Does this PR regress the computation of self.is_inplace and self._is_out_variant in some cases because you are using a heuristic instead of SchemaKind?

I am curious how you think about the tradeoff of getting rid of the torchgen dependency versus possibly having incorrect values for is_inplace and is_out_variant in some cases (if at all).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, from the current operator set registered, i think it should work fine as all of the op signature naming following the same convention for inplace and out variant (_ and .out), so I think this heuristic is relatively safe to use and should not regress existing registered operators. However, it does rely on operators following the same convention of naming, which I think it might get changed. Given that ATen op set is relatively stable at this point, I think we can go with this approach as it's simple and very fast without parsing FunctionSchema, if ever op signature gets changed, the heuristic need to be adapted to accommodate.

@wanchaol wanchaol requested a review from fduwjj December 3, 2022 04:41
@wanchaol wanchaol added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category and removed release notes: distributed (dtensor) release notes category labels Dec 3, 2022
Copy link
Contributor

@awgu awgu left a comment

Choose a reason for hiding this comment

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

I am not sure I have the context to approve, so I will defer to someone else.

out_dt = cast(dtensor.DTensor, kwargs[arg.name])
out_dt._spec = cast(DTensorSpec, output_specs[spec_idx])
out_dts.append(out_dt)
spec_idx += 1
return tuple(out_dts) if len(out_dts) > 1 else out_dts[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

General comment: This return assumes len(out_dts) >= 1 or else there will be an index out of bounds error when accessing out_dts[0]. I am guessing that this len(out_dts) >= 1 invariant always holds, but I just wanted to point this out. Maybe you want an assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll land this as is as I don't want to trigger another full CI run, the assert is added in the follow up PR #90241

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nvm, might still need to change sth, will update.

Copy link
Contributor

@awgu awgu left a comment

Choose a reason for hiding this comment

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

This looks good to me, so I will stamp to unblock. Feel free to wait for others' review.

Copy link
Contributor

@fduwjj fduwjj left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me and do we have an estimate of potential perf win?

This PR get rids of torchgen FunctionSchema parsing and parse
it manually, it should resolve torchgen package issue and also
provide some perf wins when running DTensor eagerly

[ghstack-poisoned]
@wanchaol
Copy link
Contributor Author

wanchaol commented Dec 6, 2022

Overall this looks good to me and do we have an estimate of potential perf win?

I don't yet as I didn't profile this, but my suspection is that it could result in around 20-30 perf wins on DTensor execution, feel free to try it out, I'll focus on making other parts be faster if possible.

@wanchaol
Copy link
Contributor Author

wanchaol commented Dec 6, 2022

@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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 2 additional jobs have failed, first few of them are: linux-binary-manywheel ,linux-binary-manywheel / manywheel-py3_7-cuda11_6-test / build

Details for Dev Infra team Raised by workflow job

@wanchaol
Copy link
Contributor Author

wanchaol commented Dec 6, 2022

@pytorchbot merge -f "failure not related"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

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

kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
…#90106)

This PR get rids of torchgen FunctionSchema parsing and parse
it manually, it should resolve torchgen package issue and also
provide some perf wins when running DTensor eagerly
Pull Request resolved: pytorch#90106
Approved by: https://github.com/awgu
pytorchmergebot pushed a commit that referenced this pull request Dec 10, 2022
)

This is a reland of #89845 with nothing changed. This should avoid the internal breakage now that `DTensor` does not import `torchgen` (#90106).
Pull Request resolved: #90562
Approved by: https://github.com/fduwjj
@facebook-github-bot facebook-github-bot deleted the gh/wanchaol/225/head branch June 8, 2023 19:06
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 topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants