You could use the returned unique values to index another tensor and add the counts to it:
counts = torch.zeros(4)

data1 = torch.randint(0, 4, (1000, ))
u, c = data1.unique(return_counts=True)
counts[u] += c

data2 = torch.randint(0, 3, (1000, ))
u, c = data2.unique(return_counts=True)
counts[u] += c