Skip to content

Commit

Permalink
Adding a Mamba Class
Browse files Browse the repository at this point in the history
  • Loading branch information
SrGonao authored and jettjaniak committed Feb 26, 2024
1 parent 34254e1 commit 8233613
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/delphi/train/mamba.py
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

0 comments on commit 8233613

Please sign in to comment.