I don’t get it. S1 is a tensor. S2 is a tensor. Maybe you should copy paste the original task.
If you have a problem with the number of steps, 15 steps in my solution and 16 you need you should consider starting from the empty tensor S2.
I am novice in PyTorch. Sorry for the low quality answer.