A question about matrix A
Mamba is a great job!
After reading your paper, I noticed a slight discrepancy regarding the discrete matrix A.
In your paper: The discrete matrix A is represented as: exp(A * delta)
However, in your code: The matrix A (referred to as log A in reality) is initialized as follows:
A = repeat(
torch.arange(1, self.d_state + 1, dtype=torch.float32, device=device),
"n -> d n",
d=self.d_inner,
).contiguous()
A_log = torch.log(A) # Keeping A_log in float32
self.A_log = nn.Parameter(A_log)
Then, during inference:
A = -torch.exp(self.A_log.float()) # (d_inner, d_state)
is used. It seems like we use log(-A) for initialization but the paper says it is matrix A. (so I am confused about this)
Could you please explain why log(-A) is initialized instead of A for further computations? Is this choice made for computational efficiency or some other reason?
No the code you quoted is all about initialization and parameterization. In the CUDA code we still do A_bar = exp(A * delta). We want A to be always negative, and delta always positive. To make A negative, we parameterize it by self.A_log (which is unconstained), then set A = -exp(self.A_log). To make delta always positive, we have delta = softplus(dt + self.dt_bias).
Thanks for your reply, and it really makes sense. So, A is like a trainable Hippo Matrix in Mamaba, and that's why each element in A should be negative. Additionally, elements in delta should be positive, since this matrix is related to time (it's not possible for values to be negative in a time matrix). Does that align with your understanding?
Yes
But I'm still confused. Why should A(hippo) matrix be set to negative value. thanks.
@Liyuansongdsb , since A is a diagonal matrix, having all negative values means that its eigenvalues will all be negative. With negative eigenvalues then the system is considered stable, i.e. bounded input bounded output stable. This goes back to stuff in digital signal processing, but essentially we don't want our hidden state exploding, which would lead to the vanishing gradient problem and thus unstable training.
This is just my guess, so I could be wrong.
@Hprairie Ok, I get it now, thanks!
So, if I'm not going to continue updating the parameter A, can I directly save the value after A_log exp