Later, GDN2 attempted to generalize the update matrix to , and a similar choice appeared in RWKV7. However, such a generalization can bring about new instability issues. In this post, I provide a brief analysis of this.
The general form of GDN2 is
where , , is a diagonal matrix whose diagonal elements are usually restricted to , representing the forgetting matrix. KDA corresponds to the special case where , and GDN further corresponds to the special case where .
When we unroll the recurrence, will involve the cumulative product of , so to ensure numerical stability, we should hope that
where denotes the spectral norm. Since is a diagonal matrix and its diagonal elements are already in , it satisfies ; thus, a sufficient condition for the above inequality is
Unfortunately, as we will see next, when are not collinear (which is precisely the regime GDN2 hopes to expand into), the above inequality can never hold.
For simplicity, the discussion below omits the subscript , and assumes that are already normalized (otherwise we can always absorb into ). We have
This conclusion is probably the most tedious part of this article, so we defer its proof to the end. Since are already normalized, we have , and when and , we have
That is to say, as long as and , no matter how one tunes it, has a spectral norm strictly greater than 1! More precisely, we have
However, if , then it degenerates to KDA, losing the generalization significance of GDN2. On the other hand, when , is definitely greater than 1, which means the stability of GDN2 is not guaranteed. How can we break this deadlock?
Fortunately, we still have the forget gate matrix . Since it is restricted to , their product will very likely have a spectral norm less than 1, so training in practice does not necessarily fail. However, this is merely probabilistic, not a theoretical guarantee.
The most ideal approach is to directly compute 's spectral norm and then perform operations like spectral clipping on it; however, for a general , there is no general closed-form solution for this matrix's spectral norm.
Fortunately, has an analytical solution for its spectral norm, so we can settle for the next best thing and use its spectral norm to perform a clipping operation on :
where . This way, we will only modify 's diagonal elements that are greater than . Since in practice is usually not large, on average will not be significantly less than 1, so the scope of modification will not be very broad; that is, with modifications as small and simple as possible, the stability of GDN2 is guaranteed.
It is worth pointing out that both and are merely token-wise operations that can be kept outside the RNN operator, and also has a closed-form solution, so after fusion, it will hardly affect efficiency, making it a modification with minimal mental overhead.
Finally, we supplement the proof of Eq. . Without loss of generality, assume that are not collinear, and orthogonalize them as , , where . Let , and extend it to a complete orthonormal basis , and define .
For , any vector orthogonal to both satisfies and , so and , whence
Since orthogonal transformations do not change singular values, 's non-trivial singular values can only come from the matrix , which by direct calculation yields matrices have a rather neat direct calculation method for their singular values. Let the two singular values be . Using the relationship between singular values, the Frobenius norm, and the determinant, we obtain
We are mainly interested in , which is the average of the two terms. At this point, the absolute value can be dropped (since both signs are evaluated anyway), which finally simplifies to
We have previously proved that it is not less than 1, so is the spectral norm.
In this post, we analyzed the stability issues that may arise in GDN2 after generalizing the update matrix from to , and discussed the corresponding mitigation strategies.