Kalamazooter commited on
Commit
26712aa
·
verified ·
1 Parent(s): e9f2a05

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +81 -0
README.md CHANGED
@@ -1,3 +1,84 @@
1
  ---
2
  license: apache-2.0
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ base_model: state-spaces/mamba-130m-hf
4
+ tokenizer: yhavinga/dutch-llama-tokenizer
5
+ datasets: Kalamazooter/GeminiPhiDutch
6
  ---
7
+ # A Tiny Dutch model, just-about semi-coherent
8
+
9
+ ![RatelSlang](RatelSlang-Micro.jpg)
10
+
11
+ ## Overview
12
+
13
+ An experimental fine-tune of [mamba-130m](https://hf.co/state-spaces/mamba-130m-hf) using the [GeminiPhi Dataset](https://hf.co/Kalamazooter/GeminiPhiDutch)
14
+
15
+ # Usage
16
+
17
+ You need to install `transformers` from `main` until `transformers=4.39.0` is released.
18
+ ```bash
19
+ pip install git+https://github.com/huggingface/transformers@main
20
+ ```
21
+
22
+ We also recommend you to install both `causal_conv_1d` and `mamba-ssm` using:
23
+
24
+ ```bash
25
+ pip install causal-conv1d>=1.2.0
26
+ pip install mamba-ssm
27
+ ```
28
+
29
+ If any of these two is not installed, the "eager" implementation will be used. Otherwise the more optimised `cuda` kernels will be used.
30
+
31
+ ## Generation
32
+ You can use the classic `generate` API:
33
+ **setup (For Cuda)**
34
+ ```python
35
+ from transformers import MambaConfig, MambaForCausalLM, AutoTokenizer
36
+ import torch
37
+ device = torch.device('cuda:0')
38
+ tokenizer = AutoTokenizer.from_pretrained("Kalamazooter/RatelSlang-Micro-130M")
39
+ model = MambaForCausalLM.from_pretrained("Kalamazooter/RatelSlang-Micro-130M")
40
+ model = model.to(device)
41
+ ```
42
+ **Inference**
43
+ ```python
44
+ input_ids = tokenizer("**Vraag: Ik heb 4 schapen, per schaap heb ik 3 lammetjes, hoeveel lammetjes heb ik?\n\n Antwoord:", return_tensors="pt").input_ids.to(device)
45
+ out = model.generate(input_ids, max_new_tokens=50)
46
+ print(tokenizer.batch_decode(out))
47
+ ['<s> **Vraag: Ik heb 4 schapen, per schaap heb ik 3 lammetjes, hoeveel lammetjes heb ik?\n\n Antwoord:\n\n1. Bereken het aantal lammetjes dat je hebt: 4 schapen x 3 lammetjes per schaap = 12 lammetjes\n2. Bereken het aantal lammetjes dat je hebt: 12 lam']
48
+ ```
49
+
50
+ ## PEFT finetuning example
51
+ In order to finetune using the `peft` library, it is recommend to keep the model in float32!
52
+
53
+ ```python
54
+ from datasets import load_dataset
55
+ from trl import SFTTrainer
56
+ from peft import LoraConfig
57
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
58
+ tokenizer = AutoTokenizer.from_pretrained("Kalamazooter/RatelSlang-Micro-130M")
59
+ model = AutoModelForCausalLM.from_pretrained("Kalamazooter/RatelSlang-Micro-130M")
60
+ dataset = load_dataset("Abirate/english_quotes", split="train")
61
+ training_args = TrainingArguments(
62
+ output_dir="./results",
63
+ num_train_epochs=3,
64
+ per_device_train_batch_size=4,
65
+ logging_dir='./logs',
66
+ logging_steps=10,
67
+ learning_rate=2e-3
68
+ )
69
+ lora_config = LoraConfig(
70
+ r=8,
71
+ target_modules=["x_proj", "embeddings", "in_proj", "out_proj"],
72
+ task_type="CAUSAL_LM",
73
+ bias="none"
74
+ )
75
+ trainer = SFTTrainer(
76
+ model=model,
77
+ tokenizer=tokenizer,
78
+ args=training_args,
79
+ peft_config=lora_config,
80
+ train_dataset=dataset,
81
+ dataset_text_field="quote",
82
+ )
83
+ trainer.train()
84
+ ```