Tom Ritchford
bae3b17fd9
Tweak a comment and fix spelling ( #126681 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/126681
Approved by: https://github.com/Skylion007
2024-05-21 17:19:06 +00:00
Animesh Jain
5ba777f46e
[guards][cpp-guards] Optimize NN module getattr guards ( #124522 )
...
Improves the guard overhead of MobileBert model with nn module guards from 92000 units to 20000 units.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124522
Approved by: https://github.com/jansel
ghstack dependencies: #125439 , #125421
2024-05-04 22:08:56 +00:00
Animesh Jain
8706da2bad
[dynamo][cpp-guards] Improve recompilation reason logic for NO_TENSOR_ALIASING guard ( #125439 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125439
Approved by: https://github.com/williamwen42
2024-05-03 04:49:41 +00:00
Wang, Eikan
b4a008209a
Expose tensor check from guard for reusing ( #124836 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124836
Approved by: https://github.com/jgong5 , https://github.com/jansel , https://github.com/desertfire
2024-04-27 18:35:35 +00:00
Animesh Jain
3de78a1b48
[dynamo][cpp-guards] EQUALS MATCH - Cache first passing value ( #124627 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124627
Approved by: https://github.com/jansel
ghstack dependencies: #124779
2024-04-25 15:24:12 +00:00
Animesh Jain
e68d65dae2
[dynamo][cpp-guards] Differentiate dict guards wrt to guarding on key order ( #124779 )
...
We guard on key order
1) When a key is a non-constant object
2) When we actually need key order - like .values, .items etc
For dicts/OrderedDicts that do not require key order guarding, we just rely on usual `GuardManger + DictGetItemGuardAccessor`. This is faster than going through the `list(d.keys())` based design for OrderedDicts.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124779
Approved by: https://github.com/jansel
2024-04-25 08:20:35 +00:00
Animesh Jain
f213f262af
[dynamo][cpp-guards] Improve when to use Dict vs DictSubclassGuardManager ( #124237 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124237
Approved by: https://github.com/jansel , https://github.com/mlazos
ghstack dependencies: #124230
2024-04-18 03:33:37 +00:00
Animesh Jain
51cc808ac7
[dynamo][cpp-guards] Missing decref on early returns in DictSubclassGuardManager ( #124230 )
...
I am sad that I missed this earlier. Good thing is that CI caught it. Will be more careful next time.
This was the reason https://github.com/pytorch/pytorch/pull/123547 is reverted - https://github.com/pytorch/pytorch/pull/123547#issuecomment-2058350245
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124230
Approved by: https://github.com/mlazos
2024-04-17 02:49:07 +00:00
Animesh Jain
2e6871f924
[dynamo][guards-cpp] Early return in DictGuardManager for empty dicts ( #123787 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123787
Approved by: https://github.com/jansel
ghstack dependencies: #123773
2024-04-11 22:23:28 +00:00
Animesh Jain
b0b7aa201c
[dynamo][cpp-guards] Introduce DictSubclassGuardManager ( #123773 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123773
Approved by: https://github.com/jansel
2024-04-11 22:23:28 +00:00
Jason Ansel
e3ea316623
[dynamo] Save/restore cublas_allow_tf32 in convert_frame ( #123509 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123509
Approved by: https://github.com/anijain2305
2024-04-07 03:37:47 +00:00
Animesh Jain
d3596cf004
[dynamo][cpp-guards] Fix missing decref in GradGuardAccessor ( #123488 )
...
Found that there was a peak mem increase while running HF suite.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123488
Approved by: https://github.com/jansel
ghstack dependencies: #123485
2024-04-06 03:09:29 +00:00
Animesh Jain
22b9987144
[dynamo][cpp-guards] ListGetItemGuardAccessor and TupleGetItemGuardAccessor ( #123396 )
...
Speeds up the guard-overhead microbenchmark by around 10% normalized to main-branch CPP guards
~~~
import torch
@torch.compile(backend="eager")
def fn(x, lst):
for l in lst:
x = x + l
return x
n = 1000
lst = [i for i in range(n)]
x = torch.randn(4)
print(fn(x, lst))
print("Sucess")
~~~
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123396
Approved by: https://github.com/jansel
ghstack dependencies: #123285 , #123302 , #123303
2024-04-05 22:10:04 +00:00
Animesh Jain
fb7664d5bf
[dynamo][optimizer][guard-overhead] NOT_NONE guard for param.grad instead of TENSOR_MATCH ( #123285 )
...
For optimizers, we do an DATA_PTR match for parameters. For param.grad, we were doing TENSOR_MATCH, but what we really need to guard is if param.grad is None or not. Therefore, I add a new guard called NOT_NONE.
Further improves the guard overhead

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123285
Approved by: https://github.com/mlazos , https://github.com/jansel
2024-04-04 03:52:47 +00:00
Animesh Jain
3eb84b6343
[dynamo][cpp-guards] Init LocalState only when TENSOR_MATCH guard present ( #123152 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123152
Approved by: https://github.com/jansel
2024-04-03 08:04:39 +00:00
Animesh Jain
d91db70295
[dynamo][cpp-guards] Optimize tensor.grad accessor ( #123226 )
...
For LayoutLM model, reduces C++ guard overhead by 1.48x. These are the numbers

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123226
Approved by: https://github.com/jansel
2024-04-03 05:32:13 +00:00
Animesh Jain
ffd1e4e9ba
[dynamo][cpp-guards] Always Reset relational guards ( #123046 )
...
Reset guard at the end of RootGuardManager, even if the result is true. Earlier we reset only when result was False. But this causes extra bookkeeping in each guard. This PR gives a tiny bit improvement.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123046
Approved by: https://github.com/jansel
2024-04-01 21:09:35 +00:00
William Wen
7b13228038
[dynamo, 3.12] fix DICT_VERSION C++ guards ( #122449 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/122449
Approved by: https://github.com/jansel
ghstack dependencies: #122146 , #122335 , #122354 , #122355 , #122356
2024-03-27 20:39:39 +00:00
cyy
482f6c4693
[Dynamo][3/N] Fix clang-tidy warnings in torch/csrc/dynamo/* ( #122392 )
...
This PR continues to clean clang-tidy warnings in torch/csrc/dynamo/*, following #122362
Pull Request resolved: https://github.com/pytorch/pytorch/pull/122392
Approved by: https://github.com/ezyang
2024-03-22 22:57:41 +00:00
cyy
c2eedb7f8a
[Dynamo][1/N] Fix clang-tidy warnings in torch/csrc/dynamo/* ( #122259 )
...
This PR begins a series of works to ensure dynamo C++ code is clang-tidy clean.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/122259
Approved by: https://github.com/ezyang
2024-03-21 00:43:25 +00:00
cyy
1dd1899fd6
Add missing throw of std::runtime_error in dynamo/guards.cpp ( #122306 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/122306
Approved by: https://github.com/Skylion007 , https://github.com/ezyang
2024-03-20 20:50:01 +00:00
Animesh Jain
22489bfe70
[dynamo][guards-cpp-refactor] Directly call root guard manager in eval_frame ( #121622 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121622
Approved by: https://github.com/jansel
ghstack dependencies: #121614
2024-03-12 17:09:11 +00:00
Animesh Jain
2348e8e4e7
[dynamo][guards-cpp-refactor] Simplify DYNAMIC_INDICES guard ( #121614 )
...
Use NO_HASATTR guard for the common part.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121614
Approved by: https://github.com/jansel
2024-03-12 17:08:56 +00:00
Animesh Jain
c86a1ce125
[dynamo][guards-cpp-refactor] Func defaults and kwdefaults accessor ( #121338 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121338
Approved by: https://github.com/jansel
ghstack dependencies: #121327
2024-03-08 01:24:00 +00:00
Animesh Jain
79a04f2df9
[dynamo][guards-cpp-refactor] Permit dict version guard in DictGuardManager ( #121327 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121327
Approved by: https://github.com/jansel
2024-03-08 01:24:00 +00:00
Animesh Jain
e3bd6efe72
[dynamo][guards-cpp-refactor] Prevent duplication of leaf guards ( #121164 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121164
Approved by: https://github.com/jansel
ghstack dependencies: #121121 , #121147 , #121154
2024-03-06 08:36:45 +00:00
Animesh Jain
b6b2d5b00a
[dynamo][guards-cpp-refactor] Pass source name for debug ease ( #121154 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121154
Approved by: https://github.com/jansel
ghstack dependencies: #121121 , #121147
2024-03-06 08:36:45 +00:00
Animesh Jain
52d89d8491
[dynamo][guards-cpp-refactor] Simplify DictGuardManager by removing KeyValueDictGuardManager ( #121147 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121147
Approved by: https://github.com/jansel
ghstack dependencies: #121121
2024-03-06 08:36:45 +00:00
Animesh Jain
af7f55ffc8
[dynamo][guards-cpp-refactor] Add argnames in pybind'ings ( #121121 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121121
Approved by: https://github.com/jansel
2024-03-06 08:36:45 +00:00
Animesh Jain
7f81563e5e
[dynamo][guards-cpp-refactor] Skip type and length check guard for DictGuardManager ( #120739 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120739
Approved by: https://github.com/jansel
ghstack dependencies: #120673
2024-03-02 13:15:53 +00:00
Animesh Jain
82d1465d8d
[dynamo][guards-cpp-refactor] DICT_CONTAINS guard ( #120673 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120673
Approved by: https://github.com/jansel
2024-03-02 13:15:53 +00:00
Animesh Jain
82cbd9b131
[dynamo][guards-cpp-refactor] PythonLambdaGuardAccessor ( #120730 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120730
Approved by: https://github.com/jansel
ghstack dependencies: #120864
2024-02-29 07:25:13 +00:00
Animesh Jain
63f874b476
[dynamo][guards-cpp-refactor] DictGetItemGuardAccessor for f_locals ( #120593 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120593
Approved by: https://github.com/jansel
2024-02-27 03:13:55 +00:00
Animesh Jain
a299db2983
[dynamo][guards-cpp-refactor] NO_HASATTR guard ( #120469 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120469
Approved by: https://github.com/jansel
2024-02-26 04:37:40 +00:00
Animesh Jain
4328e772bf
[dynamo][guards-cpp-refactor] DICT_VERSION guard ( #120416 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120416
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123 , #120093 , #120096 , #120342 , #120344 , #120359
2024-02-25 23:24:24 +00:00
Animesh Jain
c269e48af0
[dynamo][guards-cpp-refactor] DictGuardManager ( #120359 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120359
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123 , #120093 , #120096 , #120342 , #120344
2024-02-25 23:24:24 +00:00
Animesh Jain
775a4388d9
[dynamo][guards-cpp-refactor] WEAKREF_ALIVE guard ( #120344 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120344
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123 , #120093 , #120096 , #120342
2024-02-25 23:24:04 +00:00
Animesh Jain
007606e520
[dynamo][guards-cpp-refactor] TENSOR_MATCH guard ( #120342 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120342
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123 , #120093 , #120096
2024-02-23 20:10:09 +00:00
Animesh Jain
4b65d192f0
[dynamo][guards-cpp-refactor] DYNAMIC_INDICES guard ( #120096 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120096
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123 , #120093
2024-02-23 20:10:09 +00:00
Animesh Jain
a92ce46dc3
[dynamo][guards-cpp-refactor] GlobalWeakRefGuardAccessor ( #120093 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120093
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119 , #120123
2024-02-23 20:10:01 +00:00
Animesh Jain
bb331b1eb5
[dynamo][guards-cpp-refactor] LENGTH_CHECK guard ( #120123 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120123
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091 , #120119
2024-02-23 20:09:52 +00:00
Animesh Jain
2eac593ffd
[dynamo][guards-cpp-refactor] TUPLE_ITERATOR_LEN guard ( #120119 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120119
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089 , #120091
2024-02-23 20:09:43 +00:00
Animesh Jain
da95421f05
[dynamo][guards-cpp-refactor] TupleIteratorGetItemAccessor ( #120091 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120091
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068 , #120089
2024-02-23 20:09:34 +00:00
Animesh Jain
9c64068ef8
[dynamo][guards-cpp-refactor] TypeGuardAccessor ( #120089 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120089
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067 , #120068
2024-02-21 17:56:48 +00:00
Animesh Jain
ec6783990a
[dynamo][guards-cpp-refactor] GlobalsGuardAccessor ( #120068 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120068
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065 , #120067
2024-02-21 17:56:48 +00:00
Animesh Jain
66c52d678f
[dynamo][guards-cpp-refactor] GetItemGuardAccessor ( #120067 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120067
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064 , #120065
2024-02-21 17:56:36 +00:00
Animesh Jain
7a0c2a9d0a
[dynamo][guards-cpp-refactor] NO_TENSOR_ALIASING guard ( #120065 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120065
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062 , #120064
2024-02-21 17:56:18 +00:00
Animesh Jain
8d5ae8c0b3
[dynamo][guards-cpp-refactor] TENSOR_ALIASING guard ( #120064 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120064
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061 , #120062
2024-02-21 17:56:05 +00:00
Animesh Jain
034955b2fc
[dynamo][guards-cpp-refactor] DATA_PTR_MATCH guard ( #120062 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120062
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060 , #120061
2024-02-21 17:55:46 +00:00
Animesh Jain
cc6cf89c30
[dynamo][guards-cpp-refactor] GLOBAL_STATE guard ( #120061 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120061
Approved by: https://github.com/jansel
ghstack dependencies: #119822 , #119827 , #119833 , #120060
2024-02-21 17:55:32 +00:00