Repository: pytorch
Issue: "file_descriptor" multiprocessing sharing strategy works incorrectly in dataloading 
Labels: module: dataloader,triaged,module: data

### 🐛 Describe the bug

Issue originally found in yolo model, but I managed to write a small reproducer based on _MultiProcessingDataLoaderIter (torch/utils/data/dataloader.py):

```import threading
import queue
import random

import torch
import torch.multiprocessing as multiprocessing

def producer(data_queue, index_queue):
    torch.set_num_threads(1)
    while True:
        try:
            r = index_queue.get(timeout=5.0)
        except queue.Empty:
            continue
        data = torch.rand([16, 3, 640, 640])
        data_queue.put(data)
        del data, r

def reader(data_queue):
    def do_one_step():
        try:
            data = data_queue.get(timeout=5.0)
        except queue.Empty:
            return

    while True:
        do_one_step()

if __name__ == "__main__":
    #multiprocessing.set_sharing_strategy('file_system')
    NUM_WORKERS = 8
    workers = []
    index_queues = []
    data_queue = multiprocessing.Queue()

    for i in range(NUM_WORKERS):
        index_queue = multiprocessing.Queue()
        index_queue.cancel_join_thread()
        w = multiprocessing.Process(
            target=producer,
            args=(data_queue,index_queue))
        w.daemon = True
        w.start()
        index_queues.append(index_queue)
        workers.append(w)

    readers = []
    for i in range(1):
        reader_thread = threading.Thread(
                target=reader,
                args=(data_queue,))

        reader_thread.daemon = True
        reader_thread.start()
        readers.append(reader_thread)

    index_tensor = torch.randint(high=10000, size=[100000])
    for i in range(100000):
        index_queues[i % NUM_WORKERS].put(index_tensor[i])

    readers[0].join()
```

The script fails (most of the time) with the following error:
```$ python experiment.py 
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "experiment.py", line 27, in reader
    do_one_step()
  File "experiment.py", line 22, in do_one_step
    data = data_queue.get(timeout=5.0)
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 116, in get
    return _ForkingPickler.loads(res)
  File "/home/user/.venvs/torch/py3.8/pt2.0.1+cpu/lib/python3.8/site-packages/torch/multiprocessing/reductions.py", line 100, in rebuild_tensor
    t = torch._utils._rebuild_tensor(storage, storage_offset, size, stride)
  File "/home/user/.venvs/torch/py3.8/pt2.0.1+cpu/lib/python3.8/site-packages/torch/_utils.py", line 149, in _rebuild_tensor
    return t.set_(storage._untyped_storage, storage_offset, size, stride)
RuntimeError: Trying to resize storage that is not resizable
```

This is caused by storage from index_tensor incorrectly getting retrieved from cache when rebuilding data tensor.
When setting the sharing_strategy to "file_system" the issue goes away.

### Versions

Collecting environment information...
PyTorch version: 2.0.1+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.27.0
Libc version: glibc-2.31

Python version: 3.8.10 (default, May 26 2023, 14:05:08)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-150-generic-x86_64-with-glibc2.29
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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:                   43 bits physical, 48 bits virtual
CPU(s):                          12
On-line CPU(s) list:             0-11
Thread(s) per core:              1
Core(s) per socket:              1
Socket(s):                       12
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Gold 5220R CPU @ 2.20GHz
Stepping:                        0
CPU MHz:                         2194.843
BogoMIPS:                        4389.68
Virtualization:                  VT-x
Hypervisor vendor:               VMware
Virtualization type:             full
L1d cache:                       384 KiB
L1i cache:                       384 KiB
L2 cache:                        12 MiB
L3 cache:                        429 MiB
NUMA node0 CPU(s):               0-11
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX flush not necessary, SMT disabled
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Retbleed:          Mitigation; IBRS
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; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx 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 ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8==6.1.0
[pip3] numpy==1.23.5
[pip3] torch==2.0.1+cpu
[conda] Could not collect

cc @SsnL @VitalyFedyunin @ejguan @dzhulgakov