The desired target doesn’t match the description:
for each row, set elements which is before 99 to 1; 0 otherwise,

since the 99 in the first row is set to 0, while the others are not.
Assuming you would like to set the value at 99 to 1, this code should work and would avoid the loop:
t2 = torch.tensor(
    [[99, 2, 1, 3, 4],
     [1, 2, 3, 99, 4],
     [4, 1, 99, 2, 3]]
)

idx = torch.cumsum((t2 == 99), 1)
idx[t2==99] = 0
res = (~idx.bool()).long()
print(res)
> tensor([[1, 0, 0, 0, 0],
          [1, 1, 1, 1, 0],
          [1, 1, 1, 0, 0]])

Depending on the shape of your tensor, it might be faster or not, so I would recommend to profile both approaches.