Commit 1341794
Gracefully handle optree less than minimum version, part 2 (pytorch#151323)
Gracefully handle optree less than minimum version, part 2 (pytorch#151257)
If optree is less than the minimum version, we should pretend it doesn't
exist.
The problem right now is:
- Install optree==0.12.1
- `import torch._dynamo`
- This raise an error "min optree version is 0.13.0"
The fix is to pretend optree doesn't exist if it is less than the min
version.
There are ways to clean up this PR more (e.g. have a single source of
truth for the version, some of the variables are redundant), but I am
trying to reduce the risk as much as possible for this to go into 2.7.
Test Plan:
I verified the above problem was fixed. Also tried some other things,
like the following, which now gives the expected behavior.
```py
>>> import torch
>>> import optree
>>> optree.__version__
'0.12.1'
>>> import torch._dynamo
>>> import torch._dynamo.polyfills.pytree
>>> import torch.utils._pytree
>>> import torch.utils._cxx_pytree
ImportError: torch.utils._cxx_pytree depends on optree, which is
an optional dependency of PyTorch. To u
se it, please upgrade your optree package to >= 0.13.0
```
I also audited all non-test callsites of optree and torch.utils._cxx_pytree.
Follow along with me:
optree imports
- torch.utils._cxx_pytree. This is fine.
- [guarded by check] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/_dynamo/polyfills/pytree.py#L29-L31
_cxx_pytree imports
- [guarded by check] torch.utils._pytree (changed in this PR)
- [guarded by check] torch/_dynamo/polyfills/pytree.py (changed in this PR)
- [guarded by try-catch] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/distributed/_functional_collectives.py#L17
- [guarded by try-catch] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/distributed/tensor/_op_schema.py#L15
- [guarded by try-catch] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/distributed/tensor/_dispatch.py#L35
- [guarded by try-catch] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/_dynamo/variables/user_defined.py#L94
- [guarded by try-catch] https://github.com/pytorch/pytorch/blob/f76b7ef33cc30f7378ef71a201f68a2bef18dba0/torch/distributed/tensor/experimental/_func_map.py#L14
Pull Request resolved: pytorch#151257
Approved by: https://github.com/malfet, https://github.com/XuehaiPan
(cherry picked from commit f1f18c7)
Co-authored-by: rzou <[email protected]>1 parent 0739127 commit 1341794
File tree
3 files changed
+16
-6
lines changed- torch
- _dynamo/polyfills
- utils
3 files changed
+16
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
170 | | - | |
171 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
172 | 180 | | |
173 | 181 | | |
174 | 182 | | |
| |||
0 commit comments