Commit a122a44
adhere to lazy import rules (facebookresearch#806)
Summary:
Pull Request resolved: facebookresearch#806
Lazy import changes `Python` import semantics, specifically when it comes to initialization of packages/modules: https://www.internalfb.com/intern/wiki/Python/Cinder/Onboarding/Tutorial/Lazy_Imports/Troubleshooting/
For example, this pattern is not guaranteed to work:
```
import torch.optim
...
torch.optim._multi_tensor.Adam # may fail to resolve _multi_tensor
```
And this is guaranteed to work:
```
import torch.optim._multi_tensor
...
torch.optim._multi_tensor.Adam # will always work
```
A recent change to `PyTorch` changed module initialization logic in a way that exposed this issue.
But the code has been working for years? This is the nature of undefined behavior, any change in the environment (in this the `PyTorch` code base can make it fail.
Differential Revision: D588812911 parent 08a82e8 commit a122a44
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
0 commit comments