-
Notifications
You must be signed in to change notification settings - Fork 380
[MAMBA2] fix initialization for mamba2 #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| import warnings | ||
| from typing import TYPE_CHECKING | ||
|
|
||
|
|
@@ -170,11 +171,21 @@ def __init__( | |
|
|
||
| # time step projection (discretization) | ||
| # instantiate once and copy inv_dt in init_weights of PretrainedModel | ||
| self.dt_bias = nn.Parameter(torch.ones(self.num_heads)) | ||
| # hard coded for now | ||
| dt_init_floor = 1e-4 | ||
| dt = torch.exp( | ||
| torch.rand(self.num_heads) * ( | ||
| math.log(self.time_step_max) - math.log(self.time_step_min) | ||
| ) + math.log(self.time_step_min) | ||
| ) | ||
| dt = torch.clamp(dt, min=dt_init_floor) | ||
| # Inverse of softplus: https://github.com/pytorch/pytorch/issues/72759 | ||
| inv_dt = dt + torch.log(-torch.expm1(-dt)) | ||
| self.dt_bias = nn.Parameter(inv_dt) | ||
mayank31398 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # S4D real initialization. These are not discretized! | ||
| # The core is to load them, compute the discrete states, then write the updated state. Keeps the memory bounded | ||
| A = torch.arange(1, self.num_heads + 1) | ||
| A = torch.empty(self.num_heads, dtype=torch.float32).uniform_(0, 16) | ||
| self.A_log = nn.Parameter(torch.log(A)) | ||
|
Comment on lines
+188
to
189
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initialization of |
||
| self.A_log._no_weight_decay = True | ||
| self.norm = RMSNormGated( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.