Yuanyuan Chen
fc8ac1216c
[4/N] Remove unused loop variables in tests ( #166690 )
...
This PR removes unused loop variables in tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/166690
Approved by: https://github.com/justinchuby , https://github.com/mlazos
2025-10-31 10:20:48 +00:00
Rob Timpe
8101fd46d4
[dynamo] Implement iter with a polyfill ( #162768 )
...
Currently most variable trackers implement `iter` via `_call_iter_tuple_list`.
This makes it difficult to customize the behavior of `iter` for different
variable types. Instead, implement `iter` via a polyfill, which will delegate
to the appropriate `__iter__` method.
While this method is more flexible, it increases the overhead of dynamo tracing.
For example, `iter(x)` will generate 9x more instructions than the current
implementation for common iterable types. Microbenchmarking shows a ~6x
slowdown for this operation. I suspect this would be much less for realistic
workloads, but more work would be needed to get specific numbers. If the
performance is a concern we could also consider adding a fast path for types
that are known to correctly implement `__iter__`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162768
Approved by: https://github.com/guilhermeleobas
ghstack dependencies: #166349
2025-10-29 21:54:37 +00:00
Rob Timpe
3d4a2d8a93
[dynamo] Add __iter__ for iterable VariableTrackers ( #166349 )
...
This is in preparation for implementing iter with a polyfill
Pull Request resolved: https://github.com/pytorch/pytorch/pull/166349
Approved by: https://github.com/guilhermeleobas
2025-10-29 21:54:37 +00:00
Animesh Jain
262830d86c
[dynamo] Repro for 166238 ( #166252 )
...
xfail repro for https://github.com/pytorch/pytorch/issues/166238
Pull Request resolved: https://github.com/pytorch/pytorch/pull/166252
Approved by: https://github.com/XuehaiPan , https://github.com/jansel
2025-10-26 18:34:22 +00:00
Tugsbayasgalan Manlaibaatar
2395d7d7da
Relax equality check ( #165460 )
...
When an object is inherited from multiple types, the previous check would fail. So we should relax it to respect eager semantic
Differential Revision: [D84635322](https://our.internmc.facebook.com/intern/diff/D84635322 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/165460
Approved by: https://github.com/avikchaudhuri
2025-10-15 18:32:01 +00:00
Animesh Jain
68fa882dad
[dynamo] Correctly track mutation class source for MutableMappingVariable ( #161568 )
...
Fixes https://github.com/pytorch/pytorch/issues/161505
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161568
Approved by: https://github.com/Lucaskabela , https://github.com/malfet
2025-08-27 21:47:17 +00:00
Guilherme Leobas
379ebdaf5e
[OrderedDict] Implement OrderedDict.popitem(last=...) ( #155153 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155153
Approved by: https://github.com/anijain2305
ghstack dependencies: #160156 , #155072 , #155152
2025-08-27 15:46:40 +00:00
Guilherme Leobas
7c8f049d54
[OrderedDict] Implement OrderedDict.move_to_end(key, last=False) ( #155152 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155152
Approved by: https://github.com/anijain2305
ghstack dependencies: #160156 , #155072
2025-08-27 15:46:40 +00:00
Guilherme Leobas
e3718c4855
[dict] Implement dict.__ior__ and fix return type in dict.__or__ ( #155072 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155072
Approved by: https://github.com/anijain2305
ghstack dependencies: #160156
2025-08-27 15:46:40 +00:00
Animesh Jain
3d406429b0
[dynamo][vllm] Support typing.get_type_hints ( #161362 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161362
Approved by: https://github.com/Skylion007 , https://github.com/StrongerXi , https://github.com/jansel
2025-08-27 09:55:31 +00:00
Guilherme Leobas
bfcababbcb
[OrderedDict] Implement explicit OrderedDict dunder method call ( #154943 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154943
Approved by: https://github.com/zou3519
ghstack dependencies: #154003 , #154793 , #154794 , #154942
2025-07-10 22:50:39 +00:00
Guilherme Leobas
ba71eb496b
[dict] Implement dict.__eq__ and dict.__ne__ ( #154942 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154942
Approved by: https://github.com/zou3519
ghstack dependencies: #154003 , #154793 , #154794
2025-07-10 22:50:39 +00:00
Guilherme Leobas
ba8d19ec02
[dict] Allow Dynamo to trace through explicit dict dunder method call ( #154794 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154794
Approved by: https://github.com/mlazos
ghstack dependencies: #154003 , #154793
2025-07-10 22:50:39 +00:00
Guilherme Leobas
57d64298a0
[dict] Add dict.popitem ( #154793 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154793
Approved by: https://github.com/mlazos , https://github.com/zou3519
ghstack dependencies: #154003
2025-07-10 22:50:39 +00:00
Guilherme Leobas
e84710d1e7
[dict] Raise TypeError in dict methods ( #154003 )
...
Raise TypeError in the following scenarios:
* #args mismatch
* arg is unhashable
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154003
Approved by: https://github.com/mlazos , https://github.com/zou3519
2025-07-10 22:50:39 +00:00
Xuehai Pan
02715d0876
[BE][5/6] fix typos in test/ (test/dynamo/) ( #157639 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/157639
Approved by: https://github.com/yewentao256 , https://github.com/jansel
ghstack dependencies: #157638
2025-07-06 06:34:25 +00:00
Guilherme Leobas
11c71053e0
[Dynamo] [Set] Implement some binop operators for dict/set/frozenset/dict_keys ( #154063 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154063
Approved by: https://github.com/williamwen42 , https://github.com/zou3519
ghstack dependencies: #153150 , #152991 , #154539 , #153553
2025-07-04 00:45:34 +00:00
Guilherme Leobas
f651e28f80
[FrozenSet] Fixes for FrozenSet ( #152991 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/152991
Approved by: https://github.com/zou3519
ghstack dependencies: #153150
2025-07-04 00:45:11 +00:00
Animesh Jain
48560eef80
[dynamo] Fix bug in dict(mapping_proxy) ( #157467 )
...
Fixes https://github.com/pytorch/pytorch/issues/157284
Pull Request resolved: https://github.com/pytorch/pytorch/pull/157467
Approved by: https://github.com/jansel , https://github.com/StrongerXi
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
2025-07-02 22:13:02 +00:00
Animesh Jain
a9d5157e25
[dynamo] Use BINARY_SUBSCR for pre-graph bytecode for regular dict accesses ( #155727 )
...
vLLM profiler sets with_stack=True that shows the dict_getitem on the profiler, both inflating the numbers and confusing compile users. This PR keeps BINARY_SUBSCR for regular dicts, while using `dict.__getitem__` only for dict subclasses.
Using binary_subscr is little bit faster, but not enough to make any major latency improvements.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155727
Approved by: https://github.com/zou3519 , https://github.com/StrongerXi , https://github.com/jansel
2025-06-12 04:02:29 +00:00
Ryan Guo
6f7694f18f
[dynamo] Reconstruct defaultdict properly ( #154931 )
...
`DefaultDictVariable` inherited `ConstDictVariable.reconstruct`, causing
dynamo to reconstruct a `DefaultDictVariable` into a dict rather than
defaultdict. This patch fixes that.
Fixes #138412 .
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154931
Approved by: https://github.com/williamwen42 , https://github.com/zou3519
ghstack dependencies: #154930
2025-06-03 18:18:40 +00:00
Aaron Gokaslan
3555ebb63d
[BE]: Update ruff to 0.11.8 ( #153249 )
...
Fixes a ton of false negatives throughout the codebase. RUFF also properly validates NOQA comments now and most of the changes are fixing typos there or removing filewide flake8 suppressions that were also silencing ruff issues.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/153249
Approved by: https://github.com/cyyever , https://github.com/albanD , https://github.com/seemethere
2025-05-12 18:30:52 +00:00
Yuanhao Ji
85ada5d6dd
[Dynamo] Allow dynamo to handle 'or' operator between two dicts ( #147305 )
...
Fixes #146538
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147305
Approved by: https://github.com/anijain2305
2025-04-11 04:47:31 +00:00
Yuanhao Ji
98d06b401b
[Dynamo] Fix dict.items() return type ( #150112 )
...
Fixes #150110
Pull Request resolved: https://github.com/pytorch/pytorch/pull/150112
Approved by: https://github.com/jansel , https://github.com/zou3519
2025-04-04 04:32:13 +00:00
Animesh Jain
9dc702875d
[dynamo][mappingproxy][inspect] Support existing types.MappingProxyType ( #147217 )
...
Fixes https://github.com/pytorch/pytorch/issues/147162
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147217
Approved by: https://github.com/williamwen42
2025-02-15 07:59:33 +00:00
Animesh Jain
d6513f3246
[dynamo] Support list subclasses and fix dict subclasses mutation bugs ( #146819 )
...
This PR adds support for list subclasses. Among other things are
1) Tracking the mutations on internal vts like `_dict_vt` and `_list_vt` using sources. This helps identify if there was a mutation in the underlying data structures, and we need to reconstruct it.
2) `UserDefinedObjectVariable` now has a new method - `is_modified` which `side_effect` infra relies upon to check mutations in the underlying vts (like `_dict_vt`).
3) `reconstruction` logic ensures that we use `dict.__getitem__` and `list.__getitem__` methods. This is super important because we don't want to call the overridden `__getitem__` methods.
If this PR is hard to review, please let me know. I can break it into several small PRs.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146819
Approved by: https://github.com/StrongerXi , https://github.com/jansel
2025-02-12 17:46:02 +00:00
Animesh Jain
ee8a06f1f6
[dynamo][user-defined] User class.__new__ instead of special casing ( #146677 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146677
Approved by: https://github.com/jansel
2025-02-10 17:31:13 +00:00
Animesh Jain
487400f47f
[dynamo] Support functools.partial variables through inspect.signature ( #146339 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146339
Approved by: https://github.com/jansel
ghstack dependencies: #146322 , #146116
2025-02-04 04:39:39 +00:00
Animesh Jain
e7bb608d02
[dynamo][dicts] Support construction of types.MappingProxyType ( #145994 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145994
Approved by: https://github.com/StrongerXi , https://github.com/jansel
ghstack dependencies: #145986 , #145987
2025-01-31 00:47:31 +00:00
Animesh Jain
4665bc2cc0
[dynamo][functions] Support id on function ( #145987 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145987
Approved by: https://github.com/StrongerXi , https://github.com/jansel , https://github.com/mlazos
ghstack dependencies: #145986
2025-01-31 00:47:23 +00:00
Animesh Jain
5c5306e8bc
[dynamo][builtin-skiplist-cleanup] Remove weakref ( #145744 )
...
WeakKeyDictionary already works very nicely with the UserDefinedObject Variable Tracker.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145744
Approved by: https://github.com/jansel
2025-01-28 07:55:12 +00:00
Animesh Jain
993b229665
[dynamo][dicts] Fix dict.__new__ bug ( #145723 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145723
Approved by: https://github.com/jansel , https://github.com/StrongerXi
ghstack dependencies: #145519 , #145547 , #145558
2025-01-27 21:42:43 +00:00
Animesh Jain
c58198184b
[dynamo][dicts] Insert LENTGH guard on an if condition on dict ( #145432 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145432
Approved by: https://github.com/williamwen42 , https://github.com/jansel
2025-01-23 04:40:56 +00:00
Ryan Guo
4ceca4d60f
[dynamo] Avoid graph break on updates to obj.__dict__ ( #144419 )
...
`obj.__dict__` is handled specially in Dynamo, and prior to this patch
we only support read and membership check on that dictionary object.
This patch adds support for writes and some documentation.
Fixes #143756 .
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144419
Approved by: https://github.com/jansel , https://github.com/anijain2305
2025-01-13 21:04:10 +00:00
PyTorch MergeBot
473b745cb9
Revert "[dynamo] Avoid graph break on updates to obj.__dict__ ( #144419 )"
...
This reverts commit c8595ba7d0 .
Reverted https://github.com/pytorch/pytorch/pull/144419 on behalf of https://github.com/clee2000 due to newly added test fails internally D68004708 ([comment](https://github.com/pytorch/pytorch/pull/144419#issuecomment-2583265412 ))
2025-01-10 16:59:38 +00:00
Ryan Guo
c8595ba7d0
[dynamo] Avoid graph break on updates to obj.__dict__ ( #144419 )
...
`obj.__dict__` is handled specially in Dynamo, and prior to this patch
we only support read and membership check on that dictionary object.
This patch adds support for writes and some documentation.
Fixes #143756 .
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144419
Approved by: https://github.com/jansel , https://github.com/anijain2305
2025-01-10 05:22:04 +00:00
Animesh Jain
8ccf3f6f3f
[dynamo][easy] Move dict tests to test_dicts.py ( #144165 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144165
Approved by: https://github.com/jansel
ghstack dependencies: #143997
2025-01-08 03:56:33 +00:00
Animesh Jain
2ac41404a8
[dynamo][dicts] Guarding lazily on dict keys ( #143997 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143997
Approved by: https://github.com/jansel
2025-01-08 03:56:33 +00:00
PyTorch MergeBot
b01556bd8a
Revert "[dynamo][dicts] Guarding lazily on dict keys ( #143997 )"
...
This reverts commit f5df082fab .
Reverted https://github.com/pytorch/pytorch/pull/143997 on behalf of https://github.com/jeanschmidt due to Seems to have introduced internal ci redness in some tests, D67828366 ([comment](https://github.com/pytorch/pytorch/pull/143997#issuecomment-2571587599 ))
2025-01-05 11:09:45 +00:00
Animesh Jain
f5df082fab
[dynamo][dicts] Guarding lazily on dict keys ( #143997 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143997
Approved by: https://github.com/jansel
ghstack dependencies: #144129 , #144130 , #144141 , #144158 , #144163 , #144160
2025-01-04 18:13:00 +00:00
Animesh Jain
c5c897c3a1
[dynamo][easy] Miscellaneous fixes ( #144141 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144141
Approved by: https://github.com/williamwen42
ghstack dependencies: #144129 , #144130
2025-01-03 18:22:56 +00:00
Animesh Jain
e296bab614
[dynamo] Remove DICT_SUBCLASS_GUARD_MANAGER and use dict.keys ( #143722 )
...
In hinsight, we never needed a DICT_SUBCLASS_GUARD_MANAGER, because Dynamo would inline through the overridden keys method. In this PR, we ensure that while creating guards and constructing variable trackers, we get the `d.keys()` value by using `dict.keys(d)`. This ensures that we do not call overridden keys method. Therefore, the C++ guard can use `PyDict_Next` directly to check the guards.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143722
Approved by: https://github.com/jansel
2024-12-27 04:51:35 +00:00
PyTorch MergeBot
26364428f5
Revert "[dynamo] Remove DICT_SUBCLASS_GUARD_MANAGER and use dict.keys ( #143722 )"
...
This reverts commit fe95cbe018 .
Reverted https://github.com/pytorch/pytorch/pull/143722 on behalf of https://github.com/wdvr due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/143722#issuecomment-2563127017 ))
2024-12-26 22:04:36 +00:00
Animesh Jain
fe95cbe018
[dynamo] Remove DICT_SUBCLASS_GUARD_MANAGER and use dict.keys ( #143722 )
...
In hinsight, we never needed a DICT_SUBCLASS_GUARD_MANAGER, because Dynamo would inline through the overridden keys method. In this PR, we ensure that while creating guards and constructing variable trackers, we get the `d.keys()` value by using `dict.keys(d)`. This ensures that we do not call overridden keys method. Therefore, the C++ guard can use `PyDict_Next` directly to check the guards.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143722
Approved by: https://github.com/jansel
2024-12-24 02:00:18 +00:00
Animesh Jain
4627cfd1f9
[dynamo] Support user defined dicts ( #143548 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143548
Approved by: https://github.com/yanboliang , https://github.com/jansel , https://github.com/williamwen42
2024-12-21 01:46:14 +00:00