Two possible ways:

Use batch matrix multiplication (or einsum or whatever).
Instead of overwriting s[i], collect the results in a list and do torch.stack on it after the for loop.

Best regards
Thomas