Michael Lazos
041960a1ce
[Dynamo] Automatically in-graph traceable tensor subclass ctors ( #135151 )
...
Fixes https://github.com/pytorch/pytorch/issues/114389
Previously, dynamo would attempt to trace through the `__init__` of traceable tensor subclasses, since their constructors are AOT dispatcher traceable by definition, dynamo should automatically put these in the graph like we do for any other tensors. Not doing this is difficult because dynamo would need to apply mutations post tensor subclass creation in the graph.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/135151
Approved by: https://github.com/bdhirsh
2024-09-06 12:23:38 +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
Michael Lazos
d9ae92cd6e
[Dynamo] Support for proxying frozen dataclasses ( #134846 )
...
Fixes https://github.com/pytorch/pytorch/issues/133858
Details: Previously Dynamo would treat dataclasses as UserDefinedVariables. This was non-desirable if we would like to proxy the value into the graph, which is needed for TensorSubclassMetadata. To rectify this, frozen dataclasses are now able to be proxied similarly to NamedTuples. We require the object to be frozen, because if arbitrary mutation were allowed, we would need to replay those mutations in the graph after construction of the object.
For tracing construction of the variable, the generated `__init__` for the dataclass uses `object.__setattr__` because frozen dataclasses throw errors on the usual `__setattr__` invocation. With this treatment, no special handling is needed in dynamo for frozen dataclass construction.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134846
Approved by: https://github.com/bdhirsh , https://github.com/anijain2305
2024-09-04 22:17:00 +00:00
Animesh Jain
594162f7ab
[dynamo] Support reading attributes from pybind objects ( #134630 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134630
Approved by: https://github.com/jansel
2024-08-29 15:06:52 +00:00
Animesh Jain
fee677eeb6
[fbode-testing][dynamo][reland][inline-inbuilt-nn-modules] Mark attri… ( #134136 )
...
Shuai wants to test this internally before https://github.com/pytorch/pytorch/pull/133713 can go in. Creating a separate PR for ghmport.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134136
Approved by: https://github.com/yanboliang
2024-08-22 17:54:58 +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
68425e68fe
Revert "[dynamo][reland][inline-inbuilt-nn-modules] Mark attributes of nn mod… ( #133714 )"
...
This reverts commit e8d3c4be36 .
Reverted https://github.com/pytorch/pytorch/pull/133714 on behalf of https://github.com/anijain2305 due to fails internally ([comment](https://github.com/pytorch/pytorch/pull/133714#issuecomment-2302171472 ))
2024-08-21 14:21:06 +00:00
Xuehai Pan
539be0a769
[dynamo] support ClassMethodDescriptorType ( #133862 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133862
Approved by: https://github.com/jansel
2024-08-21 12:56:19 +00:00
Xuehai Pan
c929e1e11f
[dynamo] fix polyfill for user defined constructor __new__ ( #133822 )
...
In `cls->tp_call`, if `cls->tp_new` does not return an instance of class `cls`, then `cls->tp_init` is not called on the new instance.
Related PR:
- #132977
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133822
Approved by: https://github.com/jansel
2024-08-21 12:41:19 +00:00
Animesh Jain
1ae5d5bb62
[dynamo][user-defined] Improve getattr_static for user_defined objects ( #133742 )
...
Fixes https://github.com/pytorch/pytorch/issues/133607
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133742
Approved by: https://github.com/Skylion007 , https://github.com/jansel
2024-08-20 21:51:03 +00:00
Animesh Jain
33f1ee036e
[dynamo][user-defined] Simplify call_hasattr ( #133935 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133935
Approved by: https://github.com/williamwen42 , https://github.com/jansel
ghstack dependencies: #133745 , #133747 , #133746 , #133799 , #133800
2024-08-20 16:27:44 +00:00
Michael Lazos
f147349568
Fix DeviceContext bug ( #133729 )
...
Fixes https://github.com/pytorch/pytorch/issues/133666
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133729
Approved by: https://github.com/bdhirsh
ghstack dependencies: #133130
2024-08-20 07:14:37 +00:00
Animesh Jain
e8d3c4be36
[dynamo][reland][inline-inbuilt-nn-modules] Mark attributes of nn mod… ( #133714 )
...
Relands https://github.com/pytorch/pytorch/pull/132539
Relands https://github.com/pytorch/pytorch/pull/132736
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133714
Approved by: https://github.com/jansel
2024-08-20 05:57:52 +00:00
William Wen
2b95007d12
[dynamo] support random.Random ( #133725 )
...
Fixes the observed graph breaks in https://github.com/pytorch/pytorch/issues/121349 and https://github.com/pytorch/pytorch/issues/121350 .
But there are still graph breaks since a random output is being used as a seed, e.g.
```python
import random
import torch
def fn(x):
seed = random.randint(0, 100)
rand = random.Random(seed)
return x + rand.randrange(10)
opt_fn = torch.compile(fn, backend="eager", fullgraph=True)
opt_fn(torch.ones(1))
```
fails with
```
torch._dynamo.exc.InternalTorchDynamoError: UnspecializedPythonVariable() is not a constant
```
when tracing the line
```
rand = random.Random(seed)
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133725
Approved by: https://github.com/jansel
2024-08-19 22:34:44 +00:00
Animesh Jain
6ca68357b3
[dynamo] Save class vt in UserDefinedObjectVariable ( #133800 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133800
Approved by: https://github.com/jansel
ghstack dependencies: #133745 , #133747 , #133746 , #133799
2024-08-19 17:21:48 +00:00
Animesh Jain
08f14d5492
[refactor][dynamo][side-effects] Helper function for __new__ for user defined class ( #133799 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133799
Approved by: https://github.com/jansel
ghstack dependencies: #133745 , #133747 , #133746
2024-08-19 17:21:48 +00:00
Yanbo Liang
770086fe39
[Dynamo] Support torch.cuda.device ctx manager ( #133385 )
...
Fixes #128059
I'm not sure if this is the right way, since Inductor doesn't always respect the device id set by users, so probably we should just wrap it as null context manager and print a warning. cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @jansel @anijain2305 @mlazos @williamwen42
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133385
Approved by: https://github.com/jansel
2024-08-16 17:05:55 +00:00
Animesh Jain
8a2b064236
[dynamo][user_defined][stable-diffusion] Raise ObservedAttributeError on UserDefinedObject var_getattr ( #132806 )
...
Fixes https://github.com/pytorch/pytorch/issues/132551
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132806
Approved by: https://github.com/williamwen42
2024-08-16 04:30:06 +00:00
Animesh Jain
8a5708ba3d
[dynamo] Support object creation of classes with custom __new__ ( #132977 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132977
Approved by: https://github.com/jansel
2024-08-16 03:09:23 +00:00
Edward Z. Yang
90d2593b3e
Revert #132806 , #132736 , #132539 , #132487 ( #133570 )
...
This reverts commit 25df063f04 .
This reverts commit de00c79583 .
This reverts commit 419b76c4ac .
This reverts commit bc57d5b6ff .
Differential Revision: [D61335013](https://our.internmc.facebook.com/intern/diff/D61335013 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133570
Approved by: https://github.com/albanD , https://github.com/jansel , https://github.com/anijain2305
2024-08-15 20:54:21 +00:00
Yiming Zhou
7b8ab7eb3e
[dynamo] Partially support random.Random class ( #133037 )
...
This partially fixes the graph break issue when instantiating a `random.Random` class in Python.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/133037
Approved by: https://github.com/anijain2305
2024-08-09 07:15:42 +00:00
Animesh Jain
25df063f04
[dynamo][user_defined][stable-diffusion] Raise ObservedAttributeError on UserDefinedObject var_getattr ( #132806 )
...
Fixes https://github.com/pytorch/pytorch/issues/132551
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132806
Approved by: https://github.com/williamwen42
2024-08-07 18:19:49 +00:00
William Wen
01cdcbf7c8
[dynamo] revert map/zip iterator related changes ( #132528 )
...
Need to revert due to internal hangs: S437700
This reverts commit b6c1490cc0 .
Revert "[dynamo] implement IteratorVariable and polyfill fallbacks for enumerate (#131725 )"
This reverts commit 2576dbbc35 .
Revert "[dynamo] add itertools repeat/count bytecode reconstruction (#131716 )"
This reverts commit 35b4de32fa .
Revert "[dynamo] add lazy IteratorVariable implementations for map and zip (#131413 )"
This reverts commit 7d282d8755 .
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132528
Approved by: https://github.com/ZainRizvi
2024-08-04 18:46:55 +00:00
Oguz Ulgen
6e79932543
Add basic mypy annotations to dynamo ( #132415 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132415
Approved by: https://github.com/XuehaiPan , https://github.com/jamesjwu
2024-08-04 18:43:36 +00:00
PyTorch MergeBot
3558a8cf4a
Revert "Add basic mypy annotations to dynamo ( #132415 )"
...
This reverts commit 71e22e0959 .
Reverted https://github.com/pytorch/pytorch/pull/132415 on behalf of https://github.com/ZainRizvi due to Sorry, this PR has entered a weird state in the diff train. Trying to revert it to skip it, and then we can try relanding it ([comment](https://github.com/pytorch/pytorch/pull/132415#issuecomment-2267631785 ))
2024-08-04 18:39:29 +00:00
PyTorch MergeBot
0a25666f92
Revert "[dynamo] revert map/zip iterator related changes ( #132528 )"
...
This reverts commit e81e74ca6c .
Reverted https://github.com/pytorch/pytorch/pull/132528 on behalf of https://github.com/ZainRizvi due to This stack entered a weird state in the diff train. Reverting and relanding to clean the state ([comment](https://github.com/pytorch/pytorch/pull/132528#issuecomment-2267628475 ))
2024-08-04 18:26:09 +00:00
Animesh Jain
419b76c4ac
[dynamo] Reland 132308, 132314, 132318, 132334 - Make builtin nn modules attributes static ( #132539 )
...
Relanding 4 PRs ending at https://github.com/pytorch/pytorch/pull/132334
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132539
Approved by: https://github.com/Skylion007 , https://github.com/yanboliang , https://github.com/mlazos
2024-08-03 02:08:22 +00:00
William Wen
e81e74ca6c
[dynamo] revert map/zip iterator related changes ( #132528 )
...
Need to revert due to internal hangs: S437700
This reverts commit b6c1490cc0 .
Revert "[dynamo] implement IteratorVariable and polyfill fallbacks for enumerate (#131725 )"
This reverts commit 2576dbbc35 .
Revert "[dynamo] add itertools repeat/count bytecode reconstruction (#131716 )"
This reverts commit 35b4de32fa .
Revert "[dynamo] add lazy IteratorVariable implementations for map and zip (#131413 )"
This reverts commit 7d282d8755 .
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132528
Approved by: https://github.com/ZainRizvi
2024-08-02 19:40:57 +00:00
PyTorch MergeBot
24d0a32f98
Revert "[dynamo] Wrap unspecialized nn module getattr with UnspecializedNNModuleSource ( #132308 )"
...
This reverts commit aa0ed2496f .
Reverted https://github.com/pytorch/pytorch/pull/132308 on behalf of https://github.com/anijain2305 due to broke internal tests ([comment](https://github.com/pytorch/pytorch/pull/132308#issuecomment-2265959993 ))
2024-08-02 18:55:51 +00:00
PyTorch MergeBot
b8f7019df0
Revert "[dynamo] Track params/buffers and mark them as static ( #132334 )"
...
This reverts commit babb249a89 .
Reverted https://github.com/pytorch/pytorch/pull/132334 on behalf of https://github.com/anijain2305 due to broke internal tests ([comment](https://github.com/pytorch/pytorch/pull/132334#issuecomment-2265942261 ))
2024-08-02 18:41:19 +00:00
Animesh Jain
babb249a89
[dynamo] Track params/buffers and mark them as static ( #132334 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132334
Approved by: https://github.com/ezyang , https://github.com/mlazos
2024-08-02 08:55:43 +00:00
Yanbo Liang
5ea0f51187
[Dynamo] Support abc.MutableMapping.get ( #132363 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132363
Approved by: https://github.com/anijain2305 , https://github.com/mlazos
2024-08-02 04:17:35 +00:00
Oguz Ulgen
71e22e0959
Add basic mypy annotations to dynamo ( #132415 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132415
Approved by: https://github.com/XuehaiPan , https://github.com/jamesjwu
2024-08-01 20:14:25 +00:00
Animesh Jain
aa0ed2496f
[dynamo] Wrap unspecialized nn module getattr with UnspecializedNNModuleSource ( #132308 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132308
Approved by: https://github.com/yanboliang
ghstack dependencies: #132302 , #132304 , #132312
2024-08-01 06:21:05 +00:00
Xuehai Pan
e74ba1b34a
[BE][Easy][15/19] enforce style for empty lines in import segments in torch/_d*/ ( #129767 )
...
See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501 . Most changes are auto-generated by linter.
You can review these PRs via:
```bash
git diff --ignore-all-space --ignore-blank-lines HEAD~1
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129767
Approved by: https://github.com/anijain2305
2024-07-31 21:18:11 +00:00
William Wen
b6c1490cc0
[dynamo] make more unpack_var_sequence calls forced ( #132069 )
...
Fixes [T197204962](https://www.internalfb.com/intern/tasks/?t=197204962 ) (example failure: https://www.internalfb.com/intern/testinfra/diagnostics/11540474088277914.281475138576374.1722221031/ )
Added tests contain a simple repro for the observed failure (`test_map_unpack_vars`).
Also fixes https://github.com/pytorch/pytorch/issues/132044
Differential Revision: [D60420335](https://our.internmc.facebook.com/intern/diff/D60420335 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132069
Approved by: https://github.com/anijain2305
2024-07-30 02:30:08 +00:00
Guilherme Leobas
1e9cdf7d91
Relax constraints for creating a GenericContextWrappingVariable ( #129091 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129091
Approved by: https://github.com/yanboliang , https://github.com/zou3519
2024-07-29 15:40:59 +00:00
Vishwa Raj Singh
cd53698df0
Add hpu backend support for dynamo torchVariable _in_graph_classes() function ( #129948 )
...
Fixes #ISSUE_NUMBER
Recent change from PR#
f657b2b1f8 (diff-4a52059570bb96333d8383ce6a9d01bbb114c5e34aff6028f820899ca39b5a26R80) , has hard coded flow to cuda stream in ingraph function. For non cuda backend (hpu in our case), it breaks the graph.
As part of this PR change adding hpu backend support to dynamo variables function _in_graph_classes().
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129948
Approved by: https://github.com/yanboliang
2024-07-26 18:38:03 +00:00
Michael Lazos
51f4f87718
[Reland] Ensure staticmethods can be allowed in graph ( #131789 )
...
Fixes https://github.com/pytorch/pytorch/issues/124735
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131789
Approved by: https://github.com/anijain2305
2024-07-25 22:54:18 +00:00
Oguz Ulgen
7a42470bcb
Annotate all InstructionTranslator ( #131509 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131509
Approved by: https://github.com/zou3519
2024-07-24 23:45:53 +00:00
PyTorch MergeBot
236e06f9f9
Revert "Ensure staticmethods can be allowed in graph ( #130882 )"
...
This reverts commit 93fdd0237d .
Reverted https://github.com/pytorch/pytorch/pull/130882 on behalf of https://github.com/clee2000 due to torchrec test still broken internally D59945836 ([comment](https://github.com/pytorch/pytorch/pull/130882#issuecomment-2249003059 ))
2024-07-24 22:32:41 +00:00
PyTorch MergeBot
5db5865614
Revert "Annotate all InstructionTranslator ( #131509 )"
...
This reverts commit eafbd20f23 .
Reverted https://github.com/pytorch/pytorch/pull/131509 on behalf of https://github.com/clee2000 due to sorry need to revert this to revert something else, I think you only need to rebase and remerge ([comment](https://github.com/pytorch/pytorch/pull/131509#issuecomment-2249000843 ))
2024-07-24 22:29:49 +00:00
Oguz Ulgen
eafbd20f23
Annotate all InstructionTranslator ( #131509 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131509
Approved by: https://github.com/zou3519
2024-07-24 05:31:01 +00:00
Michael Lazos
93fdd0237d
Ensure staticmethods can be allowed in graph ( #130882 )
...
Fixes https://github.com/pytorch/pytorch/issues/124735
Pull Request resolved: https://github.com/pytorch/pytorch/pull/130882
Approved by: https://github.com/anijain2305 , https://github.com/williamwen42
2024-07-23 18:59:19 +00:00
Animesh Jain
e7c5e06772
[dynamo] Support __contains__ on __dict__ on UserDefinedClassVariable ( #131378 )
...
Fixes https://github.com/pytorch/pytorch/issues/129665
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131378
Approved by: https://github.com/mlazos
ghstack dependencies: #131347 , #131367
2024-07-23 14:15:26 +00:00
PyTorch MergeBot
9f6db5d0e2
Revert "Ensure staticmethods can be allowed in graph ( #130882 )"
...
This reverts commit b0387449db .
Reverted https://github.com/pytorch/pytorch/pull/130882 on behalf of https://github.com/atalman due to failing torchrec tests internally, please fix and reland ([comment](https://github.com/pytorch/pytorch/pull/130882#issuecomment-2236528473 ))
2024-07-18 13:31:30 +00:00
PyTorch MergeBot
0b134c15cd
Revert "Relax constraints for creating a GenericContextWrappingVariable ( #129091 )"
...
This reverts commit 882fd91869 .
Reverted https://github.com/pytorch/pytorch/pull/129091 on behalf of https://github.com/clee2000 due to test_jit started failing on main after this stack https://github.com/pytorch/pytorch/actions/runs/9980754603/job/27583474357 a8bd2933d9 ([comment](https://github.com/pytorch/pytorch/pull/129091#issuecomment-2234269541 ))
2024-07-17 20:59:40 +00:00
Guilherme Leobas
882fd91869
Relax constraints for creating a GenericContextWrappingVariable ( #129091 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129091
Approved by: https://github.com/yanboliang , https://github.com/zou3519
2024-07-17 20:07:06 +00:00
Michael Lazos
b0387449db
Ensure staticmethods can be allowed in graph ( #130882 )
...
Fixes https://github.com/pytorch/pytorch/issues/124735
Pull Request resolved: https://github.com/pytorch/pytorch/pull/130882
Approved by: https://github.com/anijain2305 , https://github.com/williamwen42
2024-07-17 19:18:30 +00:00
Xuehai Pan
973037be6a
[BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() ( #130199 )
...
This PR changes the empty collection factory call to Python literals:
- `list()` -> `[]`
- `tuple()` -> `()`
- `dict()` -> `{}`
The Python literals are more performant and safer. For example, the bytecode for building an empty dictionary:
```bash
$ python3 -m dis - <<EOS
import collections
d1 = {}
d2 = dict()
dict = collections.OrderedDict
d3 = dict()
EOS
```
```text
0 0 RESUME 0
1 2 LOAD_CONST 0 (0)
4 LOAD_CONST 1 (None)
6 IMPORT_NAME 0 (collections)
8 STORE_NAME 0 (collections)
3 10 BUILD_MAP 0
12 STORE_NAME 1 (d1)
4 14 PUSH_NULL
16 LOAD_NAME 2 (dict)
18 CALL 0
26 STORE_NAME 3 (d2)
6 28 LOAD_NAME 0 (collections)
30 LOAD_ATTR 8 (OrderedDict)
50 STORE_NAME 2 (dict)
7 52 PUSH_NULL
54 LOAD_NAME 2 (dict)
56 CALL 0
64 STORE_NAME 5 (d3)
66 RETURN_CONST 1 (None)
```
The dict literal `{}` only has one bytecode `BUILD_MAP`, while the factory call `dict()` has three `PUSH_NULL + LOAD_NAME + CALL`. Also, the factory call is not safe if users override the `dict` name in `locals` or `globals` (see the example of replacing with `OrderedDict` above).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/130199
Approved by: https://github.com/malfet
2024-07-11 17:30:28 +00:00