Willy030125 commited on
Commit
67c6da2
1 Parent(s): 4172357

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -1
README.md CHANGED
@@ -5,4 +5,75 @@ 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-v2
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 = "cosine"
22
+ max_seq_length = 2048
23
+ ```
24
+
25
+ Inference:
26
+ ```python
27
+ import torch
28
+ from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig, LlamaTokenizer
29
+ from peft import PeftModel, PeftConfig
30
+
31
+ model_name = "Ichsan2895/Merak-7B-v4"
32
+ adapter_name = "Willy030125/finetune-indoMMLU-Merak-7B-v2"
33
+
34
+ bnb_config = transformers.BitsAndBytesConfig(
35
+ load_in_4bit=True,
36
+ bnb_4bit_use_double_quant=True,
37
+ bnb_4bit_quant_type="nf4",
38
+ bnb_4bit_compute_dtype=torch.bfloat16
39
+ )
40
+
41
+ model = AutoModelForCausalLM.from_pretrained(
42
+ model_name,
43
+ quantization_config=bnb_config,
44
+ device_map="auto",
45
+ trust_remote_code=True
46
+ )
47
+
48
+ model = PeftModel.from_pretrained(model_name, adapter_name)
49
+ tokenizer = LlamaTokenizer.from_pretrained(model_name)
50
+
51
+ def generate_response(question: str) -> str:
52
+ chat = [
53
+ {"role": "system", "content": "Anda adalah Merak, sebuah model kecerdasan buatan yang dilatih oleh Muhammad Ichsan. Mohon jawab pertanyaan berikut dengan benar, faktual, dan ramah."},
54
+ {"role": "user", "content": question},
55
+ ]
56
+
57
+ prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
58
+ inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=True)
59
+
60
+ with torch.no_grad():
61
+ outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"),
62
+ attention_mask=inputs.attention_mask,
63
+ eos_token_id=tokenizer.eos_token_id,
64
+ pad_token_id=tokenizer.eos_token_id,
65
+ max_new_tokens=1024)
66
+ response = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
67
+
68
+ assistant_start = f'''{question} \n assistant\n '''
69
+ response_start = response.find(assistant_start)
70
+ return response[response_start + len(assistant_start) :].strip()
71
+
72
+ prompt = """Hewan pemakan tumbuhan dinamakan ...
73
+ A. Omnivora
74
+ B. Karnivora
75
+ C. Pengurai
76
+ D. Herbivora"""
77
+
78
+ print(generate_response(prompt))
79
+ ```