Error in iterating through dataloader

for data, transf_data,target in data_bar:

File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/tqdm/”, line 1178, in iter
for obj in iterable:
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/”, line 633, in next
data = self._next_data()
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/”, line 1345, in _next_data
return self._process_data(data)
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/”, line 1371, in _process_data
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/”, line 644, in reraise
raise exception
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/_utils/”, line 308, in _worker_loop
data = fetcher.fetch(index)
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/_utils/”, line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File “/root/anaconda3/envs/gcn/lib/python3.11/site-packages/torch/utils/data/_utils/”, line 51, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File “/home/rani1/graph_mv/nn_linear/”, line 14, in getitem
feature = self.features[idx]
RuntimeError: CUDA error: initialization error
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

You didn’t describe your use case and what exactly triggers the error, so I speculate you are using CUDATensors inside your Dataset and are then using multiple workers in your DataLoader, which will try to re-initialize the CUDA context.
If so, use CPUTensors or the spawn start method in multiprocessing.

Yes , just solved it, by num_worker = 0