Willy030125
commited on
Commit
•
0652321
1
Parent(s):
3f8335c
Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,76 @@ language:
|
|
5 |
library_name: adapter-transformers
|
6 |
tags:
|
7 |
- text-generation-inference
|
8 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
library_name: adapter-transformers
|
6 |
tags:
|
7 |
- text-generation-inference
|
8 |
+
---
|
9 |
+
# finetune-indoMMLU-Merak-7B-v3
|
10 |
+
Based on Merak-7B-v4 Mistral: https://huggingface.co/Ichsan2895/Merak-7B-v4<br>
|
11 |
+
Dataset used on Fine Tuning: https://github.com/fajri91/IndoMMLU
|
12 |
+
<br>
|
13 |
+
|
14 |
+
Some training params used:
|
15 |
+
```python
|
16 |
+
lora r=64
|
17 |
+
lora_alpha=16
|
18 |
+
lora_dropout=0.05
|
19 |
+
|
20 |
+
learning_rate = 2e-4
|
21 |
+
lr_scheduler = "constant"
|
22 |
+
optimizer = "paged_adamw_32bit"
|
23 |
+
max_seq_length = 1280
|
24 |
+
```
|
25 |
+
|
26 |
+
Inference:
|
27 |
+
```python
|
28 |
+
import torch
|
29 |
+
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig, LlamaTokenizer
|
30 |
+
from peft import PeftModel, PeftConfig
|
31 |
+
|
32 |
+
model_name = "Ichsan2895/Merak-7B-v4"
|
33 |
+
adapter_name = "Willy030125/finetune-indoMMLU-Merak-7B-v3"
|
34 |
+
|
35 |
+
bnb_config = transformers.BitsAndBytesConfig(
|
36 |
+
load_in_4bit=True,
|
37 |
+
bnb_4bit_use_double_quant=True,
|
38 |
+
bnb_4bit_quant_type="nf4",
|
39 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
40 |
+
)
|
41 |
+
|
42 |
+
model = AutoModelForCausalLM.from_pretrained(
|
43 |
+
model_name,
|
44 |
+
quantization_config=bnb_config,
|
45 |
+
device_map="auto",
|
46 |
+
trust_remote_code=True
|
47 |
+
)
|
48 |
+
|
49 |
+
model = PeftModel.from_pretrained(model_name, adapter_name)
|
50 |
+
tokenizer = LlamaTokenizer.from_pretrained(model_name)
|
51 |
+
|
52 |
+
def generate_response(question: str) -> str:
|
53 |
+
chat = [
|
54 |
+
{"role": "system", "content": "Anda adalah Merak, sebuah model kecerdasan buatan yang dilatih oleh Muhammad Ichsan. Mohon jawab pertanyaan berikut dengan benar, faktual, dan ramah."},
|
55 |
+
{"role": "user", "content": question},
|
56 |
+
]
|
57 |
+
|
58 |
+
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
59 |
+
inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=True)
|
60 |
+
|
61 |
+
with torch.no_grad():
|
62 |
+
outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"),
|
63 |
+
attention_mask=inputs.attention_mask,
|
64 |
+
eos_token_id=tokenizer.eos_token_id,
|
65 |
+
pad_token_id=tokenizer.eos_token_id,
|
66 |
+
max_new_tokens=1024)
|
67 |
+
response = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
|
68 |
+
|
69 |
+
assistant_start = f'''{question} \n assistant\n '''
|
70 |
+
response_start = response.find(assistant_start)
|
71 |
+
return response[response_start + len(assistant_start) :].strip()
|
72 |
+
|
73 |
+
prompt = """Hewan pemakan tumbuhan dinamakan ...
|
74 |
+
A. Omnivora
|
75 |
+
B. Karnivora
|
76 |
+
C. Pengurai
|
77 |
+
D. Herbivora"""
|
78 |
+
|
79 |
+
print(generate_response(prompt))
|
80 |
+
```
|