You need to revise your calculus.
If f(x) = x + w then the gradient of f with respect to w is 1. In this case the gradient doesn’t depend on the inputs.
If f(x) = x * w then the gradient of f with respect to w is x. In this case, we need to save the input value.