It finds the .creator of the output and calls this method 508. Basically, it just saves the reward in the .reward attribute of the creator function. Then, when the backward method is called, the StochasticFunction class will discard the grad_output it received and pass the saved reward 188 to the backward method.
Yes, the gradient formulas are written in such a way that they negate the reward. You might not find reward.neg() there because they might have been slightly rewritten, but it’s still a gradient to be used with a descent.
You need to give autograd the first list, so that it can discover all the stochastic nodes you want to optimize. The second list can look like that because the stochastic functions don’t need any gradients (they’ll discard them anyway), so you can give them None.