Update README.md
Browse files
README.md
CHANGED
@@ -9,51 +9,117 @@ base_model: google/gemma-1.1-2b-it
|
|
9 |
model-index:
|
10 |
- name: gemma-2b-it-example-v1
|
11 |
results: []
|
|
|
|
|
12 |
---
|
13 |
|
14 |
-
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
15 |
-
should probably proofread and complete it, then remove this comment. -->
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
model-index:
|
10 |
- name: gemma-2b-it-example-v1
|
11 |
results: []
|
12 |
+
language:
|
13 |
+
- ko
|
14 |
---
|
15 |
|
|
|
|
|
16 |
|
17 |
+
## Model Description
|
18 |
+
**git hub** : [https://github.com/aiqwe/instruction-tuning-with-rag-example](https://github.com/aiqwe/instruction-tuning-with-rag-example)
|
19 |
+
Instruction Tuning์ ํ์ต์ ์ํด ์์๋ก ํ์ตํ ๋ชจ๋ธ์
๋๋ค.
|
20 |
+
[gemma-2b-it](https://huggingface.co/google/gemma-2b-it) ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก ์ฝ 1๋ง๊ฐ์ ๋ถ๋์ฐ ๊ด๋ จ Instruction ๋ฐ์ดํฐ์
์ ํ์ตํ์์ต๋๋ค.
|
21 |
+
ํ์ต ์ฝ๋๋ ์ git hub๋ฅผ ์ฐธ์กฐํด์ฃผ์ธ์.
|
22 |
+
|
23 |
+
## Usage
|
24 |
+
### Inference on GPU example
|
25 |
+
```python
|
26 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
27 |
+
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it")
|
29 |
+
model = AutoModelForCausalLM.from_pretrained(
|
30 |
+
"aiqwe/gemma-2b-it-example-v1",
|
31 |
+
device_map="cuda",
|
32 |
+
torch_dtype=torch.bfloat16,
|
33 |
+
attn_implementation="flash_attention_2"
|
34 |
+
)
|
35 |
+
|
36 |
+
input_text = "์ํํธ ์ฌ๊ฑด์ถ์ ๋ํด ์๋ ค์ค."
|
37 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
38 |
+
|
39 |
+
outputs = model.generate(**input_ids, max_new_tokens=512)
|
40 |
+
print(tokenizer.decode(outputs[0]))
|
41 |
+
|
42 |
+
```
|
43 |
+
|
44 |
+
|
45 |
+
### Inference on CPU example
|
46 |
+
```python
|
47 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
48 |
+
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it")
|
50 |
+
model = AutoModelForCausalLM.from_pretrained(
|
51 |
+
"aiqwe/gemma-2b-it-example-v1",
|
52 |
+
device_map="cpu",
|
53 |
+
torch_dtype=torch.bfloat16
|
54 |
+
)
|
55 |
+
|
56 |
+
input_text = "์ํํธ ์ฌ๊ฑด์ถ์ ๋ํด ์๋ ค์ค."
|
57 |
+
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
58 |
+
|
59 |
+
outputs = model.generate(**input_ids, max_new_tokens=512)
|
60 |
+
print(tokenizer.decode(outputs[0]))
|
61 |
+
```
|
62 |
+
|
63 |
+
### Inference on GPU with embedded function example
|
64 |
+
๋ด์ฅ๋ ํจ์๋ก ๋ค์ด๋ฒ ๊ฒ์ API๋ฅผ ํตํด RAG๋ฅผ ์ง์๋ฐ์ต๋๋ค.
|
65 |
+
```python
|
66 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
67 |
+
from utils import generate
|
68 |
+
|
69 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it")
|
70 |
+
model = AutoModelForCausalLM.from_pretrained(
|
71 |
+
"aiqwe/gemma-2b-it-example-v1",
|
72 |
+
device_map="cuda",
|
73 |
+
torch_dtype=torch.bfloat16,
|
74 |
+
attn_implementation="flash_attention_2"
|
75 |
+
)
|
76 |
+
|
77 |
+
rag_config = {
|
78 |
+
"api_client_id": userdata.get('NAVER_API_ID'),
|
79 |
+
"api_client_secret": userdata.get('NAVER_API_SECRET')
|
80 |
+
}
|
81 |
+
completion = generate(
|
82 |
+
model=model,
|
83 |
+
tokenizer=tokenizer,
|
84 |
+
query=query,
|
85 |
+
max_new_tokens=512,
|
86 |
+
rag=True,
|
87 |
+
rag_config=rag_config
|
88 |
+
)
|
89 |
+
print(completion)
|
90 |
+
```
|
91 |
+
|
92 |
+
## Chat Template
|
93 |
+
Gemma ๋ชจ๋ธ์ Chat Template์ ์ฌ์ฉํฉ๋๋ค.
|
94 |
+
[gemma-2b-it Chat Template](https://huggingface.co/google/gemma-2b-it#chat-template)
|
95 |
+
```python
|
96 |
+
input_text = "์ํํธ ์ฌ๊ฑด์ถ์ ๋ํด ์๋ ค์ค."
|
97 |
+
|
98 |
+
input_text = tokenizer.apply_chat_template(
|
99 |
+
conversation=[
|
100 |
+
{"role": "user", "content": input_text}
|
101 |
+
],
|
102 |
+
add_generate_prompt=True,
|
103 |
+
return_tensors="pt"
|
104 |
+
).to(model.device)
|
105 |
+
|
106 |
+
outputs = model.generate(input_text, max_new_tokens=512, repetition_penalty = 1.5)
|
107 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=False))
|
108 |
+
```
|
109 |
+
|
110 |
+
## Training information
|
111 |
+
ํ์ต์ ๊ตฌ๊ธ ์ฝ๋ฉ L4 Single GPU๋ฅผ ํ์ฉํ์์ต๋๋ค.
|
112 |
+
|
113 |
+
| ๊ตฌ๋ถ | ๋ด์ฉ |
|
114 |
+
|-----------------------------|------------------|
|
115 |
+
| ํ๊ฒฝ | Google Colab |
|
116 |
+
| GPU | L4(22.5GB) |
|
117 |
+
| ์ฌ์ฉ VRAM | ์ฝ 13.8GB |
|
118 |
+
| dtype | bfloat16 |
|
119 |
+
| Attention | flash attention2 |
|
120 |
+
| Tuning | Lora(r=4, alpha=32) |
|
121 |
+
| Learning Rate | 1e-4 |
|
122 |
+
| LRScheduler | Cosine |
|
123 |
+
| Optimizer | adamw_torch_fused |
|
124 |
+
| batch_size | 4 |
|
125 |
+
| gradient_accumulation_steps | 2 |
|