Repository: pytorch
Issue: Type misalignments in `nn.functional` (also JIT related)
Labels: oncall: jit,module: typing,triaged

### 🐛 Describe the bug

This is a sub-task of #103761.

This is not user-facing as this only involves functions prefixed with an underscore.

**A major problem is JIT cannot understand `torch.Size` or `Tuple[int, ...]`. This problem is relatively self-contained and tracked in a separate issue #103803.**

---

The `_list_with_default` is used as this, where `input.size()` is `torch.Size`:
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L1135
However, it's annotated to accept `List` only. It's even possible to work on `int`:
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/modules/utils.py#L33-L35

---

Similar problem with `_verify_batch_size`:
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L2481
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L2435

And the same as above for `_verify_spatial_size`:
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L2527
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L2488


---

**Only this is not JIT related**

This `_in_projection_packed` is annotated to return a `List`:
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L4778-L4784
But actually it returns a 3-`tuple` in all cases (L4819, L4831, L4838):
https://github.com/pytorch/pytorch/blob/918fe519a0f9bdb2dd213eaaffbcd420b7391280/torch/nn/functional.py#L4812-L4838

---

<details>
<summary>Related error logs</summary>

```log
torch/nn/functional.py:1135:51: error: Argument 2 to "_list_with_default" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:1179:51: error: Argument 2 to "_list_with_default" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:1231:52: error: Argument 2 to "_list_with_default" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:1248:52: error: Argument 2 to "_list_with_default" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:2481:28: error: Argument 1 to "_verify_batch_size" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:2527:30: error: Argument 1 to "_verify_spatial_size" has incompatible type "Size"; expected "List[int]"  [arg-type]
torch/nn/functional.py:4819:20: error: Incompatible return value type (got "Tuple[Any, Any, Any]", expected "List[Tensor]")  [return-value]
torch/nn/functional.py:4831:20: error: Incompatible return value type (got "Tuple[Tensor, Any, Any]", expected "List[Tensor]")  [return-value]
torch/nn/functional.py:4838:16: error: Incompatible return value type (got "Tuple[Tensor, Tensor, Tensor]", expected "List[Tensor]")  [return-value]
```
</details>

### Versions

master
```[tasklist]
### Tasks
- [ ] https://github.com/pytorch/pytorch/issues/103803
```


cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel @ezyang @malfet @rgommers @xuzhao9 @gramster