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

Refactor wrap_fx_proxy_cls, no symbolic_shapes test anymore #103303

Closed
wants to merge 3 commits into from

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Jun 9, 2023

Stack from ghstack (oldest at bottom):

Originally, wrap_fx_proxy_cls had a thicket of conditions handling a lot of cases that, frankly, didn't make any sense to me. This refactor attempts to make sense out of the madness. Some important basic knowledge:

  • Check the high level comment at Add big doc to wrap_fx_proxy_cls #103407 describing what this function even does
  • Read the implementation of SymNodeVariable.create. In particular, if you pass it a concrete int (not SymInt), you actually end up with a ConstantVariable (and it incorrectly does not apply this treatment to floats/bools)
  • Note that example_value is None was previously overloaded for two conditions: (1) please compute the example value by running get_fake_value and (2) my example value is literally None please give me a ConstantVariable(None)
  • Notice that all of the conditionals check all sorts of different things but in the end you either make a SymNodeVariable or ConstantVariable

The refactor proceeds as follows:

  • Replace the default example_value with no_example singleton object, so we can distinguish it from None. This allows us to remove the attention return None special case. There are a few sites in code where None is explicitly passed in as example_value when they shouldn't be; they're updated to rely on the default argument.
  • Make it clear that non-SymInt/etc example values always get turned into ConstantVariable (this matches previous behavior but now it's a lot more obvious at the call site)
  • Consolidate tuple/list/torch.Size handling
  • Delete most of the special case logic for individual operators as they are subsumed by the generic handling

One thing I didn't fix is the special case for TupleVariable target_cls. I think this is just a straight up bug but I didn't feel like fixing that corner of the codebase, so leaving a mess for now.

Signed-off-by: Edward Z. Yang ezyang@meta.com

cc @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @ipiszy @aakhundov

…eems risky.

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Jun 9, 2023

ezyang added a commit that referenced this pull request Jun 9, 2023
…eems risky.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 5a81b5b661bf0c7615c5d44ae3ed08eddbe0c58e
Pull Request resolved: #103303
…cls. This seems risky."

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy aakhundov

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 12, 2023
Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 62e0cdc7373ecfd7185e0a014864eab542d6695c
Pull Request resolved: #103303
@ezyang ezyang changed the title [TEST] Delete not dynamic_shapes tests from wrap_fx_proxy_cls. This seems risky. Refactor wrap_fx_proxy_cls Jun 12, 2023
@ezyang ezyang changed the title Refactor wrap_fx_proxy_cls Refactor wrap_fx_proxy_cls, no symbolic_shapes test anymore Jun 12, 2023
Signed-off-by: Edward Z. Yang <ezyangmeta.com>

cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy aakhundov

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 12, 2023
Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 5738a2141baa95f6ccb7e431da961beb2a80d5ea
Pull Request resolved: #103303
@ezyang ezyang requested a review from jansel June 12, 2023 03:19
@ezyang ezyang added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 12, 2023
@@ -1059,7 +1059,10 @@ def _dataclasses_fields_lambda(obj):
return TupleVariable(items).add_options(obj)


def wrap_fx_proxy(tx, proxy, example_value=None, **options):
no_example = object()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Read pr description

@ezyang
Copy link
Contributor Author

ezyang commented Jun 12, 2023

Obsoleted by #103438

@ezyang ezyang closed this Jun 12, 2023
ezyang added a commit that referenced this pull request Jul 9, 2023
Per #103303 we cannot
universally allow tracing in all functions that return int,
as the graph breaks appear to be load bearing in some cases.
However, allowing for torch.sym_int to be traced in even if
the result is statically known is fine; this can happen in
case of a SymBool to int conversion.

This PR is not exhaustive but e.g., I fixed size/stride/numel
handling in #103438
The biggest risk is that arithmetic operations on sizes end
up getting constant-ified (this appears to have happened in
practice for modulus, which is why it's in this list.)  If
we don't care about spewing useless computation into the graph,
a more aggressive version of this PR would be to greatly expand
the list of allowed to specialize to int targets and then undo
#103438

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jul 9, 2023
Per #103303 we cannot
universally allow tracing in all functions that return int,
as the graph breaks appear to be load bearing in some cases.
However, allowing for torch.sym_int to be traced in even if
the result is statically known is fine; this can happen in
case of a SymBool to int conversion.

This PR is not exhaustive but e.g., I fixed size/stride/numel
handling in #103438
The biggest risk is that arithmetic operations on sizes end
up getting constant-ified (this appears to have happened in
practice for modulus, which is why it's in this list.)  If
we don't care about spewing useless computation into the graph,
a more aggressive version of this PR would be to greatly expand
the list of allowed to specialize to int targets and then undo
#103438

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: d63980a89a67822f69a606df60f6f17f3cc186bb
Pull Request resolved: #104837
pytorchmergebot pushed a commit that referenced this pull request Jul 9, 2023
Per #103303 we cannot
universally allow tracing in all functions that return int,
as the graph breaks appear to be load bearing in some cases.
However, allowing for torch.sym_int to be traced in even if
the result is statically known is fine; this can happen in
case of a SymBool to int conversion.

This PR is not exhaustive but e.g., I fixed size/stride/numel
handling in #103438
The biggest risk is that arithmetic operations on sizes end
up getting constant-ified (this appears to have happened in
practice for modulus, which is why it's in this list.)  If
we don't care about spewing useless computation into the graph,
a more aggressive version of this PR would be to greatly expand
the list of allowed to specialize to int targets and then undo
#103438

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: #104837
Approved by: https://github.com/voznesenskym
@facebook-github-bot facebook-github-bot deleted the gh/ezyang/2152/head branch July 13, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request module: dynamo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants