pytorch/torch/_dynamo/variables
David Berard d976df49c5 [dynamo] don't use LazyModuleMixin.cls_to_become if it is None (#99943)
**TL;DR**: This PR fixes handling for lazy modules where `cls_to_become is None`. In those cases, we should leave the type of the lazy module as the old value.

**Details**:
Lazy modules are intended to be initialized at execution; some of them are also supposed to switch to a different type after they have been initialized. However, not all are supposed to switch; see this logic from `nn/modules/lazy.py`

```python
    def _infer_parameters(self, ...):
        ...
        if module.cls_to_become is not None:
            module.__class__ = module.cls_to_become
```

i.e., we should leave the module type as the old value if `module.cls_to_become is None`. This PR updates dynamo's handling to match this behavior.

Test `test_lazy_module_no_cls_to_become` added to `test/dynamo/test_module.py`.

Differential Revision: [D45253698](https://our.internmc.facebook.com/intern/diff/D45253698)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99943
Approved by: https://github.com/jansel
2023-04-25 21:34:11 +00:00
..
__init__.py [dynamo] Support DELETE_ATTR (#98698) 2023-04-15 20:31:40 +00:00
base.py [BE] [2/3] Rewrite super() calls in functorch and torch (#94588) 2023-02-10 21:16:33 +00:00
builder.py [BE] Enable C419 rule for any all shortcircuiting (#99890) 2023-04-25 15:02:13 +00:00
builtin.py [BE] Enable C419 rule for any all shortcircuiting (#99890) 2023-04-25 15:02:13 +00:00
constant.py [BE] Enable C419 rule for any all shortcircuiting (#99890) 2023-04-25 15:02:13 +00:00
ctx_manager.py [Dynamo] Implementing generic context manager by inlining __enter__ and __exit__ (#98725) 2023-04-20 01:16:15 +00:00
dicts.py Fix graph break from 'hasattr: HFPretrainedConfigVariable()' (#98119) 2023-04-02 02:56:45 +00:00
functions.py Improve torch.cond useability: Return UserError with actionable error messages (#98909) 2023-04-20 17:20:41 +00:00
lists.py Revert "Replace _dynamo.config with an object instead of module (#96455)" 2023-04-12 15:06:14 +00:00
misc.py [dynamo] Support DELETE_ATTR (#98698) 2023-04-15 20:31:40 +00:00
nn_module.py [dynamo] don't use LazyModuleMixin.cls_to_become if it is None (#99943) 2023-04-25 21:34:11 +00:00
tensor.py [BE] Enable C419 rule for any all shortcircuiting (#99890) 2023-04-25 15:02:13 +00:00
torch.py [export] Associate one cond() error case with exportdb. (#99844) 2023-04-25 21:33:24 +00:00
user_defined.py [Dynamo] Implementing generic context manager by inlining __enter__ and __exit__ (#98725) 2023-04-20 01:16:15 +00:00