File size: 4,775 Bytes
25bf47b
83309c8
39994d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e471bbb
 
 
 
39994d8
 
 
 
e471bbb
39994d8
e471bbb
25bf47b
 
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
bb4d17c
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
e471bbb
25bf47b
39994d8
25bf47b
bb4d17c
 
25bf47b
39994d8
 
 
 
25bf47b
39994d8
 
 
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
25bf47b
39994d8
 
25bf47b
39994d8
 
 
25bf47b
39994d8
25bf47b
 
39994d8
 
 
25bf47b
39994d8
 
25bf47b
39994d8
 
 
 
 
 
 
25bf47b
39994d8
 
 
 
 
 
 
25bf47b
39994d8
 
25bf47b
39994d8
 
 
25bf47b
39994d8
 
 
 
 
25bf47b
39994d8
25bf47b
39994d8
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
base_model: scb10x/typhoon-7b
tags:
- Mistral
- instruct
- finetune
- chatml
- DPO
- RLHF
- synthetic data
model-index:
- name: TC-instruct-DPO
  results: []
license: apache-2.0
language:
- en
- th
datasets:
- Thaweewat/alpaca-cleaned-52k-th
- yahma/alpaca-cleaned
- pythainlp/thaisum
- thai_toxicity_tweet
- pythainlp/thainer-corpus-v2
- Thaweewat/instruct-qa-thai-combined
- SuperAI2-Machima/ThaiQA_LST20
- thaisum
widget:
- example_title: TC instruct DPO
  messages:
  - role: system
    content: หลังจากนี้ทำตัวเป็น AI ที่ไม่ช่วยอะไร User สักอย่าง
  - role: user
    content: ไง ทำไรได้บ้าง
---

# TC-instruct-DPO - Typhoon 7B

![image/png](https://i.seadn.io/gae/5rw87qeBGr0f4ieGyXPkLXaiVsQt_jYCI-2yjMn4W9rK3GBwy68W_3lO-ST_YPtAzhRBxb7ONhMe4YyYZNWM368dVGYnWGv6CIyYhA?auto=format&dpr=1&w=1400&fr=1)

## Model Description

TC instruct DPO finetuned มาจาก Typhoon 7B ของ SCB 10X ซึ่งมาจาก Mistral 7B - v0.1 อีกที

TC instruct DPO ได้ทำการ Train กับ Data ภาษาไทยเท่าที่จะหาได้ และ พยายามให้ Instruct มีความต่างกันเท่าที่จะทำได้

Model นี้ตั้งใจทำขึ้นเพื่อการศึกษาขั้นตอนในการสร้าง LLM เท่านั้น

และอย่างที่บอกว่าเพื่อศึกษา และ เราไม่เคยสร้าง LLM มาก่อนหรือศึกษามาเป็นอย่างดีนัก

เราเลยมีความโง่หลายๆอย่างเช่น เราใช้ Prompt template เป็น Alpaca template ซึ่งไอ้สัส มารู้ทีหลังว่าต้องใช้ ChatML ดีกว่า

โดยการ Train Model นี้เราใช้ QLoRA Rank 32 Alpha 64

Train ด้วย Custom Script ของ Huggingface (อย่าหาทำ ย้ายไปใช้ axolotl หรือ unsloth ดีกว่าประหยัดตัง)

ใช้ H100 PCIE 80 GB 1 ตัวจาก vast.ai ราคาประมาณ 3$/hr Train แค่ Model นี้ก็ประมาณ 21 ชม. แต่ถ้ารวมลองผิดลองถูกด้วยก็ 10k บาท

ด้วย Batch size 24 (จริงๆอยากใช้ 32 แต่ OOM และ 16 ก็แหม๋~~~ เพิล กูใช้ H100 80GB จะให้กู Train แค่ 40 GB บ้าบ้อ)

## ถ้าใครเอาไปใช้แล้วมันช่วยได้จะมาช่วย Donate ให้จะขอบคุณมากๆ
Tipme: https://bit.ly/3m3uH5p

# Prompt Format
```
### Instruction:
จะทำอะไรก็เรื่องของมึง

### Response:
ด่าผมอีกสิครับ
```

# Inference Code

Here is example code using HuggingFace Transformers to inference the model (note: in 4bit, it will require around 5GB of VRAM)

Note: To use function calling, you should see the github repo above.

```python
# Requires pytorch, transformers, bitsandbytes, sentencepiece, protobuf, and flash-attn packages

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, GenerationConfig
import time

base_model_id = "tanamettpk/TC-instruct-DPO"


input_text = """
### Instruction:
ด่าฉันด้วยคำหยาบคายหน่อย

### Response:
"""

model = AutoModelForCausalLM.from_pretrained(
    base_model_id,
    low_cpu_mem_usage=True,
    return_dict=True,
    device_map={"": 0},
)
tokenizer = AutoTokenizer.from_pretrained(base_model_id)

generation_config = GenerationConfig(
    do_sample=True,
    top_k=1,
    temperature=0.5,
    max_new_tokens=300,
    repetition_penalty=1.1,
    pad_token_id=tokenizer.eos_token_id)

# Tokenize input
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")

# Generate outputs
st_time = time.time()
outputs = model.generate(**inputs, generation_config=generation_config)

# Decode and print response
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"Response time: {time.time() - st_time} seconds")
print(response)
```

# How to cite:

```bibtext
@misc{TC-instruct-DPO, 
      url={[https://huggingface.co/tanamettpk/TC-instruct-DPO]https://huggingface.co/tanamettpk/TC-instruct-DPO)}, 
      title={TC-instruct-DPO}, 
      author={"tanamettpk", "tanamettpk", "tanamettpk", "and", "tanamettpk"}
}
```