RichardErkhov
commited on
Commit
โข
855e324
1
Parent(s):
3ae3443
uploaded readme
Browse files
README.md
ADDED
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Quantization made by Richard Erkhov.
|
2 |
+
|
3 |
+
[Github](https://github.com/RichardErkhov)
|
4 |
+
|
5 |
+
[Discord](https://discord.gg/pvy7H8DZMG)
|
6 |
+
|
7 |
+
[Request more models](https://github.com/RichardErkhov/quant_request)
|
8 |
+
|
9 |
+
|
10 |
+
ko-gemma-2-9b-it - bnb 4bits
|
11 |
+
- Model creator: https://huggingface.co/rtzr/
|
12 |
+
- Original model: https://huggingface.co/rtzr/ko-gemma-2-9b-it/
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
Original model description:
|
18 |
+
---
|
19 |
+
license: gemma
|
20 |
+
library_name: transformers
|
21 |
+
pipeline_tag: text-generation
|
22 |
+
extra_gated_heading: Access Gemma on Hugging Face
|
23 |
+
extra_gated_prompt: >-
|
24 |
+
To access Gemma on Hugging Face, youโre required to review and agree to
|
25 |
+
Googleโs usage license. To do this, please ensure youโre logged in to Hugging
|
26 |
+
Face and click below. Requests are processed immediately.
|
27 |
+
extra_gated_button_content: Acknowledge license
|
28 |
+
tags:
|
29 |
+
- conversational
|
30 |
+
base_model:
|
31 |
+
- google/gemma-2-9b
|
32 |
+
language:
|
33 |
+
- ko
|
34 |
+
---
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
## Model Details
|
39 |
+
|
40 |
+
### Ko-Gemma-2-9B-IT
|
41 |
+
|
42 |
+
**[Ko-Gemma-2-9B-IT](https://huggingface.co/rtzr/ko-gemma-2-9b-it)** is a Korean-language conversational model that is part of the Gemma family of models. It is a text-to-text, decoder-only large language model, available in Korean. We fine-tuned this model on a carefully curated high-quality dataset using Supervised Fine-Tuning (SFT). And we use [Direct Preference Optimization](https://arxiv.org/abs/2305.18290) training specifically for Human Feedback. The datasets include:
|
43 |
+
|
44 |
+
- [Orca-Math](https://huggingface.co/datasets/kuotient/orca-math-korean-dpo-pairs)
|
45 |
+
- [dpo-mix-7k](https://huggingface.co/datasets/argilla/dpo-mix-7k)
|
46 |
+
|
47 |
+
Some of these datasets were partially used and translated for training. In particular, a lot of repetition occurred during the translation process, so preprocessing was performed based on N-gram.
|
48 |
+
|
49 |
+
#### *Inputs and outputs*
|
50 |
+
|
51 |
+
- **Input:** Text string, such as a question, a prompt, or a document to be summarized.
|
52 |
+
- **Output:** Generated Korean-language text in response to the input, such as an answer to a question, or a summary of a document.
|
53 |
+
|
54 |
+
### Google Gemma 2
|
55 |
+
|
56 |
+
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
57 |
+
built from the same research and technology used to create the Gemini models.
|
58 |
+
They are text-to-text, decoder-only large language models, available in English,
|
59 |
+
with open weights for both pre-trained variants and instruction-tuned variants.
|
60 |
+
Gemma models are well-suited for a variety of text generation tasks, including
|
61 |
+
question answering, summarization, and reasoning. Their relatively small size
|
62 |
+
makes it possible to deploy them in environments with limited resources such as
|
63 |
+
a laptop, desktop or your own cloud infrastructure, democratizing access to
|
64 |
+
state of the art AI models and helping foster innovation for everyone.
|
65 |
+
|
66 |
+
## Benchmark Scores
|
67 |
+
|
68 |
+
We evaluated it internally using [LogicKor](https://github.com/instructkr/LogicKor) code. While the public LogicKor code is assessed as GPT-4, our internal evaluation was conducted as GPT-4o. Public scores will be added as they are released. The scores below include only 0-shot evaluations.
|
69 |
+
|
70 |
+
| Model | Math | Reasoning | Writing | Coding | Understanding | Grammar | Single ALL | Multi ALL | Overall |
|
71 |
+
|:---------:|:-----:|:------:|:-----:|:-----:|:----:|:-----:|:-----:|:-----:|:----:|
|
72 |
+
| [rtzr/ko-gemma-2-9b-it](https://huggingface.co/rtzr/ko-gemma-2-9b-it) | 8.71 / 8.00 | 9.14 / 8.00 | 9.43 / 9.29 | 9.00 / 9.43 | 9.57 / 9.86 | 7.14 / 5.00 | 8.83 | 8.26 | 8.55 |
|
73 |
+
| [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) | 8.57 / 7.71 | 8.86 / 7.00 | 9.29 / 9.29 | 9.29 / 9.57 | 8.57 / 8.29 | 6.86 / 3.86 | 8.57 | 7.62 | 8.10 |
|
74 |
+
| [MLP-KTLim/llama-3-Korean-Bllossom-8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B) | 6.43 / 5.71 | 6.86 / 5.14 | 9.14 / 8.57 | 8.29 / 8.14 | 8.43 / 9.29 | 5.71 / 5.29 | 7.48 | 7.02 | 7.25 |
|
75 |
+
| [yanolja/EEVE-Korean-Instruct-10.8B-v1.0](https://huggingface.co/yanolja/EEVE-Korean-Instruct-10.8B-v1.0) | 5.57 / 4.29 | 8.14 / 5.14 | 8.29 / 6.29 | 6.43 / 7.86 | 9.29 / 8.57 | 6.57 / 3.71 | 7.38 | 5.98 | 6.68 |
|
76 |
+
| [allganize/Llama-3-Alpha-Ko-8B-Instruct](https://huggingface.co/allganize/Llama-3-Alpha-Ko-8B-Instruct) | 4.57 / 3.00 | 6.86 / 6.43 | 7.43 / 6.71 | 8.43 / 8.43| 7.71 / 8.71 | 6.71 / 4.43 | 6.95 | 6.29 | 6.62 |
|
77 |
+
|
78 |
+
## Usage
|
79 |
+
|
80 |
+
### Install Dependencies
|
81 |
+
|
82 |
+
You must install transformers >= 4.42.3 for gemma2 models.
|
83 |
+
|
84 |
+
```bash
|
85 |
+
pip install transformers==4.42.3 accelerate
|
86 |
+
```
|
87 |
+
|
88 |
+
### Python code with Pipeline
|
89 |
+
|
90 |
+
```python
|
91 |
+
import transformers
|
92 |
+
import torch
|
93 |
+
|
94 |
+
|
95 |
+
model_id = "rtzr/ko-gemma-2-9b-it"
|
96 |
+
|
97 |
+
pipeline = transformers.pipeline(
|
98 |
+
"text-generation",
|
99 |
+
model=model_id,
|
100 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
101 |
+
device_map="auto",
|
102 |
+
)
|
103 |
+
|
104 |
+
pipeline.model.eval()
|
105 |
+
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
106 |
+
|
107 |
+
messages = [
|
108 |
+
{"role": "user", "content": f"{instruction}"}
|
109 |
+
]
|
110 |
+
|
111 |
+
prompt = pipeline.tokenizer.apply_chat_template(
|
112 |
+
messages,
|
113 |
+
tokenize=False,
|
114 |
+
add_generation_prompt=True
|
115 |
+
)
|
116 |
+
|
117 |
+
terminators = [
|
118 |
+
pipeline.tokenizer.eos_token_id,
|
119 |
+
pipeline.tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
120 |
+
]
|
121 |
+
|
122 |
+
outputs = pipeline(
|
123 |
+
prompt,
|
124 |
+
max_new_tokens=2048,
|
125 |
+
eos_token_id=terminators,
|
126 |
+
do_sample=True,
|
127 |
+
temperature=0.6,
|
128 |
+
top_p=0.9,
|
129 |
+
)
|
130 |
+
|
131 |
+
print(outputs[0]["generated_text"][len(prompt):])
|
132 |
+
```
|
133 |
+
|
134 |
+
```markdown
|
135 |
+
์์ธ์ ์ญ์ฌ, ๋ฌธํ, ํ๋์ฑ์ด ์กฐํ๋ฅผ ์ด๋ฃฌ ๋งค๋ ฅ์ ์ธ ๋์์
๋๋ค. ์ฌ๊ธฐ์ ์ฆ๊ธธ ์ ์๋ ๋ค์ํ ๊ด๊ด์ง์ ๋ช
์๋ฅผ ์๊ฐํฉ๋๋ค. ๋ค์์ ์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค 3๊ฐ์ง์
๋๋ค.
|
136 |
+
|
137 |
+
**1. ์ญ์ฌ์ ๋ฌธํ๋ฅผ ๋๋ฌ์ผ ํ๊ตญ๊ด๊ด์ฝ์ค**
|
138 |
+
|
139 |
+
1. **๊ฒฝ๋ณต๊ถ**: ์กฐ์ ์๋์ ์
์ฅํ ์๊ถ์ ๋ง๋ฝํ ์ ์๋ ๊ณณ์
๋๋ค. ํนํ ๋งค๋
๋ด์ ์ด๋ฆฌ๋ '์ถ์ถ์ฐํ'๋ ๊ฒฝ๋ณต๊ถ์ ์๋ฆ๋ค์์ ๋์ฑ ๋๋ณด์ด๊ฒ ํฉ๋๋ค.
|
140 |
+
2. **๋ถ์ด ํ์ฅ๋ง์**: ๊ณ ํ์ค๋ฌ์ด ํ์ฅ์ด ๋ชจ์ฌ์๋ ๊ณณ์ผ๋ก, ์ ํต ๋ฌธํ ์ฒดํ์ด ๊ฐ๋ฅํฉ๋๋ค. '๋ถ์ด ํ์ฅ๋ง์ ๋ฌธํ์ฒดํ๊ด'์์๋ ํ๋ณต ์ฒดํ๋ถํฐ ์ข
์ด๋งํ, ํ๊ธ ์ฐ๊ธฐ ๋ฑ ๋ค์ํ ํ๋ก๊ทธ๋จ์ด ์ค๋น๋์ด ์์ต๋๋ค.
|
141 |
+
3. **์ธ์ฌ๋**: ์์ , ๋ฏธ์ ๊ด, ํ์๋น์ด ๋ง์ ๊ณณ์
๋๋ค. ํนํ '์ธ์ฌ๋ ๋ฌธํ๊ด'์์๋ ์์ธ์ ์ญ์ฌ์ ๋ฌธํ๋ฅผ ์ดํดํ๋ ๋ฐ ๋์์ด ๋๋ ์ ์๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
|
142 |
+
4. **๊ดํ๋ฌธ** ๋ฐ **๋ช
๋**: ํ๋์ ์ธ ์ผํ๊ณผ ๋ ์คํ ๋์ด ์ฆ๋นํ ๊ณณ์
๋๋ค. ๊ดํ๋ฌธ์ ํนํ ์ ์์ด๋ค์ด ๋ง์ ๊ณณ์ผ๋ก, ์คํธ๋ฆฌํธ ํจ์
์ ๊ด์ฐฐํ๊ฑฐ๋ ๋ฐค๊ฑฐ๋ฆฌ์์ ํ๊ธฐ๋ฅผ ๋๋ ์ ์์ต๋๋ค.
|
143 |
+
|
144 |
+
**2. ๋์์ ๋ชจ์ต์ ๋ฐ๋ผ๋ณด๋ ๋ทฐํฌ์ด ์ฝ์ค**
|
145 |
+
|
146 |
+
1. **๋จ์ฐํ์**: ์์ธ์ ์์ง์ ์ธ ๊ฑด๋ฌผ๋ก, ๊ผญ๋๊ธฐ์์ ํผ์ณ์ง๋ 360๋์ ๊ฒฝ์น๊ฐ ์๋๋ค. ํนํ ๋ฐค์ด ๋๋ฉด ์กฐ๋ช
์ด ์ด์ฐ๋ฌ์ ธ ๋์ฑ ์๋ฆ๋ค์์ง๋๋ค.
|
147 |
+
2. **์์ธํ์**: ๋จ์ฐํ์์ ๋น์ทํ ์์น๋ก, ๋์ด๊ฐ ๋ ๋๊ธฐ ๋๋ฌธ์ ๋ ๋์ ์ ๋ง์ ๋ณผ ์ ์์ต๋๋ค. ์์ธํ์ ๋ด๋ถ์๋ ๋ค์ํ ์ ์๊ด๊ณผ ๋ ์คํ ๋๋ ์์ต๋๋ค.
|
148 |
+
3. **๋ถ์
์ฐ**: ์์ธ์ ์ค์ฌ๋ถ์ ์์นํ ์ฐ์ผ๋ก, ์์ธ์ ๊ฒฝ์น๋ฅผ ์กฐ๊ธ ๋ค๋ฅธ ๊ด์ ์์ ๋ณผ ์ ์์ต๋๋ค. ํนํ ๋ถ์
์ฐ ์ ์์ธ ๋ถ์
์ฌ์์๋ ์ข์ ์ ๋ง์ ๋ณผ ์ ์์ต๋๋ค.
|
149 |
+
4. **์์ธ์ฒ**: ๋
น์ง ๊ณต๊ฐ์ผ๋ก, ๋์์ ํผ์กํจ์์ ๋ฒ์ด๋ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, ์์ธ์ฒ ๋ด๋ถ์๋ '์์ธ์ฒ ์ํธํ๋ ์ ํธ'๋ผ๋ ๊ณต๊ฐ์ด ์์ด ์์ ๊ณผ ์์ฐ์ ํจ๊ป ์ฒดํํ ์ ์์ต๋๋ค.
|
150 |
+
|
151 |
+
**3. ํ๋ ๋ฌธํ๋ฅผ ๋ง๋๋ ์ฝ์ค**
|
152 |
+
|
153 |
+
1. **์ผ์ฑ๋**: ํ๋ ๋ฏธ์ ๊ด์ด ๋ง์ ๊ณณ์ผ๋ก, '์ผ์ฑ ๋ฏธ์ ๊ด', '์๋ชจ๋ฆฌ์นด๋์ค ๊ฐค๋ฌ๋ฆฌ' ๋ฑ์ด ์์ต๋๋ค. ๋ํ, '์ฝ์์ค'๋ '์ํฌ์นด๋กํฌ์ค' ๋ฑ์ ๋ช
์๋ ๊ฐ๊น์ด ๊ณณ์ ์์ต๋๋ค.
|
154 |
+
2. **์ดํ์**: ์ธ๊ตญ์ธ๋ค์ด ๋ง์ ๊ณณ์ผ๋ก, ๋ค์ํ ์ธ๊ตญ ์์์ ์ฆ๊ธธ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, '์ดํ์ ๊ธ๋ก์ปฌ๋ฌธํ์ผํฐ'์์๋ ์ธ๊ณ ๊ฐ๊ตญ์ ๋ฌธํ ์ฒดํ์ด ๊ฐ๋ฅํฉ๋๋ค.
|
155 |
+
3. **ํ๋**: ์ ์์ด๋ค์ ๋ฌธํ๊ฐ ๋์น๋ ๊ณณ์
๋๋ค. 'ํ๋ ๋กค๋งํ'์ ํนํ ๋ง์ ์ฌ๋๋ค์ด ๋ฐฉ๋ฌธํ๋ ๊ณณ์
๋๋ค. ๋ํ, 'ํ๋ ์์ ๊ฑฐ๋ฆฌ'์์๋ ๋
์์ ๋ฌธํ๋ฅผ ๋ง๋ ์ ์์ต๋๋ค.
|
156 |
+
4. **๊ฐ๋จ**: ์์ธ์ ํ๋์ ๋ชจ์ต์ ์ ๋ณด์ฌ์ฃผ๋ ๊ณณ์
๋๋ค. '๊ฐ๋จ์ญ'์ ์ค์ฌ์ผ๋ก ๋ง์ ๊ณ ๊ธ ์ผํ๋ชฐ๊ณผ ๋ ์คํ ๋์ด ์์ต๋๋ค.
|
157 |
+
|
158 |
+
์ด๋ฌํ ์ฝ์ค๋ฅผ ํตํด ์์ธ์ ๋ค์ํ ๋ชจ์ต์ ํ ๋ฒ์ ๋ง๋๋ณผ ์ ์์ ๊ฑฐ์์. ๊ฐ์์ ์ทจํฅ์ ๋ง์ถฐ ์ฝ์ค๋ฅผ ์กฐ์ ํ์๋ฉด ์ข๊ฒ ์ต๋๋ค. ์ฆ๊ฑฐ์ด ์ฌํ ๋์ธ์!
|
159 |
+
```
|
160 |
+
|
161 |
+
### Python code with AutoModel
|
162 |
+
|
163 |
+
```python
|
164 |
+
import os
|
165 |
+
import torch
|
166 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
167 |
+
|
168 |
+
|
169 |
+
model_id = "rtzr/ko-gemma-2-9b-it"
|
170 |
+
|
171 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
172 |
+
model = AutoModelForCausalLM.from_pretrained(
|
173 |
+
model_id,
|
174 |
+
torch_dtype=torch.bfloat16,
|
175 |
+
device_map="auto",
|
176 |
+
)
|
177 |
+
|
178 |
+
model.eval()
|
179 |
+
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
180 |
+
|
181 |
+
messages = [
|
182 |
+
{"role": "user", "content": f"{instruction}"}
|
183 |
+
]
|
184 |
+
|
185 |
+
input_ids = tokenizer.apply_chat_template(
|
186 |
+
messages,
|
187 |
+
add_generation_prompt=True,
|
188 |
+
return_tensors="pt"
|
189 |
+
).to(model.device)
|
190 |
+
|
191 |
+
terminators = [
|
192 |
+
tokenizer.eos_token_id,
|
193 |
+
tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
194 |
+
]
|
195 |
+
|
196 |
+
outputs = model.generate(
|
197 |
+
input_ids,
|
198 |
+
max_new_tokens=2048,
|
199 |
+
eos_token_id=terminators,
|
200 |
+
do_sample=True,
|
201 |
+
temperature=0.6,
|
202 |
+
top_p=0.9,
|
203 |
+
)
|
204 |
+
|
205 |
+
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
|
206 |
+
```
|
207 |
+
|
208 |
+
```markdown
|
209 |
+
์์ธ ๊ด๊ด ์ฝ์ค๋ฅผ ์ ์ํด๋๋ฆด๊ฒ์. ํ๋ฃจ ์ข
์ผ ์ฆ๊ฒ๊ฒ ์ฌํํ ์ ์๋ ๋ฃจํธ๋ก ๊ตฌ์ฑํ์ต๋๋ค.
|
210 |
+
|
211 |
+
### 1. ์์ธ์ญ์ฌ๊ด ๋ฐ ๋ถ์ดํ์ฅ๋ง์(์ค์ )
|
212 |
+
|
213 |
+
- ์์ธ์ญ์ฌ๊ด: ์์ธ์ ์ญ์ฌ์ ๋ฌธํ๋ฅผ ์ฒดํํ ์ ์๋ ๊ณณ์
๋๋ค. ๋ค์ํ ์ ์๋ฌผ๊ณผ ์์ค์ ์๋ฅผ ํตํด ์์ธ์ ๋ณํ๋ฅผ ์ดํด๋ณผ ์ ์์ต๋๋ค.
|
214 |
+
- ๋ถ์ดํ๏ฟฝ๏ฟฝ๋ง์: ์์ธ์ ํ์ฅ์ ๋ณด์กดํ๊ณ ๊ด๋ฆฌํ๋ ๊ณณ์
๋๋ค. ์กฐ์ ์๋์ ๋ถ์๊ธฐ๋ฅผ ๋๋ ์ ์์ผ๋ฉฐ, ํ์ฅ์์ ๋ฌธํ ์ฝํ
์ธ ๋ ์ ๊ณตํ๋ ๊ณณ๋ ๋ง์ต๋๋ค.
|
215 |
+
|
216 |
+
### 2. ๋ถ์
์ฐ ์
์ฅ๊ณผ ๋ถ์
์ฐ ๋ฑ์ฐ(์ค์ )
|
217 |
+
|
218 |
+
- ๋ถ์
์ฐ์ ์์ธ์ ๋ถ์ชฝ์ ์์นํ ์ฐ์ผ๋ก, ์์ธ ํ๋ณตํ์์๋ ์์ฐ์ ๋ง๋ ์ ์๋ ๊ณณ์
๋๋ค. ๋ถ์
์ฐ ์
๊ตฌ์์ ๋ฑ์ฐ์ ์์ํ์ฌ, ๋ถ์
์ฐ ์ ์๊น์ง ์ฌ๋ผ๊ฐ๋ฉด ์์ธ์ ์ ๊ฒฝ์ ๋ณผ ์ ์์ต๋๋ค.
|
219 |
+
|
220 |
+
### 3. ์ข
๋ก ๋ช
๋ ์ผํ๊ณผ ๋ง์ง ํฌ์ด(๋ฎ)
|
221 |
+
|
222 |
+
- ๋ช
๋: ๋ค์ํ ์ผํ๋ชฐ๊ณผ ๋งค์ฅ์ด ์๋ ๊ณณ์
๋๋ค. ๋ช
๋ ์ผํํ์ด, ๋ฏธ์คํฐํธ์์คํฐ, ๋ฏธ์คํฐ๋ฆฌ๋ง์ผ ๋ฑ์ ๋ฐฉ๋ฌธํด๋ณด์ธ์.
|
223 |
+
- ๋ง์ง ํฌ์ด: ๋ช
๋์๋ ๋ค์ํ ์ง์ญ ์์์ ๋จน์ ์ ์๋ ๊ณณ์ด ๋ง์ต๋๋ค. ๋ก๋ณถ์ด, ์๋, ๋ญ๊ฐ์ ๋ฑ์ ๋ง๋ณผ ์ ์๋ ๊ณณ์ ์ถ์ฒ๋๋ฆฝ๋๋ค.
|
224 |
+
|
225 |
+
### 4. ์์ธ์๋ฆฝ๋ฏธ์ ๊ด๊ณผ ๋์๊ถ(์คํ)
|
226 |
+
|
227 |
+
- ์์ธ์๋ฆฝ๋ฏธ์ ๊ด: ํ๋๋ฏธ์ ์ ์ ์ํ๋ ๊ณณ์
๋๋ค. ํน๋ณ์ ์ด ์ด๋ฆฐ๋ค๋ฉด ๋ฐฉ๋ฌธํด ๋ณผ ์ ์์ต๋๋ค.
|
228 |
+
- ๋์๊ถ: ์กฐ์ ์๋์ ๊ถ๊ถ์
๋๋ค. ํนํ ๋ด์๋ ๋ฒ๊ฝ์ด ์๋ฆ๋ต๊ฒ ๋ง๋ฐํฉ๋๋ค.
|
229 |
+
|
230 |
+
### 5. ๋จ์ฐํ์์ ๋จ์ฐ๊ณต์ ์ฐ์ฑ
(์คํ)
|
231 |
+
|
232 |
+
- ๋จ์ฐํ์: ๋จ์ฐ์ ์๋ ๊ด๋๋์
๋๋ค. ๋จ์ฐํ์์ ์ฌ๋ผ๊ฐ๋ฉด ์์ธ์ 360๋ ์ ๊ฒฝ์ ๋ณผ ์ ์์ต๋๋ค.
|
233 |
+
- ๋จ์ฐ๊ณต์: ๋จ์ฐ์ ์๋ ๊ณต์์
๋๋ค. ๋ค์ํ ํ
๋ง ๊ณต์๊ณผ ์กฐ๊ฒฝ์ด ์ ๋ ๊ณณ์
๋๋ค. ๋จ์ฐ๊ณต์์ ์ฐ์ฑ
ํ๋ฉฐ ํด์์ ์ทจํ ์ ์์ต๋๋ค.
|
234 |
+
|
235 |
+
### 6. ๋ช
๋ ๋๋ ์ดํ์์์์ ์ ๋
์์ฌ์ ๋ฌธํ ํ๋(์ ๋
)
|
236 |
+
|
237 |
+
- ๋ช
๋: ๋ค์ํ ์ ํต์ ์ธ ํ๊ตญ ์์์ ๋จน์ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, ๋ช
๋์ ๋ฐค์๋ ํ๊ธฐ์ฐจ๊ฒ ํ๋ฐํ ๋ฌธํ ์ํ์ ํ ์ ์๋ ๊ณณ์
๋๋ค.
|
238 |
+
- ์ดํ์: ์ธ๊ตญ์ธ ๊ด๊ด๊ฐ๋ค์ด ๋ง์ด ์ฐพ๋ ๊ณณ์ผ๋ก, ๋ค์ํ ์ธ๊ณ ์์์ ๋จน์ ์ ์์ผ๋ฉฐ, ํด๋ฝ์ด๋ ๋ฐ๊ฐ ๋ง์ ๋ฌธํ์ ํ๋์ด ๊ฐ๋ฅํ ๊ณณ์
๋๋ค.
|
239 |
+
|
240 |
+
์ด ์ฝ์ค๋ ํ๋ฃจ ์ข
์ผ ํ๋ฐํ๊ฒ ์ฌํ์ ํ ์ ์๋๋ก ๊ณํํ์ต๋๋ค. ๊ฐ ์ง์ญ์ ๋ฐ๋ผ ์ด๋ ์๊ฐ์ ๊ณ ๋ คํ์๊ณ , ๊ฐ์ฅ ์๊ฐ๊ณผ ์ ์ ์ผ์ ๋ฑ์ ๋ฏธ๋ฆฌ ํ์ธํ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ฆ๊ฑฐ์ด ์ฌํ ๋์ธ์!
|
241 |
+
```
|
242 |
+
|
243 |
+
### Quantized Versions through bitsandbytes
|
244 |
+
|
245 |
+
- *Using 8-bit precision*
|
246 |
+
- *Using 4-bit precision*
|
247 |
+
|
248 |
+
```python
|
249 |
+
# pip install bitsandbytes
|
250 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
251 |
+
|
252 |
+
|
253 |
+
model_id = "rtzr/ko-gemma-2-9b-it"
|
254 |
+
quantization_config_8bit = BitsAndBytesConfig(load_in_8bit=True)
|
255 |
+
# quantization_config_4bit = BitsAndBytesConfig(load_in_4bit=True)
|
256 |
+
|
257 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
258 |
+
model = AutoModelForCausalLM.from_pretrained(
|
259 |
+
model_id,
|
260 |
+
torch_dtype=torch.bfloat16,
|
261 |
+
device_map="auto",
|
262 |
+
quantization_config=quantization_config_8bit,
|
263 |
+
# quantization_config=quantization_config_4bit,
|
264 |
+
low_cpu_mem_usage=True,
|
265 |
+
)
|
266 |
+
|
267 |
+
model.eval()
|
268 |
+
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
269 |
+
|
270 |
+
messages = [
|
271 |
+
{"role": "user", "content": f"{instruction}"}
|
272 |
+
]
|
273 |
+
|
274 |
+
input_ids = tokenizer.apply_chat_template(
|
275 |
+
messages,
|
276 |
+
add_generation_prompt=True,
|
277 |
+
return_tensors="pt"
|
278 |
+
).to(model.device)
|
279 |
+
|
280 |
+
terminators = [
|
281 |
+
tokenizer.eos_token_id,
|
282 |
+
tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
283 |
+
]
|
284 |
+
|
285 |
+
outputs = model.generate(
|
286 |
+
input_ids,
|
287 |
+
max_new_tokens=2048,
|
288 |
+
eos_token_id=terminators,
|
289 |
+
do_sample=True,
|
290 |
+
temperature=0.6,
|
291 |
+
top_p=0.9,
|
292 |
+
)
|
293 |
+
|
294 |
+
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
|
295 |
+
```
|
296 |
+
|
297 |
+
### VLLM Usage
|
298 |
+
|
299 |
+
When we use `vllm==0.5.1`, the gemma2 model cannot be loaded yet and the following [issue](https://github.com/vllm-project/vllm/issues/6237) occurs. So it is recommended to use `vllm/vllm-openai:latest` docker or [`vllm==0.5.0.post1`](https://github.com/vllm-project/vllm/releases/tag/v0.5.0.post1).
|
300 |
+
|
301 |
+
```bash
|
302 |
+
#!/bin/bash
|
303 |
+
|
304 |
+
VLLM_ATTENTION_BACKEND=FLASHINFER
|
305 |
+
MODEL_NAME="rtzr/ko-gemma-2-9b-it"
|
306 |
+
|
307 |
+
MODEL_PATH="YOUR_PATH/${MODEL_NAME}"
|
308 |
+
docker run --rm --gpus all \
|
309 |
+
-p 8000:8000 \
|
310 |
+
--shm-size=12gb --ulimit memlock=-1 --ulimit stack=67108864 \
|
311 |
+
-e VLLM_ATTENTION_BACKEND=${VLLM_ATTENTION_BACKEND} \
|
312 |
+
-v $MODEL_PATH:/vllm-workspace/${MODEL_NAME} \
|
313 |
+
vllm/vllm-openai:latest \
|
314 |
+
--model ${MODEL_NAME} --dtype auto \
|
315 |
+
--gpu-memory-utilization 0.8
|
316 |
+
```
|
317 |
+
|
318 |
+
## License
|
319 |
+
|
320 |
+
Gemma 2 License: <https://ai.google.dev/gemma/terms>
|
321 |
+
|
322 |
+
## Citation
|
323 |
+
|
324 |
+
```none
|
325 |
+
@article{RTZR,
|
326 |
+
title={ko-gemma-2-9b-it},
|
327 |
+
author={Return Zero Team},
|
328 |
+
year={2024},
|
329 |
+
url={https://huggingface.co/rtzr/ko-gemma-2-9b-it}
|
330 |
+
}
|
331 |
+
```
|
332 |
+
|
333 |
+
```none
|
334 |
+
@article{gemma_2024,
|
335 |
+
title={Gemma},
|
336 |
+
url={https://www.kaggle.com/m/3301},
|
337 |
+
DOI={10.34740/KAGGLE/M/3301},
|
338 |
+
publisher={Kaggle},
|
339 |
+
author={Gemma Team},
|
340 |
+
year={2024}
|
341 |
+
}
|
342 |
+
```
|
343 |
+
|
344 |
+
|