mjschock commited on
Commit
f05cba2
·
verified ·
1 Parent(s): 4e5b657

Upload model

Browse files
Files changed (2) hide show
  1. config.json +6 -1
  2. modeling_mamba.py +5 -2
config.json CHANGED
@@ -1,6 +1,10 @@
1
  {
 
 
 
2
  "auto_map": {
3
- "AutoConfig": "configuration_mamba.MambaConfig"
 
4
  },
5
  "bias": false,
6
  "conv_bias": true,
@@ -14,6 +18,7 @@
14
  "model_type": "mamba",
15
  "n_layer": 24,
16
  "pad_vocab_size_multiple": 8,
 
17
  "transformers_version": "4.37.2",
18
  "vocab_size": 50280
19
  }
 
1
  {
2
+ "architectures": [
3
+ "MambaModelForCausalLM"
4
+ ],
5
  "auto_map": {
6
+ "AutoConfig": "configuration_mamba.MambaConfig",
7
+ "AutoModelForCausalLM": "modeling_mamba.MambaModelForCausalLM"
8
  },
9
  "bias": false,
10
  "conv_bias": true,
 
18
  "model_type": "mamba",
19
  "n_layer": 24,
20
  "pad_vocab_size_multiple": 8,
21
+ "torch_dtype": "float32",
22
  "transformers_version": "4.37.2",
23
  "vocab_size": 50280
24
  }
modeling_mamba.py CHANGED
@@ -187,7 +187,7 @@ class Mamba(nn.Module):
187
 
188
 
189
  class MambaBlock(nn.Module):
190
- def __init__(self, config: MambaConfig):
191
  """A single Mamba block, as described in Figure 3 in Section 3.4 in the Mamba paper [1]."""
192
  super().__init__()
193
  self.config = config
@@ -195,6 +195,9 @@ class MambaBlock(nn.Module):
195
  self.mixer = Mamba(config)
196
  self.norm = MambaRMSNorm(config.d_model)
197
 
 
 
 
198
 
199
  class MambaPreTrainedModel(PreTrainedModel):
200
  config_class = MambaConfig
@@ -226,7 +229,7 @@ class MambaModel(MambaPreTrainedModel):
226
  self.config = config
227
 
228
  self.embedding = nn.Embedding(config.vocab_size, config.d_model)
229
- self.layers = nn.ModuleList([MambaBlock(config) for _ in range(config.n_layer)])
230
  self.norm_f = MambaRMSNorm(config.d_model)
231
 
232
  self.gradient_checkpointing = False
 
187
 
188
 
189
  class MambaBlock(nn.Module):
190
+ def __init__(self, config: MambaConfig, layer_idx: int = 0):
191
  """A single Mamba block, as described in Figure 3 in Section 3.4 in the Mamba paper [1]."""
192
  super().__init__()
193
  self.config = config
 
195
  self.mixer = Mamba(config)
196
  self.norm = MambaRMSNorm(config.d_model)
197
 
198
+ def forward(self, x):
199
+ return self.norm(self.mixer(x))
200
+
201
 
202
  class MambaPreTrainedModel(PreTrainedModel):
203
  config_class = MambaConfig
 
229
  self.config = config
230
 
231
  self.embedding = nn.Embedding(config.vocab_size, config.d_model)
232
+ self.layers = nn.ModuleList([MambaBlock(config, layer_idx) for layer_idx in range(config.n_layer)])
233
  self.norm_f = MambaRMSNorm(config.d_model)
234
 
235
  self.gradient_checkpointing = False