How to get all combinations of two data loaders of different sizes

I want to get all combintations of two dataLoaders which have different dataset size.
I can’t contain the whole data because of the GPU memory. (batch size == 32)
What I want to do is:

loader_a : [a1,a2,a3] # Acutal size: 2,500
loader_b: [b1,b2,b3,b4] # Actual size: 5,430
Get Possible Combinations:
[a1-b1]
[a1-b2]
[a1-b3]
[a1-b4]
[a2-b1]
[a2-b2]
...
[a3-b4]
for step, (data_a, data_b) in enumerate(zip(loader_a, loader_b)):
... ?

You could try to use itertools.product:

from itertools import product

from torch.utils.data import TensorDataset, DataLoader

loaderA = DataLoader(
    TensorDataset(torch.arange(6)), batch_size=2)
loaderB = DataLoader(
    TensorDataset(torch.arange(1, 7) * 10), batch_size=2)

for a, b in product(loaderA, loaderB):
    print(a, b)

> [tensor([0, 1])] [tensor([10, 20])]
  [tensor([0, 1])] [tensor([30, 40])]
  [tensor([0, 1])] [tensor([50, 60])]
  [tensor([2, 3])] [tensor([10, 20])]
  [tensor([2, 3])] [tensor([30, 40])]
  [tensor([2, 3])] [tensor([50, 60])]
  [tensor([4, 5])] [tensor([10, 20])]
  [tensor([4, 5])] [tensor([30, 40])]
  [tensor([4, 5])] [tensor([50, 60])]