|
Quantization made by Richard Erkhov. |
|
|
|
[Github](https://github.com/RichardErkhov) |
|
|
|
[Discord](https://discord.gg/pvy7H8DZMG) |
|
|
|
[Request more models](https://github.com/RichardErkhov/quant_request) |
|
|
|
|
|
ko-gemma-2-9b-it - bnb 4bits |
|
- Model creator: https://huggingface.co/rtzr/ |
|
- Original model: https://huggingface.co/rtzr/ko-gemma-2-9b-it/ |
|
|
|
|
|
|
|
|
|
Original model description: |
|
---
|
|
license: gemma
|
|
library_name: transformers
|
|
pipeline_tag: text-generation
|
|
extra_gated_heading: Access Gemma on Hugging Face
|
|
extra_gated_prompt: >-
|
|
To access Gemma on Hugging Face, youโre required to review and agree to
|
|
Googleโs usage license. To do this, please ensure youโre logged in to Hugging
|
|
Face and click below. Requests are processed immediately.
|
|
extra_gated_button_content: Acknowledge license
|
|
tags:
|
|
- conversational
|
|
base_model:
|
|
- google/gemma-2-9b
|
|
language:
|
|
- ko
|
|
---
|
|
|
|
|
|
|
|
## Model Details
|
|
|
|
### Ko-Gemma-2-9B-IT
|
|
|
|
**[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:
|
|
|
|
- [Orca-Math](https://huggingface.co/datasets/kuotient/orca-math-korean-dpo-pairs)
|
|
- [dpo-mix-7k](https://huggingface.co/datasets/argilla/dpo-mix-7k)
|
|
|
|
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.
|
|
|
|
#### *Inputs and outputs*
|
|
|
|
- **Input:** Text string, such as a question, a prompt, or a document to be summarized.
|
|
- **Output:** Generated Korean-language text in response to the input, such as an answer to a question, or a summary of a document.
|
|
|
|
### Google Gemma 2
|
|
|
|
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
|
built from the same research and technology used to create the Gemini models.
|
|
They are text-to-text, decoder-only large language models, available in English,
|
|
with open weights for both pre-trained variants and instruction-tuned variants.
|
|
Gemma models are well-suited for a variety of text generation tasks, including
|
|
question answering, summarization, and reasoning. Their relatively small size
|
|
makes it possible to deploy them in environments with limited resources such as
|
|
a laptop, desktop or your own cloud infrastructure, democratizing access to
|
|
state of the art AI models and helping foster innovation for everyone.
|
|
|
|
## Benchmark Scores
|
|
|
|
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.
|
|
|
|
| Model | Math | Reasoning | Writing | Coding | Understanding | Grammar | Single ALL | Multi ALL | Overall |
|
|
|:---------:|:-----:|:------:|:-----:|:-----:|:----:|:-----:|:-----:|:-----:|:----:|
|
|
| [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 |
|
|
| [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 |
|
|
| [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 |
|
|
| [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 |
|
|
| [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 |
|
|
|
|
## Usage
|
|
|
|
### Install Dependencies
|
|
|
|
You must install transformers >= 4.42.3 for gemma2 models.
|
|
|
|
```bash
|
|
pip install transformers==4.42.3 accelerate
|
|
```
|
|
|
|
### Python code with Pipeline
|
|
|
|
```python
|
|
import transformers
|
|
import torch
|
|
|
|
|
|
model_id = "rtzr/ko-gemma-2-9b-it"
|
|
|
|
pipeline = transformers.pipeline(
|
|
"text-generation",
|
|
model=model_id,
|
|
model_kwargs={"torch_dtype": torch.bfloat16},
|
|
device_map="auto",
|
|
)
|
|
|
|
pipeline.model.eval()
|
|
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
|
|
|
messages = [
|
|
{"role": "user", "content": f"{instruction}"}
|
|
]
|
|
|
|
prompt = pipeline.tokenizer.apply_chat_template(
|
|
messages,
|
|
tokenize=False,
|
|
add_generation_prompt=True
|
|
)
|
|
|
|
terminators = [
|
|
pipeline.tokenizer.eos_token_id,
|
|
pipeline.tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
|
]
|
|
|
|
outputs = pipeline(
|
|
prompt,
|
|
max_new_tokens=2048,
|
|
eos_token_id=terminators,
|
|
do_sample=True,
|
|
temperature=0.6,
|
|
top_p=0.9,
|
|
)
|
|
|
|
print(outputs[0]["generated_text"][len(prompt):])
|
|
```
|
|
|
|
```markdown
|
|
์์ธ์ ์ญ์ฌ, ๋ฌธํ, ํ๋์ฑ์ด ์กฐํ๋ฅผ ์ด๋ฃฌ ๋งค๋ ฅ์ ์ธ ๋์์
๋๋ค. ์ฌ๊ธฐ์ ์ฆ๊ธธ ์ ์๋ ๋ค์ํ ๊ด๊ด์ง์ ๋ช
์๋ฅผ ์๊ฐํฉ๋๋ค. ๋ค์์ ์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค 3๊ฐ์ง์
๋๋ค.
|
|
|
|
**1. ์ญ์ฌ์ ๋ฌธํ๋ฅผ ๋๋ฌ์ผ ํ๊ตญ๊ด๊ด์ฝ์ค**
|
|
|
|
1. **๊ฒฝ๋ณต๊ถ**: ์กฐ์ ์๋์ ์
์ฅํ ์๊ถ์ ๋ง๋ฝํ ์ ์๋ ๊ณณ์
๋๋ค. ํนํ ๋งค๋
๋ด์ ์ด๋ฆฌ๋ '์ถ์ถ์ฐํ'๋ ๊ฒฝ๋ณต๊ถ์ ์๋ฆ๋ค์์ ๋์ฑ ๋๋ณด์ด๊ฒ ํฉ๋๋ค.
|
|
2. **๋ถ์ด ํ์ฅ๋ง์**: ๊ณ ํ์ค๋ฌ์ด ํ์ฅ์ด ๋ชจ์ฌ์๋ ๊ณณ์ผ๋ก, ์ ํต ๋ฌธํ ์ฒดํ์ด ๊ฐ๋ฅํฉ๋๋ค. '๋ถ์ด ํ์ฅ๋ง์ ๋ฌธํ์ฒดํ๊ด'์์๋ ํ๋ณต ์ฒดํ๋ถํฐ ์ข
์ด๋งํ, ํ๊ธ ์ฐ๊ธฐ ๋ฑ ๋ค์ํ ํ๋ก๊ทธ๋จ์ด ์ค๋น๋์ด ์์ต๋๋ค.
|
|
3. **์ธ์ฌ๋**: ์์ , ๋ฏธ์ ๊ด, ํ์๋น์ด ๋ง์ ๊ณณ์
๋๋ค. ํนํ '์ธ์ฌ๋ ๋ฌธํ๊ด'์์๋ ์์ธ์ ์ญ์ฌ์ ๋ฌธํ๋ฅผ ์ดํดํ๋ ๋ฐ ๋์์ด ๋๋ ์ ์๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
|
|
4. **๊ดํ๋ฌธ** ๋ฐ **๋ช
๋**: ํ๋์ ์ธ ์ผํ๊ณผ ๋ ์คํ ๋์ด ์ฆ๋นํ ๊ณณ์
๋๋ค. ๊ดํ๋ฌธ์ ํนํ ์ ์์ด๋ค์ด ๋ง์ ๊ณณ์ผ๋ก, ์คํธ๋ฆฌํธ ํจ์
์ ๊ด์ฐฐํ๊ฑฐ๋ ๋ฐค๊ฑฐ๋ฆฌ์์ ํ๊ธฐ๋ฅผ ๋๋ ์ ์์ต๋๋ค.
|
|
|
|
**2. ๋์์ ๋ชจ์ต์ ๋ฐ๋ผ๋ณด๋ ๋ทฐํฌ์ด ์ฝ์ค**
|
|
|
|
1. **๋จ์ฐํ์**: ์์ธ์ ์์ง์ ์ธ ๊ฑด๋ฌผ๋ก, ๊ผญ๋๊ธฐ์์ ํผ์ณ์ง๋ 360๋์ ๊ฒฝ์น๊ฐ ์๋๋ค. ํนํ ๋ฐค์ด ๋๋ฉด ์กฐ๋ช
์ด ์ด์ฐ๋ฌ์ ธ ๋์ฑ ์๋ฆ๋ค์์ง๋๋ค.
|
|
2. **์์ธํ์**: ๋จ์ฐํ์์ ๋น์ทํ ์์น๋ก, ๋์ด๊ฐ ๋ ๋๊ธฐ ๋๋ฌธ์ ๋ ๋์ ์ ๋ง์ ๋ณผ ์ ์์ต๋๋ค. ์์ธํ์ ๋ด๋ถ์๋ ๋ค์ํ ์ ์๊ด๊ณผ ๋ ์คํ ๋๋ ์์ต๋๋ค.
|
|
3. **๋ถ์
์ฐ**: ์์ธ์ ์ค์ฌ๋ถ์ ์์นํ ์ฐ์ผ๋ก, ์์ธ์ ๊ฒฝ์น๋ฅผ ์กฐ๊ธ ๋ค๋ฅธ ๊ด์ ์์ ๋ณผ ์ ์์ต๋๋ค. ํนํ ๋ถ์
์ฐ ์ ์์ธ ๋ถ์
์ฌ์์๋ ์ข์ ์ ๋ง์ ๋ณผ ์ ์์ต๋๋ค.
|
|
4. **์์ธ์ฒ**: ๋
น์ง ๊ณต๊ฐ์ผ๋ก, ๋์์ ํผ์กํจ์์ ๋ฒ์ด๋ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, ์์ธ์ฒ ๋ด๋ถ์๋ '์์ธ์ฒ ์ํธํ๋ ์ ํธ'๋ผ๋ ๊ณต๊ฐ์ด ์์ด ์์ ๊ณผ ์์ฐ์ ํจ๊ป ์ฒดํํ ์ ์์ต๋๋ค.
|
|
|
|
**3. ํ๋ ๋ฌธํ๋ฅผ ๋ง๋๋ ์ฝ์ค**
|
|
|
|
1. **์ผ์ฑ๋**: ํ๋ ๋ฏธ์ ๊ด์ด ๋ง์ ๊ณณ์ผ๋ก, '์ผ์ฑ ๋ฏธ์ ๊ด', '์๋ชจ๋ฆฌ์นด๋์ค ๊ฐค๋ฌ๋ฆฌ' ๋ฑ์ด ์์ต๋๋ค. ๋ํ, '์ฝ์์ค'๋ '์ํฌ์นด๋กํฌ์ค' ๋ฑ์ ๋ช
์๋ ๊ฐ๊น์ด ๊ณณ์ ์์ต๋๋ค.
|
|
2. **์ดํ์**: ์ธ๊ตญ์ธ๋ค์ด ๋ง์ ๊ณณ์ผ๋ก, ๋ค์ํ ์ธ๊ตญ ์์์ ์ฆ๊ธธ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, '์ดํ์ ๊ธ๋ก์ปฌ๋ฌธํ์ผํฐ'์์๋ ์ธ๊ณ ๊ฐ๊ตญ์ ๋ฌธํ ์ฒดํ์ด ๊ฐ๋ฅํฉ๋๋ค.
|
|
3. **ํ๋**: ์ ์์ด๋ค์ ๋ฌธํ๊ฐ ๋์น๋ ๊ณณ์
๋๋ค. 'ํ๋ ๋กค๋งํ'์ ํนํ ๋ง์ ์ฌ๋๋ค์ด ๋ฐฉ๋ฌธํ๋ ๊ณณ์
๋๋ค. ๋ํ, 'ํ๋ ์์ ๊ฑฐ๋ฆฌ'์์๋ ๋
์์ ๋ฌธํ๋ฅผ ๋ง๋ ์ ์์ต๋๋ค.
|
|
4. **๊ฐ๋จ**: ์์ธ์ ํ๋์ ๋ชจ์ต์ ์ ๋ณด์ฌ์ฃผ๋ ๊ณณ์
๋๋ค. '๊ฐ๋จ์ญ'์ ์ค์ฌ์ผ๋ก ๋ง์ ๊ณ ๊ธ ์ผํ๋ชฐ๊ณผ ๋ ์คํ ๋์ด ์์ต๋๋ค.
|
|
|
|
์ด๋ฌํ ์ฝ์ค๋ฅผ ํตํด ์์ธ์ ๋ค์ํ ๋ชจ์ต์ ํ ๋ฒ์ ๋ง๋๋ณผ ์ ์์ ๊ฑฐ์์. ๊ฐ์์ ์ทจํฅ์ ๋ง์ถฐ ์ฝ์ค๋ฅผ ์กฐ์ ํ์๋ฉด ์ข๊ฒ ์ต๋๋ค. ์ฆ๊ฑฐ์ด ์ฌํ ๋์ธ์!
|
|
```
|
|
|
|
### Python code with AutoModel
|
|
|
|
```python
|
|
import os
|
|
import torch
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
model_id = "rtzr/ko-gemma-2-9b-it"
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|
model_id,
|
|
torch_dtype=torch.bfloat16,
|
|
device_map="auto",
|
|
)
|
|
|
|
model.eval()
|
|
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
|
|
|
messages = [
|
|
{"role": "user", "content": f"{instruction}"}
|
|
]
|
|
|
|
input_ids = tokenizer.apply_chat_template(
|
|
messages,
|
|
add_generation_prompt=True,
|
|
return_tensors="pt"
|
|
).to(model.device)
|
|
|
|
terminators = [
|
|
tokenizer.eos_token_id,
|
|
tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
|
]
|
|
|
|
outputs = model.generate(
|
|
input_ids,
|
|
max_new_tokens=2048,
|
|
eos_token_id=terminators,
|
|
do_sample=True,
|
|
temperature=0.6,
|
|
top_p=0.9,
|
|
)
|
|
|
|
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
|
|
```
|
|
|
|
```markdown
|
|
์์ธ ๊ด๊ด ์ฝ์ค๋ฅผ ์ ์ํด๋๋ฆด๊ฒ์. ํ๋ฃจ ์ข
์ผ ์ฆ๊ฒ๊ฒ ์ฌํํ ์ ์๋ ๋ฃจํธ๋ก ๊ตฌ์ฑํ์ต๋๋ค.
|
|
|
|
### 1. ์์ธ์ญ์ฌ๊ด ๋ฐ ๋ถ์ดํ์ฅ๋ง์(์ค์ )
|
|
|
|
- ์์ธ์ญ์ฌ๊ด: ์์ธ์ ์ญ์ฌ์ ๋ฌธํ๋ฅผ ์ฒดํํ ์ ์๋ ๊ณณ์
๋๋ค. ๋ค์ํ ์ ์๋ฌผ๊ณผ ์์ค์ ์๋ฅผ ํตํด ์์ธ์ ๋ณํ๋ฅผ ์ดํด๋ณผ ์ ์์ต๋๋ค.
|
|
- ๋ถ์ดํ์ฅ๋ง์: ์์ธ์ ํ์ฅ์ ๋ณด์กดํ๊ณ ๊ด๋ฆฌํ๋ ๊ณณ์
๋๋ค. ์กฐ์ ์๋์ ๋ถ์๊ธฐ๋ฅผ ๋๋ ์ ์์ผ๋ฉฐ, ํ์ฅ์์ ๋ฌธํ ์ฝํ
์ธ ๋ ์ ๊ณตํ๋ ๊ณณ๋ ๋ง์ต๋๋ค.
|
|
|
|
### 2. ๋ถ์
์ฐ ์
์ฅ๊ณผ ๋ถ์
์ฐ ๋ฑ์ฐ(์ค์ )
|
|
|
|
- ๋ถ์
์ฐ์ ์์ธ์ ๋ถ์ชฝ์ ์์นํ ์ฐ์ผ๋ก, ์์ธ ํ๋ณตํ์์๋ ์์ฐ์ ๋ง๋ ์ ์๋ ๊ณณ์
๋๋ค. ๋ถ์
์ฐ ์
๊ตฌ์์ ๋ฑ์ฐ์ ์์ํ์ฌ, ๋ถ์
์ฐ ์ ์๊น์ง ์ฌ๋ผ๊ฐ๋ฉด ์์ธ์ ์ ๊ฒฝ์ ๋ณผ ์ ์์ต๋๋ค.
|
|
|
|
### 3. ์ข
๋ก ๋ช
๋ ์ผํ๊ณผ ๋ง์ง ํฌ์ด(๋ฎ)
|
|
|
|
- ๋ช
๋: ๋ค์ํ ์ผํ๋ชฐ๊ณผ ๋งค์ฅ์ด ์๋ ๊ณณ์
๋๋ค. ๋ช
๋ ์ผํํ์ด, ๋ฏธ์คํฐํธ์์คํฐ, ๋ฏธ์คํฐ๋ฆฌ๋ง์ผ ๋ฑ์ ๋ฐฉ๋ฌธํด๋ณด์ธ์.
|
|
- ๋ง์ง ํฌ์ด: ๋ช
๋์๋ ๋ค์ํ ์ง์ญ ์์์ ๋จน์ ์ ์๋ ๊ณณ์ด ๋ง์ต๋๋ค. ๋ก๋ณถ์ด, ์๋, ๋ญ๊ฐ์ ๋ฑ์ ๋ง๋ณผ ์ ์๋ ๊ณณ์ ์ถ์ฒ๋๋ฆฝ๋๋ค.
|
|
|
|
### 4. ์์ธ์๋ฆฝ๋ฏธ์ ๊ด๊ณผ ๋์๊ถ(์คํ)
|
|
|
|
- ์์ธ์๋ฆฝ๋ฏธ์ ๊ด: ํ๋๋ฏธ์ ์ ์ ์ํ๋ ๊ณณ์
๋๋ค. ํน๋ณ์ ์ด ์ด๋ฆฐ๋ค๋ฉด ๋ฐฉ๋ฌธํด ๋ณผ ์ ์์ต๋๋ค.
|
|
- ๋์๊ถ: ์กฐ์ ์๋์ ๊ถ๊ถ์
๋๋ค. ํนํ ๋ด์๋ ๋ฒ๊ฝ์ด ์๋ฆ๋ต๊ฒ ๋ง๋ฐํฉ๋๋ค.
|
|
|
|
### 5. ๋จ์ฐํ์์ ๋จ์ฐ๊ณต์ ์ฐ์ฑ
(์คํ)
|
|
|
|
- ๋จ์ฐํ์: ๋จ์ฐ์ ์๋ ๊ด๋๋์
๋๋ค. ๋จ์ฐํ์์ ์ฌ๋ผ๊ฐ๋ฉด ์์ธ์ 360๋ ์ ๊ฒฝ์ ๋ณผ ์ ์์ต๋๋ค.
|
|
- ๋จ์ฐ๊ณต์: ๋จ์ฐ์ ์๋ ๊ณต์์
๋๋ค. ๋ค์ํ ํ
๋ง ๊ณต์๊ณผ ์กฐ๊ฒฝ์ด ์ ๋ ๊ณณ์
๋๋ค. ๋จ์ฐ๊ณต์์ ์ฐ์ฑ
ํ๋ฉฐ ํด์์ ์ทจํ ์ ์์ต๋๋ค.
|
|
|
|
### 6. ๋ช
๋ ๋๋ ์ดํ์์์์ ์ ๋
์์ฌ์ ๋ฌธํ ํ๋(์ ๋
)
|
|
|
|
- ๋ช
๋: ๋ค์ํ ์ ํต์ ์ธ ํ๊ตญ ์์์ ๋จน์ ์ ์๋ ๊ณณ์
๋๋ค. ๋ํ, ๋ช
๋์ ๋ฐค์๋ ํ๊ธฐ์ฐจ๊ฒ ํ๋ฐํ ๋ฌธํ ์ํ์ ํ ์ ์๋ ๊ณณ์
๋๋ค.
|
|
- ์ดํ์: ์ธ๊ตญ์ธ ๊ด๊ด๊ฐ๋ค์ด ๋ง์ด ์ฐพ๋ ๊ณณ์ผ๋ก, ๋ค์ํ ์ธ๊ณ ์์์ ๋จน์ ์ ์์ผ๋ฉฐ, ํด๋ฝ์ด๋ ๋ฐ๊ฐ ๋ง์ ๋ฌธํ์ ํ๋์ด ๊ฐ๋ฅํ ๊ณณ์
๋๋ค.
|
|
|
|
์ด ์ฝ์ค๋ ํ๋ฃจ ์ข
์ผ ํ๋ฐํ๊ฒ ์ฌํ์ ํ ์ ์๋๋ก ๊ณํํ์ต๋๋ค. ๊ฐ ์ง์ญ์ ๋ฐ๋ผ ์ด๋ ์๊ฐ์ ๊ณ ๋ คํ์๊ณ , ๊ฐ์ฅ ์๊ฐ๊ณผ ์ ์ ์ผ์ ๋ฑ์ ๋ฏธ๋ฆฌ ํ์ธํ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ฆ๊ฑฐ์ด ์ฌํ ๋์ธ์!
|
|
```
|
|
|
|
### Quantized Versions through bitsandbytes
|
|
|
|
- *Using 8-bit precision*
|
|
- *Using 4-bit precision*
|
|
|
|
```python
|
|
# pip install bitsandbytes
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
|
|
|
|
|
model_id = "rtzr/ko-gemma-2-9b-it"
|
|
quantization_config_8bit = BitsAndBytesConfig(load_in_8bit=True)
|
|
# quantization_config_4bit = BitsAndBytesConfig(load_in_4bit=True)
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|
model_id,
|
|
torch_dtype=torch.bfloat16,
|
|
device_map="auto",
|
|
quantization_config=quantization_config_8bit,
|
|
# quantization_config=quantization_config_4bit,
|
|
low_cpu_mem_usage=True,
|
|
)
|
|
|
|
model.eval()
|
|
instruction = "์์ธ์ ์ ๋ช
ํ ๊ด๊ด ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค๋?"
|
|
|
|
messages = [
|
|
{"role": "user", "content": f"{instruction}"}
|
|
]
|
|
|
|
input_ids = tokenizer.apply_chat_template(
|
|
messages,
|
|
add_generation_prompt=True,
|
|
return_tensors="pt"
|
|
).to(model.device)
|
|
|
|
terminators = [
|
|
tokenizer.eos_token_id,
|
|
tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
|
]
|
|
|
|
outputs = model.generate(
|
|
input_ids,
|
|
max_new_tokens=2048,
|
|
eos_token_id=terminators,
|
|
do_sample=True,
|
|
temperature=0.6,
|
|
top_p=0.9,
|
|
)
|
|
|
|
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
|
|
```
|
|
|
|
### VLLM Usage
|
|
|
|
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).
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
|
|
VLLM_ATTENTION_BACKEND=FLASHINFER
|
|
MODEL_NAME="rtzr/ko-gemma-2-9b-it"
|
|
|
|
MODEL_PATH="YOUR_PATH/${MODEL_NAME}"
|
|
docker run --rm --gpus all \
|
|
-p 8000:8000 \
|
|
--shm-size=12gb --ulimit memlock=-1 --ulimit stack=67108864 \
|
|
-e VLLM_ATTENTION_BACKEND=${VLLM_ATTENTION_BACKEND} \
|
|
-v $MODEL_PATH:/vllm-workspace/${MODEL_NAME} \
|
|
vllm/vllm-openai:latest \
|
|
--model ${MODEL_NAME} --dtype auto \
|
|
--gpu-memory-utilization 0.8
|
|
```
|
|
|
|
## License
|
|
|
|
Gemma 2 License: <https://ai.google.dev/gemma/terms>
|
|
|
|
## Citation
|
|
|
|
```none
|
|
@article{RTZR,
|
|
title={ko-gemma-2-9b-it},
|
|
author={Return Zero Team},
|
|
year={2024},
|
|
url={https://huggingface.co/rtzr/ko-gemma-2-9b-it}
|
|
}
|
|
```
|
|
|
|
```none
|
|
@article{gemma_2024,
|
|
title={Gemma},
|
|
url={https://www.kaggle.com/m/3301},
|
|
DOI={10.34740/KAGGLE/M/3301},
|
|
publisher={Kaggle},
|
|
author={Gemma Team},
|
|
year={2024}
|
|
}
|
|
```
|
|
|
|
|
|
|