If you can capture the operation that you are doing in the for loop into a function, you can use the inbuilt torch.vmap() that would essentially vectorize this for you.
torch.vmap()