torch.unique with a dim argument will return the unique tensors in the specified dimension, while dim=None will treat the tensor as a flattened tensor.
Have a look at this example:
x = torch.tensor([[0, 0, 0],
                  [0, 0, 1],
                  [0, 0, 0],
                  [0 ,0, 1]])

print(torch.unique(x, dim=0))
> tensor([[0, 0, 0],
        [0, 0, 1]])
print(torch.unique(x, dim=1))
> tensor([[0, 0],
        [0, 1],
        [0, 0],
        [0, 1]])
print(torch.unique(x))
> tensor([0, 1])

If you want to get the flattened unique values for each row, you would need to use a loop, as torch.unique won’t add padding to the result.