Repository navigation
[dynamo] Split DequeReverseIteratorVariable off DequeIteratorVariable to match CPython - #194348
indrajeetapache wants to merge 2 commits into
Conversation
… to match CPython _deque_reverse_iterator is not a subclass of _deque_iterator. Reparent DequeReverseIteratorVariable onto BaseListIteratorVariable so the two deque iterator VTs are siblings, matching CPython. The deque mutation snapshot (source_deque / saved_state) is copied onto the reverse class rather than inherited, so isinstance(..., DequeIteratorVariable) no longer matches reverse iterators. Call sites list both types explicitly: GET_YIELD_FROM_ITER and _unpack_fast_types. Part of pytorch#192874 Test plan: - python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_not_a_deque_iterator - python test/dynamo/test_iterators.py TestIterators.test_yield_from_deque_reverse_iterator - python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_python_type - python test/dynamo/test_iterators.py - python test/dynamo/test_sequence_ops.py -k deque_reverse Authored with an AI assistant.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194348
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 7bec86f with merge base 0fa7965 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
guilhermeleobas
left a comment
There was a problem hiding this comment.
LGTM. Can you fix the lintrunner issue?
|
@pytorchbot lint |
|
@pytorchbot fix-lint |
|
@indrajeetapache can you fix the lint issue? |
lintrunner PYFMT failed because two added lines exceeded the 88-char limit: the issubclass assertion in the new deque reverse-iterator test, and the GET_YIELD_FROM_ITER iter_vts tuple. Wrap them to match black. Test Plan: - black --line-length 88 --check on the two files (passes) Authored with an AI assistant; human-reviewed before submit.
|
@guilhermeleobas fixed — thanks for the ping. |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.2-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
… CPython (#194348) Summary: ## Summary In CPython, `_deque_reverse_iterator` is not a subclass of `_deque_iterator`: ``` >>> from collections import deque >>> issubclass(type(reversed(deque())), type(iter(deque()))) False ``` `dir()` on both is the same (`__iter__`, `__next__`, `__length_hint__`). Dynamo still had `DequeReverseIteratorVariable(DequeIteratorVariable)`, so every `isinstance(x, DequeIteratorVariable)` check also matched reverse deque iterators. This follows the same shape as #193261 (deque forward) and #193717 (tuple): reparent onto the existing `BaseListIteratorVariable` so the two deque iterator VTs are siblings. No new base class. The deque mutation snapshot (`source_deque` / `saved_state`) cannot be inherited from `DequeIteratorVariable` after the split, or reverse iterators would still type-check as deque iterators. It is copied onto `DequeReverseIteratorVariable` so `reversed(d)` still raises `RuntimeError: deque mutated during iteration`. ### Files touched | File | What changed | | --- | --- | | `torch/_dynamo/variables/lists.py` | `DequeReverseIteratorVariable` now subclasses `BaseListIteratorVariable`. Mutation snapshot copied so reverse iterators stay siblings. | | `torch/_dynamo/symbolic_convert.py` | `GET_YIELD_FROM_ITER` lists `DequeReverseIteratorVariable` explicitly (same pattern as list/tuple/deque after #193717). | | `torch/_dynamo/utils.py` | `_unpack_fast_types` adds `DequeReverseIteratorVariable` so reverse deque unpack keeps the fast path. | | `torch/_dynamo/variables/__init__.py` | Import `DequeReverseIteratorVariable` (not exported in `__all__`, same as `DequeIteratorVariable`). | | `test/dynamo/test_iterators.py` | Hierarchy, `yield from reversed(deque)`, and `type(reversed(deque))` regression tests. | Not touched: `side_effects.py`. Deque iterators are built sourceless with `ValueMutationNew` and never hit the list/tuple iterator replay handler (#193261). Reverse is the same. Part of #192874 ## Test plan ``` python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_not_a_deque_iterator python test/dynamo/test_iterators.py TestIterators.test_yield_from_deque_reverse_iterator python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_python_type python test/dynamo/test_iterators.py python test/dynamo/test_sequence_ops.py -k deque_reverse ``` X-link: pytorch/pytorch#194348 Approved by: https://github.com/guilhermeleobas, https://github.com/hameerabbasi Reviewed By: huydhn Differential Revision: D118488968 fbshipit-source-id: 9e6eaa7b62840a79cf2951c5b91d4cfc65007064
… to match CPython (pytorch#194348) ## Summary In CPython, `_deque_reverse_iterator` is not a subclass of `_deque_iterator`: ``` >>> from collections import deque >>> issubclass(type(reversed(deque())), type(iter(deque()))) False ``` `dir()` on both is the same (`__iter__`, `__next__`, `__length_hint__`). Dynamo still had `DequeReverseIteratorVariable(DequeIteratorVariable)`, so every `isinstance(x, DequeIteratorVariable)` check also matched reverse deque iterators. This follows the same shape as pytorch#193261 (deque forward) and pytorch#193717 (tuple): reparent onto the existing `BaseListIteratorVariable` so the two deque iterator VTs are siblings. No new base class. The deque mutation snapshot (`source_deque` / `saved_state`) cannot be inherited from `DequeIteratorVariable` after the split, or reverse iterators would still type-check as deque iterators. It is copied onto `DequeReverseIteratorVariable` so `reversed(d)` still raises `RuntimeError: deque mutated during iteration`. ### Files touched | File | What changed | | --- | --- | | `torch/_dynamo/variables/lists.py` | `DequeReverseIteratorVariable` now subclasses `BaseListIteratorVariable`. Mutation snapshot copied so reverse iterators stay siblings. | | `torch/_dynamo/symbolic_convert.py` | `GET_YIELD_FROM_ITER` lists `DequeReverseIteratorVariable` explicitly (same pattern as list/tuple/deque after pytorch#193717). | | `torch/_dynamo/utils.py` | `_unpack_fast_types` adds `DequeReverseIteratorVariable` so reverse deque unpack keeps the fast path. | | `torch/_dynamo/variables/__init__.py` | Import `DequeReverseIteratorVariable` (not exported in `__all__`, same as `DequeIteratorVariable`). | | `test/dynamo/test_iterators.py` | Hierarchy, `yield from reversed(deque)`, and `type(reversed(deque))` regression tests. | Not touched: `side_effects.py`. Deque iterators are built sourceless with `ValueMutationNew` and never hit the list/tuple iterator replay handler (pytorch#193261). Reverse is the same. Part of pytorch#192874 ## Test plan ``` python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_not_a_deque_iterator python test/dynamo/test_iterators.py TestIterators.test_yield_from_deque_reverse_iterator python test/dynamo/test_iterators.py TestIterators.test_deque_reverse_iterator_python_type python test/dynamo/test_iterators.py python test/dynamo/test_sequence_ops.py -k deque_reverse ``` Pull Request resolved: pytorch#194348 Approved by: https://github.com/guilhermeleobas, https://github.com/hameerabbasi
Summary
In CPython,
_deque_reverse_iteratoris not a subclass of_deque_iterator:dir()on both is the same (__iter__,__next__,__length_hint__). Dynamo still hadDequeReverseIteratorVariable(DequeIteratorVariable), so everyisinstance(x, DequeIteratorVariable)check also matched reverse deque iterators.This follows the same shape as #193261 (deque forward) and #193717 (tuple): reparent onto the existing
BaseListIteratorVariableso the two deque iterator VTs are siblings. No new base class.The deque mutation snapshot (
source_deque/saved_state) cannot be inherited fromDequeIteratorVariableafter the split, or reverse iterators would still type-check as deque iterators. It is copied ontoDequeReverseIteratorVariablesoreversed(d)still raisesRuntimeError: deque mutated during iteration.Files touched
torch/_dynamo/variables/lists.pyDequeReverseIteratorVariablenow subclassesBaseListIteratorVariable. Mutation snapshot copied so reverse iterators stay siblings.torch/_dynamo/symbolic_convert.pyGET_YIELD_FROM_ITERlistsDequeReverseIteratorVariableexplicitly (same pattern as list/tuple/deque after #193717).torch/_dynamo/utils.py_unpack_fast_typesaddsDequeReverseIteratorVariableso reverse deque unpack keeps the fast path.torch/_dynamo/variables/__init__.pyDequeReverseIteratorVariable(not exported in__all__, same asDequeIteratorVariable).test/dynamo/test_iterators.pyyield from reversed(deque), andtype(reversed(deque))regression tests.Not touched:
side_effects.py. Deque iterators are built sourceless withValueMutationNewand never hit the list/tuple iterator replay handler (#193261). Reverse is the same.Part of #192874
Test plan
cc @guilhermeleobas @williamwen42 @jansel @Skylion007 @albanD @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98