Each worker in your DataLoader will try to create a CUDA context, since you are using CUDATensors, which will raise this error.
You could use the 'spawn' method for multiprocessing as described here 42.
Here is a small example:
import torch.multiprocessing as mp

class MyDataset(Dataset):
    def __init__(self, device='cpu'):
        super(MyDataset, self).__init__()
        self.data = torch.randn(100, 1, device=device)
        
    def __getitem__(self, index):
        x = self.data[index]
        return x
    
    def __len__(self):
        return len(self.data)
    
def main():
    dataset = MyDataset(device='cuda')
    loader = DataLoader(
        dataset,
        num_workers=2
    )
    
    for data in loader:
        print(data.device)
    
if __name__=='__main__':
    mp.set_start_method('spawn')
    main()