This error points to different lengths of both input tensors.
TensorDataset would return samples from both inputs using the same index internally.
If one tensor contains more samples (dim0 is used for indexing), this error is thrown.
You could e.g. crop the larger tensor to the same length as the smaller one or duplicate the smaller one.
If you want to apply some more complicated sampling strategy, I would recommend to write a custom Dataset and create the pairs in __getitem__.