You can do this when you get it from the DataLoader itself. Assume you have a training loop like this:
my_data_loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=batch_size, shuffle=shuffle)`
for i, itr in enumerate(my_data_loader):
   	X, Y = itr
  	Y = my_function(Y)
   	# Do something

I think this should work