Inconsistent memory allocation using FSDP between PT 2.0 and Nightlies
Labels: high priority, triage review, oncall: distributed, triaged, module: fsdp

### 🐛 Describe the bug

I am running the multi-node training of T5-11B using FSDP. Running this with 5 nodes each 8 A100 40 GB works fine with PT 1.13.1 and PT 2.0, however this runs into OOM with Pytorch Nightlies, (2.1.0.dev20230606+cu118) and even like nightlies from two weeks ago. This kind of continue even if I scale nodes to 7-8 nodes still the same issue. I would appreciate any thoughts on the root cause/ debugging steps.

Also wanted to mention that PT 1.13.1 and PT 2.0 were tested with cuda 11.7 vs PT nightlies is on cuda 11.8.

**memory stats on different versions**

- PT 1.13.1  reserved memory: 37.043 GB, allocate memory: 21.1228
- PT 2.0  reserved memory: 37.6172 GB, allocate memory: 21.1387
- PT nightlies OOM

**Repro steps**

```bash
git clone https://github.com/HamidShojanazeri/examples.git
cd examples
git checkout repro
cd distributed/FSDP
pip install -r requirements.txt
sh download_dataset.sh

sbatch t5.slurm

```

PT 1.13 successful run[ logs](https://gist.github.com/HamidShojanazeri/901927f6b2290c3c3548f95e761d6355)
PT 2.0 successful run[ logs](https://gist.github.com/HamidShojanazeri/4b9f16cd758a05595cb9d3ca22536495)
PT Nightlies failure [logs](https://gist.github.com/HamidShojanazeri/fe9831f6f401524c4235c5a36d9d678b) 


### Versions
```bash 
Collecting environment information...
PyTorch version: 2.1.0.dev20230606+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: 10.0.0-4ubuntu1 
CMake version: version 3.26.3
Libc version: glibc-2.31

Python version: 3.10.11 (main, Apr 20 2023, 19:02:41) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-1019-aws-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: 11.2.152
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
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
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          96
On-line CPU(s) list:             0-95
Thread(s) per core:              2
Core(s) per socket:              24
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
Stepping:                        7
CPU MHz:                         2977.283
BogoMIPS:                        4999.99
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       1.5 MiB
L1i cache:                       1.5 MiB
L2 cache:                        48 MiB
L3 cache:                        71.5 MiB
NUMA node0 CPU(s):               0-23,48-71
NUMA node1 CPU(s):               24-47,72-95
Vulnerability Itlb multihit:     KVM: Mitigation: VMX unsupported
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Retbleed:          Vulnerable
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, STIBP disabled, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.5
[pip3] pytorch-triton==2.1.0+9820899b38
[pip3] torch==2.1.0.dev20230606+cu118
[pip3] torch-model-archiver==0.8.0
[pip3] torch-workflow-archiver==0.2.8
[pip3] torchaudio==2.1.0.dev20230606+cu118
[pip3] torchpippy==0.1.1+3edf3ab
[pip3] torchserve==0.8.0
[pip3] torchvision==0.16.0.dev20230606+cu118
[pip3] triton==2.0.0
[pip3] vit-pytorch==1.2.2
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] pytorch-triton            2.1.0+9820899b38          pypi_0    pypi
[conda] torch                     2.1.0.dev20230606+cu118          pypi_0    pypi
[conda] torch-model-archiver      0.8.0                    pypi_0    pypi
[conda] torch-workflow-archiver   0.2.8                    pypi_0    pypi
[conda] torchaudio                2.1.0.dev20230606+cu118          pypi_0    pypi
[conda] torchpippy                0.1.1+3edf3ab            pypi_0    pypi
[conda] torchserve                0.8.0                    pypi_0    pypi
[conda] torchvision               0.16.0.dev20230606+cu118          pypi_0    pypi
[conda] triton                    2.0.0                    pypi_0    pypi
[conda] vit-pytorch               1.2.2                    pypi_0    pypi

```

cc @ezyang @gchanan @zou3519 @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu