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

Split wrap_symint out of wrap_unspecialized_primitive #125483

Closed
wants to merge 4 commits into from

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented May 3, 2024

Stack from ghstack (oldest at bottom):

While there are some similarities, they are also quite different (one
handles Numpy numbers while the other handles ints. I am also going to
add a wrap_symfloat soon which will do even more different behavior.
So split these out for clarity.

Signed-off-by: Edward Z. Yang [email protected]

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang

[ghstack-poisoned]
Copy link

pytorch-bot bot commented May 3, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 449acdd with merge base 79af814 (image):
💚 Looks good so far! There are no failures yet. 💚

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

ezyang added a commit that referenced this pull request May 3, 2024
While there are some similarities, they are also quite different (one
handles Numpy numbers while the other handles ints.  I am also going to
add a wrap_symfloat soon which will do even more different behavior.
So split these out for clarity.

Signed-off-by: Edward Z. Yang <[email protected]>

ghstack-source-id: fe0128b2113f3de87d9aeb40356d95437e77f1d3
Pull Request resolved: #125483
[ghstack-poisoned]
ezyang added a commit that referenced this pull request May 3, 2024
While there are some similarities, they are also quite different (one
handles Numpy numbers while the other handles ints.  I am also going to
add a wrap_symfloat soon which will do even more different behavior.
So split these out for clarity.

Signed-off-by: Edward Z. Yang <[email protected]>

ghstack-source-id: 12612e4e2da189b8167c606c3a2ed80595ec4103
Pull Request resolved: #125483
@albanD albanD removed their request for review May 3, 2024 19:27
[ghstack-poisoned]
[ghstack-poisoned]
)

# NB: We do not do float. For motivation, see
# https://docs.google.com/document/d/1INSCdYu1PxXcr43HrD82OudeEuS-qxQe1yZmLg2wy6A/edit
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is stale

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually not stale, but I'm going to be ripping all this out soon anyway

Comment on lines +1377 to +1378
# TODO: Do I actually need guard for constant source?
self.install_guards(GuardBuilder.CONSTANT_MATCH)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. But note that we already have a version of this path in wrap_literal with a much more complex condition, so it would be good to reconcile them. Unless you plan to use this function in other contexts, of course.

elif (
type(value) is int
and not is_constant_source(self.get_source())
and not isinstance(self.get_source(), RandomValueSource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why were RandomValues not allowed here before and why do we allow them now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The prior behavior, which this PR makes clear (because I did not change this at all), is that the RandomValue case can only occur under the wrap_unspecialized_primitive path, which eventually produces the UnspecializedPythonVariable subclass (that is treated like a Tensor). So wrap_symint can never be called with a RandomValueSource.

This is a kind of illogical separation, it's more logical for an integer random variable to be treated as a SymNodeVariable, but the point of this PR is not to fix the problem yet, it's just to make it more clear what the current behavior is.

Comment on lines +1444 to +1448
self.tx.output.unspec_variable_map[self.name] = unspec_var
if not is_constant_source(self.get_source()):
if self.tx.export and not isinstance(self.get_source(), LocalSource):
raise AssertionError(
f"Dynamo attempts to add additional input during export: value={wrapped_value}, source={self.get_source()}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now all this is duped??

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'm not really sure what I want to do with this code. I suppose it can be factored to a method. It's pretty short though, I might end up rewriting it all

@ezyang ezyang requested a review from jansel May 5, 2024 13:42
@ezyang
Copy link
Contributor Author

ezyang commented May 5, 2024

If people hate this "defactor" then I will probably just absorb it into the actual rewrite that is coming later in the stack. This is split out because it is change neutral (no behavior change) and I think will make the next rewrite easier to review.

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.

Nah, it's fine.

You might also consider submitting the rest of changes as one PR with clean commit history to be able to have all the changes separated and easy to review, but also a clear end state that does not instantiate all the intermediary suboptimal states.

pytorchmergebot pushed a commit that referenced this pull request May 5, 2024
We use very little of the code in wrap_fx_proxy_cls, so dupe it out.

Signed-off-by: Edward Z. Yang <[email protected]>

Pull Request resolved: #125494
Approved by: https://github.com/lezcano
ghstack dependencies: #125395, #125419, #125483
pytorchmergebot pushed a commit that referenced this pull request May 5, 2024
Signed-off-by: Edward Z. Yang <[email protected]>

Pull Request resolved: #125496
Approved by: https://github.com/lezcano
ghstack dependencies: #125395, #125419, #125483, #125494
@github-actions github-actions bot deleted the gh/ezyang/2725/head branch June 5, 2024 01:55
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

3 participants