Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

adhere to lazy import rules #806

Open
wants to merge 1 commit into
base: classy_vision-0.7.0
Choose a base branch
from

Commits on Jun 27, 2024

  1. adhere to lazy import rules (facebookresearch#807)

    Summary:
    Pull Request resolved: facebookresearch#807
    
    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.
    
    Reviewed By: mannatsingh
    
    Differential Revision: D58881291
    fbgheith authored and facebook-github-bot committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    79665d2 View commit details
    Browse the repository at this point in the history