Repository: pytorch
Issue: XPU ConvTranspose2d Causes DataLoader Memory Leak
Labels: triaged,module: xpu

### 🐛 Describe the bug

I run the following notebook on XPU (device_type = "xpu") failed with "Too many open files" error. It seems the DataLoader does not close the files. The memory increases slowly from 2 GiB to 8 GiB within 3 epochs. Running on CPU (device_type = "cpu") is fine.
[Convolutional Autoencoder Notebook](https://github.com/ekaakurniawan/DLND/blob/a770-part3/assignments/P3-CNN/L5-autoencoder/Convolutional_Autoencoder_Exercise.ipynb)

I suspect the issue is caused by ConvTranspose2d layer because the following notebook without the layer is working fine on XPU.
[Simple Autoencoder Notebook](https://github.com/ekaakurniawan/DLND/blob/a770-part3/assignments/P3-CNN/L5-autoencoder/Simple_Autoencoder_Exercise.ipynb)

Please find the [steps to setup](https://github.com/ekaakurniawan/DLND/tree/a770-part3?tab=readme-ov-file#intel-gpu) as well as the following entire error message.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[8], line 11
      6 train_loss = 0.0
      8 ###################
      9 # train the model #
     10 ###################
---> 11 for data in train_loader:
     12     # _ stands in for labels, here
     13     # no need to flatten images
     14     images, _ = data
     15     images = images.to(device)

File [~/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py:708](http://localhost:8888/home/eka/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py#line=707), in _BaseDataLoaderIter.__next__(self)
    705 if self._sampler_iter is None:
    706     # TODO(https://github.com/pytorch/pytorch/issues/76750)
    707     self._reset()  # type: ignore[call-arg]
--> 708 data = self._next_data()
    709 self._num_yielded += 1
    710 if (
    711     self._dataset_kind == _DatasetKind.Iterable
    712     and self._IterableDataset_len_called is not None
    713     and self._num_yielded > self._IterableDataset_len_called
    714 ):

File ~/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py:1458, in _MultiProcessingDataLoaderIter._next_data(self)
   1455     return self._process_data(data)
   1457 assert not self._shutdown and self._tasks_outstanding > 0
-> 1458 idx, data = self._get_data()
   1459 self._tasks_outstanding -= 1
   1460 if self._dataset_kind == _DatasetKind.Iterable:
   1461     # Check for _IterableDatasetStopIteration

File [~/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py:1420](http://localhost:8888/home/eka/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py#line=1419), in _MultiProcessingDataLoaderIter._get_data(self)
   1416     # In this case, `self._data_queue` is a `queue.Queue`,. But we don't
   1417     # need to call `.task_done()` because we don't use `.join()`.
   1418 else:
   1419     while True:
-> 1420         success, data = self._try_get_data()
   1421         if success:
   1422             return data

File [~/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py:1282](http://localhost:8888/home/eka/Workspace/pytorch_arc/pytorch_arc_env/lib/python3.12/site-packages/torch/utils/data/dataloader.py#line=1281), in _MultiProcessingDataLoaderIter._try_get_data(self, timeout)
   1280 except OSError as e:
   1281     if e.errno == errno.EMFILE:
-> 1282         raise RuntimeError(
   1283             "Too many open files. Communication with the"
   1284             " workers is no longer possible. Please increase the"
   1285             " limit using `ulimit -n` in the shell or change the"
   1286             " sharing strategy by calling"
   1287             " `torch.multiprocessing.set_sharing_strategy('file_system')`"
   1288             " at the beginning of your code"
   1289         ) from None
   1290 raise

```RuntimeError: Too many open files. Communication with the workers is no longer possible. Please increase the limit using `ulimit -n` in the shell or change the sharing strategy by calling `torch.multiprocessing.set_sharing_strategy('file_system')` at the beginning of your code```



### Versions

```
$ python collect_env.py
Collecting environment information...
PyTorch version: 2.6.0+xpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39
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
Address sizes:                        46 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               24
On-line CPU(s) list:                  0-23
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Core(TM) Ultra 9 285K
CPU family:                           6
Model:                                198
Thread(s) per core:                   1
Core(s) per socket:                   1
Socket(s):                            24
Stepping:                             2
CPU(s) scaling MHz:                   30%
CPU max MHz:                          5100.0000
CPU min MHz:                          800.0000
BogoMIPS:                             7372.80
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault intel_ppin ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni lam wbnoinvd dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid bus_lock_detect movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                       VT-x
L1d cache:                            768 KiB (20 instances)
L1i cache:                            1.3 MiB (20 instances)
L2 cache:                             40 MiB (12 instances)
L3 cache:                             36 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-23
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.1.2
[pip3] pytorch-triton-xpu==3.2.0
[pip3] torch==2.6.0+xpu
[pip3] torchaudio==2.6.0+xpu
[pip3] torchvision==0.21.0+xpu
[pip3] triton==3.2.0
[conda] Could not collect
```

cc @gujinghui @EikanWang @fengyuan14 @guangyey