Skip to content

Conversation

lezcano
Copy link
Collaborator

@lezcano lezcano commented Jan 17, 2024

Stack from ghstack (oldest at bottom):

Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in
_HashableTracker._eq_impl but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also makes the dicts code easier to maintain
(removes is_hashable_python_var).

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

This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Jan 17, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 9931d42 with merge base 4cba1dd (image):
💚 Looks good so far! There are no failures yet. 💚

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

lezcano added a commit that referenced this pull request Jan 17, 2024
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

ghstack-source-id: f421743
Pull Request resolved: #117625
@lezcano lezcano requested a review from voznesenskym January 17, 2024 10:23
@lezcano lezcano requested review from anijain2305 and jansel January 17, 2024 10:23
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`) and more correct.

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`) and more correct.

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

[ghstack-poisoned]
This removes the need of having to reimplement the whole builder logic
to try to predict what is it that we have inside.

This is marginally less efficient when we graph break, but in turn we
should graph break less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`) and more correct.

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

[ghstack-poisoned]
@lezcano lezcano changed the title Build the keys of a dict depth-first Make variables in dict lazy and avoid using DICT_KEYS guard Jan 18, 2024
@lezcano lezcano requested a review from peterbell10 January 18, 2024 14:45
Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
self.install_guards(GuardBuilder.BOOL_FALSE)
else:
self.install_guards(GuardBuilder.DICT_KEYS)
self.install_guards(GuardBuilder.LIST_LENGTH)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to delete DICT_KEYS guard (maybe we will have to clean up at other places)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's the plan, yes. I'll put up a PR next week.

…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
This was referenced Jan 30, 2024
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
…t) and avoid using DICT_KEYS guard"


Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in 
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

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

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
Supersedes #118096 as a much cleaner and simpler solution.

It is difficult to write a test for this one without exposing too much
of the internals. You can see empirically that it works by running
```
TORCHDYNAMO_PRINT_GUARDS=1 TORCH_LOGS=+guards  python test/test_optim.py -k test_can_load_older_state_dict_ASGD_cpu_float32
```

Pull Request resolved: #118194
Approved by: https://github.com/jansel, https://github.com/peterbell10
ghstack dependencies: #117982, #118098, #117983, #117625
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
With this one, the only keys we are not tracing properly in the
(non-skipped) test suite are `OutDtypeHigherOrderVariable()`, and a
couple `UserDefinedObjectVariables`

Pull Request resolved: #118003
Approved by: https://github.com/anijain2305, https://github.com/Skylion007, https://github.com/jansel
ghstack dependencies: #117982, #118098, #117983, #117625, #118194
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
This is tested by `fullgraph=True` in the `test_getattr_dict` test.
I can write a one-off test for both if that's needed.

Pull Request resolved: #118199
Approved by: https://github.com/peterbell10, https://github.com/jansel, https://github.com/anijain2305
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
…g "params" in an optimizer (#118535)

Fixes the unnecessary guards described at #117983 (comment)

Pull Request resolved: #118535
Approved by: https://github.com/mlazos
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208, #118199
pytorchmergebot pushed a commit that referenced this pull request Feb 2, 2024
We also rename ODICT_KEYS and make it use a list rather than a string.

Split from #118630.

Pull Request resolved: #118855
Approved by: https://github.com/peterbell10
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208, #118199, #118535
@facebook-github-bot facebook-github-bot deleted the gh/Lezcano/252/head branch February 5, 2024 15:23
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
…d using DICT_KEYS guard (#117625)

Make variables in dict lazy and remove DICT_KEYS guard.

We build the keys of a dict depth-first and we rely on the guards of
each element in the dict to create the correct guards. This allows us to
remove the rather buggy DICT_KEYS guard and make the guard lazy.
The guards are not completely lazy yet, as we instantiate them in
`_HashableTracker._eq_impl` but it should be possible to make them
truly lazy.

Also, adding new types to the supported types within keys should be less
error prone.

This is marginally less efficient when we graph break, but in turn we
should graph break much less. It also  makes the dicts code easier to maintain
(removes `is_hashable_python_var`).

Pull Request resolved: #117625
Approved by: https://github.com/jansel, https://github.com/peterbell10, https://github.com/anijain2305
ghstack dependencies: #117982, #118098, #117983
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
Supersedes #118096 as a much cleaner and simpler solution.

It is difficult to write a test for this one without exposing too much
of the internals. You can see empirically that it works by running
```
TORCHDYNAMO_PRINT_GUARDS=1 TORCH_LOGS=+guards  python test/test_optim.py -k test_can_load_older_state_dict_ASGD_cpu_float32
```

Pull Request resolved: #118194
Approved by: https://github.com/jansel, https://github.com/peterbell10
ghstack dependencies: #117982, #118098, #117983, #117625
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
With this one, the only keys we are not tracing properly in the
(non-skipped) test suite are `OutDtypeHigherOrderVariable()`, and a
couple `UserDefinedObjectVariables`

Pull Request resolved: #118003
Approved by: https://github.com/anijain2305, https://github.com/Skylion007, https://github.com/jansel
ghstack dependencies: #117982, #118098, #117983, #117625, #118194
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
This is tested by `fullgraph=True` in the `test_getattr_dict` test.
I can write a one-off test for both if that's needed.

Pull Request resolved: #118199
Approved by: https://github.com/peterbell10, https://github.com/jansel, https://github.com/anijain2305
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
…g "params" in an optimizer (#118535)

Fixes the unnecessary guards described at #117983 (comment)

Pull Request resolved: #118535
Approved by: https://github.com/mlazos
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208, #118199
pytorch-bot bot pushed a commit that referenced this pull request Feb 8, 2024
We also rename ODICT_KEYS and make it use a list rather than a string.

Split from #118630.

Pull Request resolved: #118855
Approved by: https://github.com/peterbell10
ghstack dependencies: #117982, #118098, #117983, #117625, #118194, #118003, #118208, #118199, #118535
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.

6 participants