torch.dot gives wrong result on Macos
Labels: high priority, triaged, module: macos, module: correctness (silent)

### 🐛 Describe the bug

When I try to create a demo, I found that the result is realy baffling:
(1)The demo created by me:

```
Last login: Tue Aug 22 14:42:20 on ttys000
(base) crk@crkdeMacBook-Air ~ % conda activate kk
(kk) crk@crkdeMacBook-Air ~ % python
Python 3.8.17 (default, Jul  5 2023, 15:35:58) 
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.arange(4.0)
>>> x
tensor([0., 1., 2., 3.])
>>> x.requires_grad_(True)
tensor([0., 1., 2., 3.], requires_grad=True)
>>> y = 2 * torch.dot(x, x)
>>> y
tensor(0., grad_fn=<MulBackward0>)
>>> 
```
I'm very confused, and when I try it on Colab, the result of y is 
`tensor(28., grad_fn=<MulBackward0>)`
I realy want to know why.

### Versions

My enviorment is below:

```
(kk) crk@crkdeMacBook-Air ~ % conda list
# packages in environment at /Users/crk/miniconda3/envs/kk:
#
# Name                    Version                   Build  Channel
appnope                   0.1.3              pyhd8ed1ab_0    conda-forge
asttokens                 2.2.1              pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
ca-certificates           2023.7.22            hf0a4a13_0    conda-forge
comm                      0.1.4              pyhd8ed1ab_0    conda-forge
contourpy                 1.1.0                    pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
debugpy                   1.6.7            py38h313beb8_0  
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
fonttools                 4.42.0                   pypi_0    pypi
glob2                     0.7                      pypi_0    pypi
importlib-resources       6.0.1                    pypi_0    pypi
ipykernel                 6.25.1             pyh5fb750a_0    conda-forge
ipython                   8.12.0             pyhd1c38e8_0    conda-forge
jedi                      0.19.0             pyhd8ed1ab_0    conda-forge
jupyter_client            7.3.4              pyhd8ed1ab_0    conda-forge
jupyter_core              5.3.0            py38hca03da5_0  
kiwisolver                1.4.4                    pypi_0    pypi
libcxx                    14.0.6               h848a8c0_0  
libffi                    3.4.4                hca03da5_0  
libsodium                 1.0.18               h27ca646_1    conda-forge
matplotlib                3.7.2                    pypi_0    pypi
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
ncurses                   6.4                  h313beb8_0  
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
numpy                     1.24.4                   pypi_0    pypi
opencv-python             4.8.0.76                 pypi_0    pypi
openssl                   3.1.2                h53f4e23_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandas                    2.0.3                    pypi_0    pypi
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.0.0                   pypi_0    pypi
pip                       23.2.1           py38hca03da5_0  
platformdirs              3.10.0             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
psutil                    5.9.0            py38h1a28f6b_0  
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.16.1             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9                    pypi_0    pypi
python                    3.8.17               hb885b13_0  
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.8                      2_cp38    conda-forge
pytz                      2023.3                   pypi_0    pypi
pyzmq                     25.1.0           py38h313beb8_0  
readline                  8.2                  h1a28f6b_0  
setuptools                68.0.0           py38hca03da5_0  
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.41.2               h80987f9_0  
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               hb8d0fd4_0  
torch                     1.9.0                    pypi_0    pypi
torchaudio                0.9.0                    pypi_0    pypi
torchvision               0.10.0                   pypi_0    pypi
tornado                   6.1              py38hea4295b_1    conda-forge
tqdm                      4.66.0                   pypi_0    pypi
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.7.1                hd8ed1ab_0    conda-forge
typing_extensions         4.7.1              pyha770c72_0    conda-forge
tzdata                    2023.3                   pypi_0    pypi
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
wheel                     0.38.4           py38hca03da5_0  
xz                        5.4.2                h80987f9_0  
zeromq                    4.3.4                hbdafb3b_1    conda-forge
zipp                      3.16.2                   pypi_0    pypi
zlib                      1.2.13               h5a0b063_0  
(kk) crk@crkdeMacBook-Air ~ % 
```

cc @ezyang @gchanan @zou3519 @malfet @albanD