mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: - `torch._VF` is a hack to work around the lack of support for `torch.functional` in the JIT - that hack hides `torch._VF` functions from Mypy - could be worked around by re-introducing a stub file for `torch.functional`, but that's undesirable - so instead try to make both happy at the same time: the type ignore comments are needed for Mypy, and don't seem to affect the JIT after excluding them from the `get_type_line()` logic Encountered this issue while trying to make `mypy` run on `torch/functional.py` in gh-43446. Pull Request resolved: https://github.com/pytorch/pytorch/pull/43454 Reviewed By: glaringlee Differential Revision: D23305579 Pulled By: malfet fbshipit-source-id: 50e490693c1e53054927b57fd9acc7dca57e88ca
30 lines
656 B
Python
30 lines
656 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 torch
|
|
import sys
|
|
import types
|
|
|
|
|
|
class VFModule(types.ModuleType):
|
|
vf: types.ModuleType
|
|
|
|
def __init__(self, name):
|
|
super(VFModule, self).__init__(name)
|
|
self.vf = torch._C._VariableFunctions
|
|
|
|
def __getattr__(self, attr):
|
|
return getattr(self.vf, attr)
|
|
|
|
|
|
sys.modules[__name__] = VFModule(__name__)
|