-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34254e1
commit 8233613
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dataclasses import dataclass | ||
from mamba_ssm.models.config_mamba import MambaConfig | ||
from mamba_ssm.models.mixer_seq_simple import MambaLMHeadModel | ||
import torch.nn.functional as F | ||
|
||
@dataclass | ||
class MambaArgs(MambaConfig): | ||
pass | ||
|
||
|
||
class Mamba(MambaLMHeadModel): | ||
|
||
def __init__(self, params) -> None: | ||
super().__init__(params) | ||
|
||
def forward(self, input_ids, target_ids=None): | ||
""" | ||
"position_ids" is just to be compatible with Transformer generation. We don't use it. | ||
num_last_tokens: if > 0, only return the logits for the last n tokens | ||
""" | ||
hidden_states = self.backbone(input_ids) | ||
logits = self.lm_head(hidden_states) | ||
self.last_loss = F.cross_entropy(logits.view(-1, logits.size(-1)), target_ids.view(-1), ignore_index=-1) | ||
|
||
return logits |