In your loop you are assigning the “last” i value to a in case inds contains duplicated values and are also overwriting already replaced values.
E.g. assume that inds contains [1, 0]: if a contains any 1s, they would be replaces with a 0 and in the next iteration all 0s would be replaced with 1s again.
Given that, I think a “vectorized” approach might be tricky, as it would not consider this sequential way.
Nevertheless, here is a potentially faster approach, which will not yield the same results, if values are not unique:
input = torch.randint(0, 5, (6,))
a = input.clone()
b = input.clone()
inds = torch.randint(0, 7, (5,))
for i, ind in enumerate(inds):
    a[a==ind] = i
    
idx = (b.unsqueeze(0) == inds.unsqueeze(1)).nonzero()
b[idx[:, 1]] = idx[:, 0]