Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
Here is a code to create this tiny model:
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
torch.set_default_dtype(torch.bfloat16)
|
| 14 |
+
|
| 15 |
+
from transformers import AutoTokenizer, AutoConfig, Lfm2MoeForCausalLM
|
| 16 |
+
|
| 17 |
+
# # === Step 1: Define tiny model config ===
|
| 18 |
+
model_id = "LiquidAI/LFM2-24B-A2B"
|
| 19 |
+
config = AutoConfig.from_pretrained(model_id)
|
| 20 |
+
|
| 21 |
+
config.num_hidden_layers = 2
|
| 22 |
+
config.layer_types = [
|
| 23 |
+
"full_attention",
|
| 24 |
+
"conv",
|
| 25 |
+
]
|
| 26 |
+
config.num_attention_heads = 4
|
| 27 |
+
config.num_key_value_heads = 4
|
| 28 |
+
config.hidden_size = 16
|
| 29 |
+
|
| 30 |
+
# === Step 2: Create model from config ===
|
| 31 |
+
model = Lfm2MoeForCausalLM(config)
|
| 32 |
+
|
| 33 |
+
# === Step 3: Load or create tokenizer ===
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 35 |
+
|
| 36 |
+
# === Step 4: Save model and tokenizer ===
|
| 37 |
+
output_dir = "./lfm2_moe"
|
| 38 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 39 |
+
model.save_pretrained(output_dir, safe_serialization=False)
|
| 40 |
+
tokenizer.save_pretrained(output_dir)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
```
|