|
--- |
|
license: apache-2.0 |
|
language: |
|
- ko |
|
pipeline_tag: text-generation |
|
--- |
|
|
|
### How to use GPTQ model |
|
https://github.com/jongmin-oh/korean-LLM-quantize |
|
``` |
|
mkdir ./templates && mkdir ./utils && wget -P ./templates https://raw.githubusercontent.com/jongmin-oh/korean-LLM-quantize/main/templates/kullm.json && wget -P ./utils https://raw.githubusercontent.com/jongmin-oh/korean-LLM-quantize/main/utils/prompter.py |
|
``` |
|
|
|
### install package |
|
``` |
|
pip install torch==2.0.1 auto-gptq==0.4.2 |
|
``` |
|
|
|
- ๊ธํ์ ๋ถ๋ค์ ๋ฐ์ ์์ ์ฝ๋ ์คํํ์๋ฉด ๋ฐ๋ก ํ
์คํธ ๊ฐ๋ฅํฉ๋๋ค. (GPU memory 19GB ์ ์ ) |
|
- 2023-08-23์ผ ์ดํ๋ถํฐ๋ huggingFace์์ GPTQ๋ฅผ ๊ณต์์ง์ํ๊ฒ๋์์ต๋๋ค. |
|
|
|
```python |
|
import torch |
|
from transformers import pipeline |
|
from auto_gptq import AutoGPTQForCausalLM |
|
|
|
from utils.prompter import Prompter |
|
|
|
MODEL = "j5ng/kullm-5.8b-GPTQ-8bit" |
|
model = AutoGPTQForCausalLM.from_quantized(MODEL, device="cuda:0", use_triton=False) |
|
|
|
pipe = pipeline('text-generation', model=model,tokenizer=MODEL) |
|
|
|
prompter = Prompter("kullm") |
|
|
|
def infer(instruction="", input_text=""): |
|
prompt = prompter.generate_prompt(instruction, input_text) |
|
output = pipe( |
|
prompt, max_length=512, |
|
temperature=0.2, |
|
repetition_penalty=3.0, |
|
num_beams=5, |
|
eos_token_id=2 |
|
) |
|
s = output[0]["generated_text"] |
|
result = prompter.get_response(s) |
|
|
|
return result |
|
|
|
instruction = """ |
|
์ํฅ๋ฏผ(ํ๊ตญ ํ์: ๅญซ่ๆ
, 1992๋
7์ 8์ผ ~ )์ ๋ํ๋ฏผ๊ตญ์ ์ถ๊ตฌ ์ ์๋ก ํ์ฌ ์๊ธ๋๋ ํ๋ฆฌ๋ฏธ์ด๋ฆฌ๊ทธ ํ ํธ๋ ํ์คํผ์์ ์์ด๋ก ํ์ฝํ๊ณ ์๋ค. |
|
๋ํ ๋ํ๋ฏผ๊ตญ ์ถ๊ตฌ ๊ตญ๊ฐ๋ํํ์ ์ฃผ์ฅ์ด์ 2018๋
์์์ ๊ฒ์ ๊ธ๋ฉ๋ฌ๋ฆฌ์คํธ์ด๋ฉฐ ์๊ตญ์์๋ ์ ์นญ์ธ "์๋"(Sonny)๋ก ๋ถ๋ฆฐ๋ค. |
|
์์์ ์ ์๋ก์๋ ์ญ๋ ์ต์ด๋ก ํ๋ฆฌ๋ฏธ์ด๋ฆฌ๊ทธ ๊ณต์ ๋ฒ ์คํธ ์ผ๋ ๋ธ๊ณผ ์์์ ์ ์ ์ต์ด์ ํ๋ฆฌ๋ฏธ์ด๋ฆฌ๊ทธ ๋์ ์์ ๋ฌผ๋ก FIFA ํธ์ค์นด์ค์๊น์ง ํฉ์ธ์๊ณ 2022๋
์๋ ์ถ๊ตฌ ์ ์๋ก๋ ์ต์ด๋ก ์ฒด์กํ์ฅ ์ฒญ๋ฃก์ฅ ์ํ์๊ฐ ๋์๋ค. |
|
์ํฅ๋ฏผ์ ํ์ฌ ๋ฆฌ๊ทธ 100ํธ๋ฅผ ๋ฃ์ด์ ํ์ ๊ฐ ๋๊ณ ์๋ค. |
|
""" |
|
result = infer(instruction=instruction, input_text="์ํฅ๋ฏผ์ ์ ์นญ์ ๋ญ์ผ?") |
|
print(result) # ์ํฅ๋ฏผ์ ์ ์นญ์ "์๋"์
๋๋ค. |
|
``` |
|
|
|
### Reference |
|
|
|
- [EleutherAI/polyglot](https://huggingface.co/EleutherAI/polyglot-ko-12.8b) |
|
- [๊ณ ๋ ค๋ํ๊ต/kullm](https://huggingface.co/nlpai-lab/kullm-polyglot-12.8b-v2) |
|
- [GPTQ](https://github.com/IST-DASLab/gptq) |
|
|