Is there a way to add tensors to an existing dataloader?

The dataloader I have is derived like this:

from torch.utils.data import DataLoader,TensorDataset
dataset = TensorDataset(tensor0, tensor1)
dataloader = DataLoader(
                dataset,  
                sampler = RandomSampler(dataset)
                batch_size = batch_size
)

Then I realized I had to add tensor2 when creating dataset: It should have been

dataset = TensorDataset(tensor0, tensor1, tensor2)

But I didn’t save tensor0, tensor1, or dataset. Creating these all over again is very costly.
Can I make the desired modification to dataloader if I only have dataloader?

The DataLoader uses the provided Dataset to create the batches. Based on your description it seems that you would like to add the new tensor to the Dataset. Outside of the DataLoader loop, you could access it via dataloader.dataset and could also try to reassign a new Dataset. However, the TensorDataset doesn’t provide a method to add new tensors, so you would have to recreate it.

Thank you very much!