Repository: pytorch
Issue: verbose stack trace for default collate function
Labels: module: dataloader,module: error checking,triaged

I had to write a custom collate function to figure out my bug. would be nice if the default collate function can provide detailed / more specific stack trace, thanks!

`Run wy0zpbq7 errored: RuntimeError('Caught RuntimeError in DataLoader worker process 0.\nOriginal Traceback (most recent call last):\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop\n    data = fetcher.fetch(index)\n           ^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch\n    return self.collate_fn(data)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File "/work/shivanim/vqvae/train.py", line 67, in collate_tensor_fn\n    seq=torch.stack(seq,dim=0)\n        ^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: stack expects each tensor to be equal size, but got [3, 4, 224, 224] at entry 0 and [3, 4, 144, 192] at entry 6\n')
wandb: ERROR Run wy0zpbq7 errored: RuntimeError('Caught RuntimeError in DataLoader worker process 0.\nOriginal Traceback (most recent call last):\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop\n    data = fetcher.fetch(index)\n           ^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch\n    return self.collate_fn(data)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File "/work/shivanim/vqvae/train.py", line 67, in collate_tensor_fn\n    seq=torch.stack(seq,dim=0)\n        ^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: stack expects each tensor to be equal size, but got [3, 4, 224, 224] at entry 0 and [3, 4, 144, 192] at entry 6\n')
`

PyTorch stack trace for the same bug

`Run pvk42txf errored: RuntimeError('Caught RuntimeError in DataLoader worker process 0.\nOriginal Traceback (most recent call last):\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop\n    data = fetcher.fetch(index)\n           ^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch\n    return self.collate_fn(data)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 269, in default_collate\n    return collate(batch, collate_fn_map=default_collate_fn_map)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 142, in collate\n    return [collate(samples, collate_fn_map=collate_fn_map) for samples in transposed]  # Backwards compatibility.\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 142, in <listcomp>\n    return [collate(samples, collate_fn_map=collate_fn_map) for samples in transposed]  # Backwards compatibility.\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 119, in collate\n    return collate_fn_map[elem_type](batch, collate_fn_map=collate_fn_map)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 165, in collate_tensor_fn\n    out = elem.new(storage).resize_(len(batch), *list(elem.size()))\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: Trying to resize storage that is not resizable\n')
wandb: ERROR Run pvk42txf errored: RuntimeError('Caught RuntimeError in DataLoader worker process 0.\nOriginal Traceback (most recent call last):\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop\n    data = fetcher.fetch(index)\n           ^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch\n    return self.collate_fn(data)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 269, in default_collate\n    return collate(batch, collate_fn_map=default_collate_fn_map)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 142, in collate\n    return [collate(samples, collate_fn_map=collate_fn_map) for samples in transposed]  # Backwards compatibility.\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 142, in <listcomp>\n    return [collate(samples, collate_fn_map=collate_fn_map) for samples in transposed]  # Backwards compatibility.\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 119, in collate\n    return collate_fn_map[elem_type](batch, collate_fn_map=collate_fn_map)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/users/shivanim/anaconda3/envs/tqn2/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 165, in collate_tensor_fn\n    out = elem.new(storage).resize_(len(batch), *list(elem.size()))\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: Trying to resize storage that is not resizable\n')`


cc @SsnL @VitalyFedyunin @ejguan @dzhulgakov @malfet