_VF.py 643 B

123456789101112131415161718192021222324252627282930
  1. """
  2. This makes the functions in torch._C._VariableFunctions available as
  3. torch._VF.<funcname>
  4. without mypy being able to find them.
  5. A subset of those functions are mapped to ATen functions in
  6. torch/jit/_builtins.py
  7. See https://github.com/pytorch/pytorch/issues/21478 for the reason for
  8. introducing torch._VF
  9. """
  10. import sys
  11. import types
  12. import torch
  13. class VFModule(types.ModuleType):
  14. vf: types.ModuleType
  15. def __init__(self, name):
  16. super().__init__(name)
  17. self.vf = torch._C._VariableFunctions
  18. def __getattr__(self, attr):
  19. return getattr(self.vf, attr)
  20. sys.modules[__name__] = VFModule(__name__)