Repository navigation
[dynamo] Fix DequeVariable maxlen=0 keeping items instead of emptying - #195029
gabrielfruet wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195029
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 a88cad0 with merge base 5b60cff ( 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. |
|
Ready to review @guilhermeleobas |
|
Thanks @gabrielfruet |
|
@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: Command Details for Dev Infra teamRaised by workflow job |
DequeVariable clamps to maxlen with items[-maxlen:], but when maxlen is 0 that slice is items[-0:], i.e. items[0:], which returns the whole list instead of an empty one. So under torch.compile a deque(maxlen=0) modeled its contents wrong: collections.deque([1, 2, 3], maxlen=0) traced as length 3, and appending or extending a maxlen=0 deque kept the new items, while CPython keeps it empty in every case. __init__ (construction) and _clamp_maxlen's right side (append and extend) both used the bare slice; appendleft/extendleft use items[:maxlen], which is already correct for 0. Both sites now special-case maxlen == 0 to items[:0]. Test Plan: ``` python test/dynamo/test_misc.py MiscTests.test_deque_maxlen_zero PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_deque.py ``` test_deque_maxlen_zero is new and fails without the fix; the cpython deque suite stays green. This change was authored with the assistance of Claude (Anthropic). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Use `maxlen != 0` instead of a bare truthiness check in __init__ and _clamp_maxlen. maxlen is a non-negative int at both sites, so 0 is the only falsy value: behavior is unchanged, and the check now reads the same as the "maxlen == 0" comment above it. Test Plan: behavior-preserving refactor; covered by test_deque_maxlen_zero from the parent commit. This change was authored with the assistance of Claude (Anthropic). Co-Authored-By: Claude Opus 4.8 <[email protected]>
6168b4e to
a88cad0
Compare
|
@guilhermeleobas I had to sort out a merge conflict. |
|
@pytorchbot merge |
Merge startedYour 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 |
…pytorch#195029) DequeVariable clamps to maxlen with items[-maxlen:], but when maxlen is 0 that slice is items[-0:], i.e. items[0:], which returns the whole list instead of an empty one. So under torch.compile a deque(maxlen=0) modeled its contents wrong: collections.deque([1, 2, 3], maxlen=0) traced as length 3, and appending or extending a maxlen=0 deque kept the new items, while CPython keeps it empty in every case. __init__ (construction) and _clamp_maxlen's right side (append and extend) both used the bare slice; appendleft/extendleft use items[:maxlen], which is already correct for 0. Both sites now special-case maxlen == 0 to items[:0]. Test Plan: ``` python test/dynamo/test_misc.py MiscTests.test_deque_maxlen_zero PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_deque.py ``` test_deque_maxlen_zero is new and fails without the fix; the cpython deque suite stays green. This change was authored with the assistance of Claude (Anthropic). Co-Authored-By: Claude Opus 4.8 <[email protected]> Pull Request resolved: pytorch#195029 Approved by: https://github.com/guilhermeleobas Co-authored-by: Claude Opus 4.8 <[email protected]>
…pytorch#195029) DequeVariable clamps to maxlen with items[-maxlen:], but when maxlen is 0 that slice is items[-0:], i.e. items[0:], which returns the whole list instead of an empty one. So under torch.compile a deque(maxlen=0) modeled its contents wrong: collections.deque([1, 2, 3], maxlen=0) traced as length 3, and appending or extending a maxlen=0 deque kept the new items, while CPython keeps it empty in every case. __init__ (construction) and _clamp_maxlen's right side (append and extend) both used the bare slice; appendleft/extendleft use items[:maxlen], which is already correct for 0. Both sites now special-case maxlen == 0 to items[:0]. Test Plan: ``` python test/dynamo/test_misc.py MiscTests.test_deque_maxlen_zero PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_deque.py ``` test_deque_maxlen_zero is new and fails without the fix; the cpython deque suite stays green. This change was authored with the assistance of Claude (Anthropic). Co-Authored-By: Claude Opus 4.8 <[email protected]> Pull Request resolved: pytorch#195029 Approved by: https://github.com/guilhermeleobas Co-authored-by: Claude Opus 4.8 <[email protected]>
DequeVariable clamps to maxlen with items[-maxlen:], but when maxlen is 0 that
slice is items[-0:], i.e. items[0:], which returns the whole list instead of an
empty one. So under torch.compile a deque(maxlen=0) modeled its contents wrong:
collections.deque([1, 2, 3], maxlen=0) traced as length 3, and appending or
extending a maxlen=0 deque kept the new items, while CPython keeps it empty in
every case. init (construction) and _clamp_maxlen's right side (append and
extend) both used the bare slice; appendleft/extendleft use items[:maxlen],
which is already correct for 0. Both sites now special-case maxlen == 0 to
items[:0].
Test Plan:
test_deque_maxlen_zero is new and fails without the fix; the cpython deque suite
stays green.
This change was authored with the assistance of Claude (Anthropic).
Co-Authored-By: Claude Opus 4.8 [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98