Oops, yes. That’s a typo. It was supposed to be x, I tried to make my code more generic.
Sorry, I left this out. The reason I have the if condition is because I reuse the same step() function for validation, except with step(optimizer=None), so that neither loss.backward() nor optimizer.step() get called.