PyTorch MergeBot
c1fe6be202
Revert "[dynamo] add SymNode bitwise and/or ( #138777 )"
...
This reverts commit c98ef0279e .
Reverted https://github.com/pytorch/pytorch/pull/138777 on behalf of https://github.com/ezyang due to triggering AssertionError: Guard check failed: 14/2: name 'BitwiseFn_bitwise_or' is not defined ([comment](https://github.com/pytorch/pytorch/pull/138777#issuecomment-2477477776 ))
2024-11-14 21:52:40 +00:00
William Wen
c98ef0279e
[dynamo] add SymNode bitwise and/or ( #138777 )
...
Fixes [T203472723](https://www.internalfb.com/intern/tasks/?t=203472723 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/138777
Approved by: https://github.com/ezyang
2024-11-13 18:31:06 +00:00
Yuanhao Ji
5aadaaf2b5
[Dynamo] Allow filter() to handle infinite iterator ( #138305 )
...
Fixes #137380
```python
import torch
def filt(x):
return x < 10
@torch.compile(backend="eager", fullgraph=True)
def f(x):
x = x + 1
return zip(range(3), filter(filt, itertools.count()))
print(list(f(torch.ones(3)))) # [(0, 0), (1, 1), (2, 2)]
@torch.compile(backend="eager")
def g(x):
x = x + 1
return filter(filt, [1, 2, 3])
res = g(torch.ones(3))
assert isinstance(res, filter)
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/138305
Approved by: https://github.com/williamwen42
2024-11-12 17:32:56 +00:00
Michael Lazos
d622b490d6
[Dynamo] Support tensor mro without source ( #139838 )
...
Fixes https://github.com/pytorch/pytorch/issues/137743
The issue here is that if `type` was called on a tensor without a source, we wouldn't have a source even for `torch.Tensor`, and the `__mro__` retrieval would fail. Since `torch.Tensor` is an internal torch type, I add handling for it in `call_type` in builtins.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139838
Approved by: https://github.com/williamwen42
2024-11-06 08:52:53 +00:00
Ryan Guo
2b3a227b35
[dynamo] Add is_mutable() and is_immutable() methods to VariableTracker ( #139341 )
...
This patch adds 2 simple methods `VariableTracker.is_mutable()` and
`VariableTracker.is_immutable()`, which helps clarify intention. For
instance, rather than writing
```python
if var.mutation_type:
...
```
After this patch one can write
```python
if var.is_mutable():
...
```
This patch also simplifies `mutation_type` propagation in some
`ListVariable` methods.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139341
Approved by: https://github.com/mlazos , https://github.com/anijain2305
ghstack dependencies: #139339 , #139340
2024-11-05 19:11:41 +00:00
Ryan Guo
693a0a1bd4
[dynamo][NFC] Rename mutable_local and add documentation ( #139339 )
...
This patch addresses the renaming part of #133027 , specifically, it
renames the following and adds documentation for relevant classes.
1. `VariableTracker.mutable_local` to `mutation_type`
2. `MatableLocal `to `ValueMutationNew`
3. `MutableSideEffects `to `ValueMutationExisting`
4. `MutableLocalSource` to `SourceType`
5. `MutableLocalSource.Local` to `New`
Note that (2), (3) and (5) are mainly to bring consistency between them
and `AttributeMutationNew`, `AttributeMutationExisting`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139339
Approved by: https://github.com/jansel , https://github.com/mlazos , https://github.com/anijain2305
2024-11-05 19:11:41 +00:00
PyTorch MergeBot
b6b9596607
Revert "[dynamo] Fix constant propagation in builtins and UserClasses ( #131354 )"
...
This reverts commit 44257c063e .
Reverted https://github.com/pytorch/pytorch/pull/131354 on behalf of https://github.com/huydhn due to Sorry for reverting your change, but it seems to break some internal tests ([comment](https://github.com/pytorch/pytorch/pull/131354#issuecomment-2451050605 ))
2024-11-01 00:13:20 +00:00
Tom Ritchford
44257c063e
[dynamo] Fix constant propagation in builtins and UserClasses ( #131354 )
...
* Fixes https://github.com/pytorch/pytorch/issues/118675
* Replaces https://github.com/pytorch/pytorch/pull/118994
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131354
Approved by: https://github.com/jansel , https://github.com/anijain2305
2024-10-30 12:47:20 +00:00
Tom Ritchford
8ad191ae21
[dynamo] Replace __str__ with __repr__ in some places ( #136316 )
...
## The problem
In a typical debugger, `repr()` is used to display variables and not `str()`.
Several classes in Dynamo have a `__str__()` method that returns useful information and a `__repr__()` that does not. Having to call `str(x)` or `[str(i) for i in x]` in the debugger all the time is a chore.
`str()` should be ["informal, nicely printable"](https://docs.python.org/3/library/stdtypes.html#str ) and `repr()` should ["attempt to return a string that would yield an object with the same value when passed to eval()](https://docs.python.org/3/library/functions.html#repr )".
## The solution
In the Python object model, if there is no `__str__` method, `__repr__` is used instead (but not the other way around).
So renaming `__str__` to `__repr__` in a few cases where no `__repr__` method exists now should not change observable behavior, and should make debugging easier.
The specific classes changed were all in `torch._dynamo.variables`:
* `builtin.BuiltinVariable`
* `constant.ConstantVariable`
* `constant.EnumVariable`
* `functions.UserMethodVariable`
* `lazy.LazyVariableTracker`
* `lazy.LazySymNodeFormatString`
* `misc.GetAttrVariable`
* `misc.NullVariable`
* `user_defined.UserDefinedObjectVariable`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136316
Approved by: https://github.com/XuehaiPan , https://github.com/jansel
2024-10-21 19:50:38 +00:00
Tom Ritchford
e1c4548441
[dynamo] Simplify creation of VariableTrackers ( #135714 )
...
## `VariableTracker::build()` hides the Builders
### The problem
In the current code, creating a `VariableTracker` involves choosing one of two `Builder` classes and either calling a method, or calling a constructor that creates an object that you immediately call, [like this](083c9149b7/torch/_dynamo/variables/functions.py (L761-L768) ).
Variations on this code are repeated in many places.
More, the `Builder` classes have a lot of dependencies, so they have to be loaded late in the whole import process to avoid circular imports, so they end up being repeatedly imported at local scope.
### The solution
In this commit, the import from `builder` and the logic of choosing and calling the Builder class are hidden in a single static factory method, `VariableTracker.build()`, easier to reason about and to import.
This commit net lowers the total lines of code by over 150 lines by removing repetitive logic and unnecessary local imports.
**CHANGES:** Originally the name of the static method was `VariableTracker.create()` but a static method on a derived class, `LazyVariableTracker.create()` now exists with a different signature that's irreconcilable, so the new static method was renamed to `VariableTracker.build()`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/135714
Approved by: https://github.com/jansel
2024-10-18 09:36:46 +00:00
Michael Lazos
27dee935af
[Dynamo] Ensure torch function modes are dispatched on builtin ops ( #137117 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/137117
Approved by: https://github.com/yanboliang , https://github.com/williamwen42
ghstack dependencies: #137114 , #137115 , #137116
2024-10-09 02:29:40 +00:00
PyTorch MergeBot
2d18c2d5e7
Revert "[Dynamo] Ensure torch function modes are dispatched on builtin ops ( #137117 )"
...
This reverts commit 941be418d8 .
Reverted https://github.com/pytorch/pytorch/pull/137117 on behalf of https://github.com/huydhn due to The top of the stack has been reverted but it leaves trunk in a broken state, so I try to revert the rest of the stack ([comment](https://github.com/pytorch/pytorch/pull/137114#issuecomment-2400765603 ))
2024-10-08 20:33:17 +00:00
Michael Lazos
941be418d8
[Dynamo] Ensure torch function modes are dispatched on builtin ops ( #137117 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/137117
Approved by: https://github.com/yanboliang , https://github.com/williamwen42
ghstack dependencies: #137114 , #137115 , #137116
2024-10-07 18:55:26 +00:00
PyTorch MergeBot
9223c16208
Revert "Fix constant propagation in builtins and UserClasses ( #131354 )"
...
This reverts commit dd4a51b39a .
Reverted https://github.com/pytorch/pytorch/pull/131354 on behalf of https://github.com/atalman due to Breaks torchrec tests ([comment](https://github.com/pytorch/pytorch/pull/131354#issuecomment-2375417145 ))
2024-09-25 23:01:03 +00:00
Tom Ritchford
dd4a51b39a
Fix constant propagation in builtins and UserClasses ( #131354 )
...
* Fixes https://github.com/pytorch/pytorch/issues/118675
* Replaces https://github.com/pytorch/pytorch/pull/118994
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131354
Approved by: https://github.com/jansel , https://github.com/anijain2305
2024-09-25 13:03:40 +00:00
Xuehai Pan
951c21d679
[dynamo] simplify implementation for builtins.sum ( #133779 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133779
Approved by: https://github.com/jansel , https://github.com/anijain2305
ghstack dependencies: #133778
2024-09-16 04:53:06 +00:00
Xuehai Pan
9961aaa601
[dynamo] simplify implementation for functools.reduce ( #133778 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133778
Approved by: https://github.com/jansel , https://github.com/anijain2305
2024-09-16 04:53:06 +00:00
William Wen
a4030e37be
[dynamo] reland map/zip iterator related changes ( #135074 )
...
Differential Revision: [D62211019](https://our.internmc.facebook.com/intern/diff/D62211019 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/135074
Approved by: https://github.com/jansel , https://github.com/anijain2305 , https://github.com/mlazos
2024-09-06 20:38:02 +00:00
Tom Ritchford
2c99f17a32
Implement VariableTracker.python_type() ( #134215 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134215
Approved by: https://github.com/amjames , https://github.com/jansel
2024-09-05 16:35:47 +00:00
Xinyu
58f2477a26
[Dynamo] Support builtin function frozenset ( #134563 )
...
Support builtin function frozenset in dynamo
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134563
Approved by: https://github.com/anijain2305 , https://github.com/EikanWang , https://github.com/jansel
2024-09-05 12:15:10 +00:00
Xuehai Pan
eed0d76682
[dynamo][itertools] refactor itertools.islice to use polyfill ( #133876 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133876
Approved by: https://github.com/jansel
ghstack dependencies: #133864 , #133894
2024-08-31 10:08:07 +00:00
Xuehai Pan
ec660c383e
[dynamo] reduce overhead for PolyfilledFunctionVariable.call_function ( #134842 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134842
Approved by: https://github.com/jansel
2024-08-31 09:12:46 +00:00
Xuehai Pan
a854c3a25e
[dynamo] refactor builtins.enumerate to use polyfill ( #133894 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133894
Approved by: https://github.com/jansel
ghstack dependencies: #133864
2024-08-31 00:17:27 +00:00
Xuehai Pan
ebbdeeede1
[dynamo][itertools] refactor itertools.chain and itertools.chain.from_iterable to use polyfills ( #133864 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133864
Approved by: https://github.com/jansel
2024-08-31 00:11:54 +00:00
PyTorch MergeBot
c6ecf57dd2
Revert "[dynamo] simplify implementation for functools.reduce ( #133778 )"
...
This reverts commit b5f1ffa7ab .
Reverted https://github.com/pytorch/pytorch/pull/133778 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968 ))
2024-08-30 16:06:10 +00:00
PyTorch MergeBot
7a85c488a8
Revert "[dynamo] simplify implementation for builtins.sum ( #133779 )"
...
This reverts commit eaa449fbf0 .
Reverted https://github.com/pytorch/pytorch/pull/133779 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968 ))
2024-08-30 16:06:10 +00:00
PyTorch MergeBot
1ad08c7a5b
Revert "[dynamo][itertools] refactor itertools.chain and itertools.chain.from_iterable to use polyfills ( #133864 )"
...
This reverts commit 1b70366957 .
Reverted https://github.com/pytorch/pytorch/pull/133864 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968 ))
2024-08-30 16:06:10 +00:00
PyTorch MergeBot
8aa44e14cf
Revert "[dynamo] refactor builtins.enumerate to use polyfill ( #133894 )"
...
This reverts commit a2566adfb6 .
Reverted https://github.com/pytorch/pytorch/pull/133894 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968 ))
2024-08-30 16:06:09 +00:00
PyTorch MergeBot
10c31e96df
Revert "[dynamo][itertools] refactor itertools.islice to use polyfill ( #133876 )"
...
This reverts commit 7d12e6dceb .
Reverted https://github.com/pytorch/pytorch/pull/133876 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968 ))
2024-08-30 16:06:09 +00:00
Xuehai Pan
7d12e6dceb
[dynamo][itertools] refactor itertools.islice to use polyfill ( #133876 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133876
Approved by: https://github.com/jansel
ghstack dependencies: #133769 , #133778 , #133779 , #133864 , #133894
2024-08-29 20:56:16 +00:00
Xuehai Pan
a2566adfb6
[dynamo] refactor builtins.enumerate to use polyfill ( #133894 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133894
Approved by: https://github.com/jansel
ghstack dependencies: #133769 , #133778 , #133779 , #133864
2024-08-29 20:56:16 +00:00
Xuehai Pan
1b70366957
[dynamo][itertools] refactor itertools.chain and itertools.chain.from_iterable to use polyfills ( #133864 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133864
Approved by: https://github.com/jansel
ghstack dependencies: #133769 , #133778 , #133779
2024-08-29 20:56:16 +00:00
Xuehai Pan
eaa449fbf0
[dynamo] simplify implementation for builtins.sum ( #133779 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133779
Approved by: https://github.com/jansel , https://github.com/anijain2305
ghstack dependencies: #133769 , #133778
2024-08-29 20:56:16 +00:00
Xuehai Pan
b5f1ffa7ab
[dynamo] simplify implementation for functools.reduce ( #133778 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133778
Approved by: https://github.com/jansel , https://github.com/anijain2305
ghstack dependencies: #133769
2024-08-29 20:56:16 +00:00
Xuehai Pan
e09324e7da
[dynamo] simplify polyfill registration for builtins.all and builtins.any ( #133769 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133769
Approved by: https://github.com/jansel
2024-08-29 20:56:16 +00:00
PyTorch MergeBot
4811dc3de9
Revert "[dynamo] simplify polyfill registration for builtins.all and builtins.any ( #133769 )"
...
This reverts commit cc3a76edba .
Reverted https://github.com/pytorch/pytorch/pull/133769 on behalf of https://github.com/ZainRizvi due to Sorry but this has been discovered to be causing a performance regression internally ([comment](https://github.com/pytorch/pytorch/pull/133769#issuecomment-2316620213 ))
2024-08-29 03:00:47 +00:00
PyTorch MergeBot
50e90d7203
Revert "[dynamo] simplify implementation for functools.reduce ( #133778 )"
...
This reverts commit 6c0b15e382 .
Reverted https://github.com/pytorch/pytorch/pull/133778 on behalf of https://github.com/ZainRizvi due to Sorry, but this breaks internal tests because of using functools ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2310445169 ))
2024-08-26 15:16:17 +00:00
PyTorch MergeBot
472c7cf962
Revert "[dynamo] simplify implementation for builtins.sum ( #133779 )"
...
This reverts commit 8d90392fb0 .
Reverted https://github.com/pytorch/pytorch/pull/133779 on behalf of https://github.com/ZainRizvi due to Sorry, but this breaks internal tests because of using functools ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2310445169 ))
2024-08-26 15:16:17 +00:00
Xuehai Pan
8d90392fb0
[dynamo] simplify implementation for builtins.sum ( #133779 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133779
Approved by: https://github.com/jansel
ghstack dependencies: #133769 , #133778
2024-08-23 10:10:19 +00:00
Xuehai Pan
6c0b15e382
[dynamo] simplify implementation for functools.reduce ( #133778 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133778
Approved by: https://github.com/jansel
ghstack dependencies: #133769
2024-08-23 09:10:44 +00:00
Xuehai Pan
cc3a76edba
[dynamo] simplify polyfill registration for builtins.all and builtins.any ( #133769 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133769
Approved by: https://github.com/jansel
2024-08-23 09:05:24 +00:00
Xuehai Pan
b6abac68ec
[BE][dynamo] reorganize polyfill module hierarchy ( #133977 )
...
Changes:
1. Move `polyfill.py` -> `polyfills/__init__.py`. It can be used as `polyfill.xxx` -> `polyfills.xxx`.
2. Move submodule loading from `polyfills/__init__.py` to `polyfills/loader.py`.
Merge `polyfill.py` and `polyfills/` packages. Each polyfill module have its own namespace for better code organization.
The ultimate goal is make `polyfills/__init__.py` empty and all polyfill functions move to its own namespace.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133977
Approved by: https://github.com/jansel
2024-08-22 16:42:29 +00:00
PyTorch MergeBot
88ead0afc6
Revert "[dynamo] simplify polyfill registration for builtins.all and builtins.any ( #133769 )"
...
This reverts commit 178e8563b8 .
Reverted https://github.com/pytorch/pytorch/pull/133769 on behalf of https://github.com/ZainRizvi due to breaking main windows cpu tests - this stack still causes that windows test to fail ([comment](https://github.com/pytorch/pytorch/pull/133712#issuecomment-2299776241 ))
2024-08-20 21:14:45 +00:00
PyTorch MergeBot
3fa874abbe
Revert "[dynamo] simplify implementation for functools.reduce ( #133778 )"
...
This reverts commit 37b4bc60a4 .
Reverted https://github.com/pytorch/pytorch/pull/133778 on behalf of https://github.com/ZainRizvi due to breaking main windows cpu tests - this stack still causes that windows test to fail ([comment](https://github.com/pytorch/pytorch/pull/133712#issuecomment-2299776241 ))
2024-08-20 21:14:45 +00:00
PyTorch MergeBot
98e6a1d8ff
Revert "[dynamo] simplify implementation for builtins.sum ( #133779 )"
...
This reverts commit 3f58a8051a .
Reverted https://github.com/pytorch/pytorch/pull/133779 on behalf of https://github.com/ZainRizvi due to breaking main windows cpu tests - this stack still causes that windows test to fail ([comment](https://github.com/pytorch/pytorch/pull/133712#issuecomment-2299776241 ))
2024-08-20 21:14:44 +00:00
Xuehai Pan
b03381cac2
[dynamo] support cls.__flags__ ( #133970 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133970
Approved by: https://github.com/jansel
ghstack dependencies: #133969
2024-08-20 20:03:31 +00:00
Xuehai Pan
5229b52bf2
[dynamo] support cls.__base__ ( #133969 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133969
Approved by: https://github.com/jansel
2024-08-20 20:03:31 +00:00
Xuehai Pan
3f58a8051a
[dynamo] simplify implementation for builtins.sum ( #133779 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133779
Approved by: https://github.com/jansel
ghstack dependencies: #133712 , #133769 , #133778
2024-08-20 19:48:57 +00:00
Xuehai Pan
37b4bc60a4
[dynamo] simplify implementation for functools.reduce ( #133778 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133778
Approved by: https://github.com/jansel
ghstack dependencies: #133712 , #133769
2024-08-20 19:48:57 +00:00
Xuehai Pan
178e8563b8
[dynamo] simplify polyfill registration for builtins.all and builtins.any ( #133769 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133769
Approved by: https://github.com/jansel
ghstack dependencies: #133712
2024-08-20 19:48:57 +00:00