A nice question about gradients!
Let's break it down step by step:
f1(x) = g(rms_norm(W * x))
f2(x) = g(rms_norm(100 * W * x))
To compute the gradients of f1 and f2 with respect to W, we'll apply the chain rule.
Gradient of f1 with respect to W:
Using the chain rule, we can write:
∂f1/∂W = ∂g/∂(rms_norm(W * x)) * ∂(rms_norm(W * x))/∂(W * x) * ∂(W * x)/∂W
Since rms_norm is a scalar function, we can write:
∂(rms_norm(W * x))/∂(W * x) = (1/rms_norm(W * x)) * (W * x) / ||W * x||
where ||.|| denotes the Euclidean norm.
Now, ∂(W * x)/∂W = x^T (the transpose of x).
So, putting it all together:
∂f1/∂W = ∂g/∂(rms_norm(W * x)) * (1/rms_norm(W * x)) * (W * x) / ||W * x|| * x^T
Gradient of f2 with respect to W:
Similarly, we can write:
∂f2/∂W = ∂g/∂(rms_norm(100 * W * x)) * ∂(rms_norm(100 * W * x))/∂(100 * W * x) * ∂(100 * W * x)/∂W
Notice that ∂(100 * W * x)/∂W = 100 * x^T.
Now, ∂(rms_norm(100 * W * x))/∂(100 * W * x) = (1/rms_norm(100 * W * x)) * (100 * W * x) / ||100 * W * x||
Since rms_norm is a scalar function, we can simplify:
rms_norm(100 * W * x) = 100 * rms_norm(W * x)
and
||100 * W * x|| = 100 * ||W * x||
So, we can rewrite:
∂(rms_norm(100 * W * x))/∂(100 * W * x) = (1/(100 * rms_norm(W * x))) * (100 * W * x) / (100 * ||W * x||)
Simplifying further:
∂(rms_norm(100 * W * x))/∂(100 * W * x) = (1/rms_norm(W * x)) * (W * x) / ||W * x||
Now, putting it all together:
∂f2/∂W = ∂g/∂(rms_norm(100 * W * x)) * (1/rms_norm(W * x)) * (W * x) / ||W * x|| * 100 * x^T
Comparison:
Comparing the gradients of f1 and f2 with respect to W, we can see that:
∂f2/∂W = 100 * ∂f1/∂W
if and only if:
∂g/∂(rms_norm(100 * W * x)) = ∂g/∂(rms_norm(W * x))
This condition is not necessarily true, since g is a function of the input, and the inputs to g are different in f1 and f2.
However, if g is a linear function, or if the input to g is scaled in a way that doesn't affect the gradient (e.g., g is a ReLU function), then the condition might hold.
In general, though, the gradients of f1 and f2 with respect to W will not be the same.
So, to answer your question: no, the gradients of f1 and f2 with respect to W will not be the same, unless some specific conditions are met.