Repository: pytorch
Issue: Type hints from _VariableFunctions and elsewhere clash
Labels: module: typing,triaged

## 🐛 Bug

PR #43339 fixes the type checking guards, so that the stubs for `_VariableFunctions.py` are pulled into `torch/__init__.py`. After fixing these guards [the mypy tests reveal](https://github.com/pytorch/pytorch/blob/3d46e02ea1f8951bcef167c33bad0217ec9da980/test/test_type_hints.py#L181) that [some of the stubs in `_VariableFunctions.py` are incompatible with those already in `torch/__init__.py`](https://dr.pytorch.org/build-details.html?build_id=128527014). 

On @ezyang's advice, those incompatibilities have been suppressed for now with a `type: ignore`. They should be fixed at some point in the future. 

## To Reproduce

* Check out PR #43339 (or master once it's merged)
* Remove the `type: ignore` from the [`_VariableFunctions` import](https://github.com/pytorch/pytorch/pull/43339/files#diff-14258fce7c17ccb97b488e64373b0803R426).
* Run the `test_type_hints.py` tests

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Environment

Any of the CI environments should suffice.

## Additional context

Pulling from [the CI logs](https://dr.pytorch.org/build-details.html?build_id=128527014), there are two groups of errors. The first is from incompatible variable names:

```
Incompatible import of "set_flush_denormal" (imported name has type "Callable[[Arg(bool, 'mode')], bool]", local name has type "Callable[[Arg(bool, 'arg')], bool]") [misc]
Incompatible import of "set_num_interop_threads" (imported name has type "Callable[[Arg(int, 'num')], None]", local name has type "Callable[[Arg(int, 'nthreads')], None]") [misc]
Incompatible import of "set_num_threads" (imported name has type "Callable[[Arg(int, 'num')], None]", local name has type "Callable[[Arg(int, 'nthreads')], None]") [misc]
```

Searching for these symbols, I think the problem is a mismatch between torch/_C/__init__.pyi.in and tools/pyi/gen_pyi.py

The second group of errors are from `torch._C._VariableFunctions.namedtuple` clashing with `torch._C.namedtuple`:
```
Incompatible import of "namedtuple_values_indices" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_values_indices]", local name has type "Type[torch._C.namedtuple_values_indices]") [misc]
Incompatible import of "namedtuple_eigenvalues_eigenvectors" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_eigenvalues_eigenvectors]", local name has type "Type[torch._C.namedtuple_eigenvalues_eigenvectors]") [misc]
Incompatible import of "namedtuple_a_tau" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_a_tau]", local name has type "Type[torch._C.namedtuple_a_tau]") [misc]
Incompatible import of "namedtuple_solution_QR" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_solution_QR]", local name has type "Type[torch._C.namedtuple_solution_QR]") [misc]
Incompatible import of "namedtuple_Q_R" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_Q_R]", local name has type "Type[torch._C.namedtuple_Q_R]") [misc]
Incompatible import of "namedtuple_sign_logabsdet" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_sign_logabsdet]", local name has type "Type[torch._C.namedtuple_sign_logabsdet]") [misc]
Incompatible import of "namedtuple_solution_LU" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_solution_LU]", local name has type "Type[torch._C.namedtuple_solution_LU]") [misc]
Incompatible import of "namedtuple_U_S_V" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_U_S_V]", local name has type "Type[torch._C.namedtuple_U_S_V]") [misc]
Incompatible import of "namedtuple_solution_cloned_coefficient" (imported name has type "Type[torch._C._VariableFunctions.namedtuple_solution_cloned_coefficient]", local name has type "Type[torch._C.namedtuple_solution_cloned_coefficient]") [misc]
```

These seem to originate from the namedtuple chunk of gen_pyi.py, which is pretty intimidating.

cc @ezyang @malfet @rgommers