`vmap` causes unpredictable behavior when combined with `autocast`
Labels: triaged, module: vmap, module: amp (automated mixed precision), module: functorch

### 🐛 Describe the bug

Hi, when I use `autocast` I get numerical differences in the output of basic pytorch operators (in the attached example, `nn.Linear`) depending on whether or not `vmap` is used. In the following minimal code example, we calculate the sum of an output of a matrix multiplication applied to a vector. The output of the summation changes from standard pytorch to vmap if we use autocast, and does not if we do not use `autocast` (here, in the "no autocast" scenario we use `bfloat16` values). Is this expected behavior or a bug? 

Minimal code example:
```
import torch as ch
import copy

def make_functional_with_buffers(mod):
    params_dict = dict(mod.named_parameters())
    params_names = tuple(params_dict.keys())
    params_values = tuple(params_dict.values())
    
    stateless_mod = copy.deepcopy(mod)
    stateless_mod.to('cuda')

    def fmodel(new_params_values, x: ch.Tensor):
        new_params_dict = {name: value for name, value in zip(params_names, new_params_values)}
        return ch.func.functional_call(stateless_mod, (new_params_dict,), (x,))

    return fmodel, params_values, params_dict

def test(enable_autocast=True):
    ch.manual_seed(25)
    x = ch.rand(1, 1024, 768, dtype=ch.bfloat16, device='cuda')

    if enable_autocast:
        linear_dtype = ch.float32
    else:
        linear_dtype = ch.bfloat16

    Wqkv = ch.nn.Linear(768, 2304).to(device='cuda', dtype=linear_dtype)
    Wqkv.weight.data = ch.randn(2304, 768, dtype=linear_dtype, device='cuda' )
    Wqkv.bias.data = ch.randn(2304, dtype=linear_dtype, device='cuda')

    fmodel, params_values, _ = make_functional_with_buffers(Wqkv)
    def output_function(fmodel, weights, x_input):
        outp = fmodel(weights, x_input)
        return outp.sum()

    vmap_output_fn = ch.func.vmap(output_function, in_dims=(None, None, 0))

    print('With autocast?', enable_autocast)
    with ch.cuda.amp.autocast(dtype=ch.bfloat16, enabled=enable_autocast):
        print('> functorch:', vmap_output_fn(fmodel, params_values, x[None, ...]))

    with ch.cuda.amp.autocast(dtype=ch.bfloat16, enabled=enable_autocast):
        qkv = Wqkv(x)
        print('> standard pytorch:', qkv.sum())

if __name__ == '__main__':
    test(enable_autocast=True)
    print('\n')
    test(enable_autocast=False)
```

which outputs:

```
With autocast? True
> functorch: tensor([173219.2500], device='cuda:0', grad_fn=<SumBackward1>)
> standard pytorch: tensor(173103.8125, device='cuda:0', grad_fn=<SumBackward0>)


With autocast? False
> functorch: tensor([173056.], device='cuda:0', dtype=torch.bfloat16,
       grad_fn=<SumBackward1>)
> standard pytorch: tensor(173056., device='cuda:0', dtype=torch.bfloat16, grad_fn=<SumBackward0>)
```

Please let me know if I can provide any more information that helps!

### Versions

Collecting environment information...
PyTorch version: 2.1.0.dev20230713+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Clang version: Could not collect
CMake version: version 3.26.3
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jul  5 2023, 18:54:27) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-76-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.7.64
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA A100-PCIE-40GB
GPU 1: NVIDIA A100-PCIE-40GB
GPU 2: NVIDIA A100-PCIE-40GB
GPU 3: NVIDIA A100-PCIE-40GB
GPU 4: NVIDIA A100-PCIE-40GB
GPU 5: NVIDIA A100-PCIE-40GB
GPU 6: NVIDIA A100-PCIE-40GB
GPU 7: NVIDIA A100-PCIE-40GB
GPU 8: NVIDIA A100-PCIE-40GB

Nvidia driver version: 515.43.04
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   43 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          96
On-line CPU(s) list:             0-95
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 7402 24-Core Processor
CPU family:                      23
Model:                           49
Thread(s) per core:              2
Core(s) per socket:              24
Socket(s):                       2
Stepping:                        0
Frequency boost:                 enabled
CPU max MHz:                     2800.0000
CPU min MHz:                     1500.0000
BogoMIPS:                        5600.11
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
Virtualization:                  AMD-V
L1d cache:                       1.5 MiB (48 instances)
L1i cache:                       1.5 MiB (48 instances)
L2 cache:                        24 MiB (48 instances)
L3 cache:                        256 MiB (16 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-23,48-71
NUMA node1 CPU(s):               24-47,72-95
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.4
[pip3] pytorch-ranger==0.1.1
[pip3] pytorch-triton==2.1.0+3c400e7818
[pip3] torch==2.1.0.dev20230713+cu118
[pip3] torch-optimizer==0.3.0
[pip3] torchaudio==2.1.0.dev20230713+cu118
[pip3] torchdata==0.6.1
[pip3] torchmetrics==0.11.4
[pip3] torchtext==0.15.2
[pip3] torchvision==0.16.0.dev20230713+cu118
[pip3] triton==2.0.0
[pip3] triton-pre-mlir==2.0.0
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               11.8.0               h6a678d5_0
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2023.1.0         h6d00ec8_46342
[conda] mkl-service               2.4.0           py310h5eee18b_1
[conda] mkl_fft                   1.3.6           py310h1128e8f_1
[conda] mkl_random                1.2.2           py310h1128e8f_1
[conda] numpy                     1.24.4                   pypi_0    pypi
[conda] pytorch-cuda              11.7                 h778d358_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pytorch-ranger            0.1.1                    pypi_0    pypi
[conda] pytorch-triton            2.1.0+3c400e7818          pypi_0    pypi
[conda] torch                     2.1.0.dev20230713+cu118          pypi_0    pypi
[conda] torch-optimizer           0.3.0                    pypi_0    pypi
[conda] torchaudio                2.1.0.dev20230713+cu118          pypi_0    pypi
[conda] torchdata                 0.6.1                    pypi_0    pypi
[conda] torchmetrics              0.11.4                   pypi_0    pypi
[conda] torchtext                 0.15.2                   pypi_0    pypi
[conda] torchtriton               2.0.0                     py310    pytorch
[conda] torchvision               0.16.0.dev20230713+cu118          pypi_0    pypi
[conda] triton-pre-mlir           2.0.0                    pypi_0    pypi

cc @zou3519 @mcarilli @ptrblck @leslie-fang-intel @jgong5 @Chillee @samdow @kshitij12345 @janeyx99