mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
Rewrite Python built-in class `super()` calls. Only non-semantic changes should be applied. - #94587 - #94588 - #94592 Also, methods with only a `super()` call are removed: ```diff class MyModule(nn.Module): - def __init__(self): - super().__init__() - def forward(self, ...): ... ``` Some cases that change the semantics should be kept unchanged. E.g.:f152a79be9/caffe2/python/net_printer.py (L184-L190)
f152a79be9/test/test_jit_fuser_te.py (L2628-L2635)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/94588 Approved by: https://github.com/ezyang, https://github.com/albanD
31 lines
643 B
Python
31 lines
643 B
Python
"""
|
|
This makes the functions in torch._C._VariableFunctions available as
|
|
torch._VF.<funcname>
|
|
without mypy being able to find them.
|
|
|
|
A subset of those functions are mapped to ATen functions in
|
|
torch/jit/_builtins.py
|
|
|
|
See https://github.com/pytorch/pytorch/issues/21478 for the reason for
|
|
introducing torch._VF
|
|
|
|
"""
|
|
import sys
|
|
import types
|
|
|
|
import torch
|
|
|
|
|
|
class VFModule(types.ModuleType):
|
|
vf: types.ModuleType
|
|
|
|
def __init__(self, name):
|
|
super().__init__(name)
|
|
self.vf = torch._C._VariableFunctions
|
|
|
|
def __getattr__(self, attr):
|
|
return getattr(self.vf, attr)
|
|
|
|
|
|
sys.modules[__name__] = VFModule(__name__)
|