The correction you suggested is inside the for loop but the error (RuntimeError: All input tensors must be on the same device. Received cuda:0 and cpu) is at the for loop statement.
Also, I just tried what you suggested, but it’s throwing the same error.