File size: 695 Bytes
ad5f26a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""

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: str):
        super().__init__(name)
        self.vf = torch._C._VariableFunctions

    def __getattr__(self, name: str) -> object:
        return getattr(self.vf, name)


sys.modules[__name__] = VFModule(__name__)