Recently, due to the success of ChatGPT, numerous large language models have emerged in an attempt to catch up with ChatGPT's capabilities. However, when it comes to Korean language performance, it has been observed that many models still struggle to provide accurate answers or generate Korean text effectively. This study addresses these challenges by introducing a multi-task instruction technique that leverages supervised datasets from various tasks to create training data for Large Language Models (LLMs).
- dpo train ์ฝ๋ ๊ณต๊ฐ dpo_train.py
- komt-mistral-7b-v1-dpo : dpo(Direct Preference Optimization) ํ์ต ๋ชจ๋ธ ์ถ๊ฐ
- komt-mistral-7b-v1-dpo ํ๊ฐ๊ฒฐ๊ณผ ํ์ฌ komt๋ชจ๋ธ ์ค์์ ๊ฐ์ฅ๋์ ์ฑ๋ฅ์ธ 76.75%๊ธฐ๋ก.. (gpt-3.5-turbo 79.45%)
- komt-mistral-7b-v1 ๋ชจ๋ธ ์ถ๊ฐ
- komt-llama-30b-v1 ๋ชจ๋ธ ์ถ๊ฐ
- chatgpt ๊ธฐ๋ฐ ํ๊ฐ ๊ฒฐ๊ณผ์ ์๋ ๋ชจ๋ธ ์ถ๊ฐ
- naver Cue
- clova X
- nlpai-lab/kullm-polyglot-12.8b-v2
- kfkas/Llama-2-ko-7b-Chat
- beomi/KoAlpaca-Polyglot-12.8B
- komt-llama2-13b-v1 ๋ชจ๋ธ ์ถ๊ฐ
- Fine-tune with deepspeed ํ์ต ๋ฐฉ๋ฒ ์ถ๊ฐ
- usage komt with vllm ์ฝ๋์ ์ค์น ๋ฐฉ๋ฒ ์ถ๊ฐ
- ๋ชจ๋ธ ํ๊ฐ ๊ฒฐ๊ณผํ ์ถ๊ฐ
- finetune_with_lora ํ์ต์ 4bit, 8bit ์ ํํ์ฌ ํ์ตํ ์ ์๋๋ก ๊ธฐ๋ฅ์ถ๊ฐ
- komt-llama2 ๋ชจ๋ธ์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ์์ ์ ํ์ต ๋ฐฉ๋ฒ, ๋ฐ์ดํฐ์ ์ ์ถ๊ฐํฉ๋๋ค.
- ๊ฐ์ ๋ multi-task dataset์ผ๋ก ํ์ตํ komt-llama2-7b-v1 ๋ชจ๋ธ์ ๋ฐฐํฌํฉ๋๋ค.(๊ฐ๋์ฉ end token ์ ์ฉ์ด ์๋๋ ๋ฌธ์ , ๋ต๋ณ์ ๋๋ฌด ๊ธธ๊ฒ ํ๋ ๋ฌธ์ ๋ฑ ์์ )
- davidkim205/komt-llama2-7b-v1
- davidkim205/komt-llama2-7b-v1-lora
- davidkim205/komt-llama2-7b-v1-ggml
- We are releasing the davidkim205/komt-Llama-2-7b-chat-hf-ggml model
- We are releasing the davidkim205/komt-Llama-2-13b-hf-lora and [davidkim205/komt-Llama-2-13b-hf-ggml]https://huggingface.co/davidkim205/komt-Llama-2-13b-hf-ggml) models
- davidkim205/komt-llama2-13b-v1
- davidkim205/komt-llama2-13b-v1-lora
- davidkim205/komt-llama2-13b-v1-ggml
- davidkim205/komt-mistral-7b-v1
- davidkim205/komt-mistral-7b-v1-lora
- davidkim205/komt-mistral-7b-v1-gguf
- davidkim205/komt-mistral-7b-v1-dpo
- nvidia driver : 535.54.03
- CUDA Version: 12.2
git clone https://github.com/davidkim205/komt.git
cd komt
conda create -n komt python=3.10
conda activate komt
pip install -r requirements.txt
์ฐ๋ฆฌ๋ komt-llama2 ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์๋ ๋ค์ํ ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค.
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import TextStreamer, GenerationConfig
model_name='davidkim205/komt-llama2-7b-v1'
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
streamer = TextStreamer(tokenizer)
def gen(x):
generation_config = GenerationConfig(
temperature=0.8,
top_p=0.8,
top_k=100,
max_new_tokens=512,
early_stopping=True,
do_sample=True,
)
q = f"### instruction: {x}\n\n### Response: "
gened = model.generate(
**tokenizer(
q,
return_tensors='pt',
return_token_type_ids=False
).to('cuda'),
generation_config=generation_config,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id,
streamer=streamer,
)
result_str = tokenizer.decode(gened[0])
start_tag = f"\n\n### Response: "
start_index = result_str.find(start_tag)
if start_index != -1:
result_str = result_str[start_index + len(start_tag):].strip()
return result_str
print(gen('์ ์ฃผ๋๋ฅผ 1๋ฐ2์ผ๋ก ํผ์ ์ฌํํ๋ ค๊ณ ํ๋๋ฐ ์ฌํ ์ฝ์ค๋ฅผ ๋ง๋ค์ด์ค'))
๊ฒฐ๊ณผ
### Response: ์ ์ฃผ๋๋ฅผ 1๋ฐ2์ผ๋ก ํผ์ ์ฌํํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ ์ฌํ ์ฝ์ค๋ฅผ ๋ง๋ค์ด ๊ณํํ ์ ์์ต๋๋ค:
1์ผ์ฐจ:
- ์์นจ: ์ ์ฃผ๋์ ์๋ฆ๋ค์ด ํด๋ณ์ ๊ตฌ๊ฒฝํ๊ธฐ ์ํด ํด๋ณ์ ๋์ฐฉํ์ธ์. ์ผ์ถ์ ๊ฐ์ํ๋ฉฐ ์์ฐ์ ์๋ฆ๋ค์์ ๋ง๋ฝํ์ธ์.
- ์คํ: ์ ์ฃผ๋์ ๋ํ์ ์ธ ๊ด๊ด์ง์ธ ํ๋ผ์ฐ์ ํํํ์ธ์. ๋ฑ์ฐ๋ก๋ฅผ ๋ฐ๋ผ ์ฌ๋ผ๊ฐ๋ฉด์ ๊ฒฝ์น๋ฅผ ์ฆ๊ธฐ๊ณ ์ค๋ช
์ ๋ฃ์ผ๋ฉฐ ์ฌ์ด ์ฐ์ฑ
์ ์ฆ๊ธฐ์ธ์.
- ์ ๋
: ์ ์ฃผ๋์ ๋ง์๋ ์์์ ์์ ์ ๋
์ ๋ณด๋ด์ธ์. ์ ์ ํ ํด์ฐ๋ฌผ๊ณผ ํฅ์ ๋ฃ๋ก ๋ง๋ ์์์ ๋ง๋ณด๋ ๊ฒ์ ์ ์ฃผ๋ ์ฌํ์ ์๋ฒฝํ ๊ฒฝํ์ด ๋ ๊ฒ์
๋๋ค.
2์ผ์ฐจ:
- ์์นจ: ํ๋ผ์ฐ ์ผ๋๋ฅผ ํํํ๊ธฐ ์ํด ํ๋ผ์ฐ ์ผ์ดํ๋ก ์ด๋ํ์ธ์. ์ด ์ผ์ดํ๋ ๋ฑ์ฐ์ ์ฆ๊ธฐ๋ ์ฌ๋๋ค์๊ฒ ์ต์ ์ ์ ํ์
๋๋ค.
# text-generation-webui ์ฝ๋ ๋ฐ๊ธฐ
git clone https://github.com/oobabooga/text-generation-webui
cd text-generation-webui/
# conda ํ๊ฒฝ์์ฑ
conda create -n text-generation-webui python=3.10
conda activate text-generation-webui
# pip install
pip install -r requirements.txt
# model download
pip install huggingface-hub
python -c "from huggingface_hub import hf_hub_download;print(hf_hub_download(repo_id='davidkim205/komt-llama2-7b-v1-ggml', filename='ggml-model-q4_0.gguf', local_dir='./models/'))"
# server ์คํ
python server.py
https://github.com/liltom-eth/llama2-webui
llama2-webui๋ฅผ git cloneํ requirements๋ฅผ install ํฉ๋๋ค. ๊ทธ๋ฐ๋ค์ ์ฉ๋์ด ํฌ๊ธฐ๋๋ฌธ์ git lfs์ ์ด์ฉํ์ฌ komt-llama2-7b๋ฅผ ๋ค์ด๋ก๋ ๋ฐ์ต๋๋ค.
git clone https://github.com/liltom-eth/llama2-webui.git
cd llama2-webui
pip install -r requirements.txt
model์ ๋ค์ด๋ก๋ํ app์ ์คํํฉ๋๋ค.
sudo apt install git-lfs
git lfs clone https://huggingface.co/davidkim205/komt-llama2-7b-v1
python app.py --backend_type transformers --model_path ./komt-llama2-7b-v1/
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
pip install -r requirements.txt
pip install huggingface-hub
python -c "from huggingface_hub import hf_hub_download;print(hf_hub_download(repo_id='davidkim205/komt-llama2-7b-v1-ggml', filename='ggml-model-q4_0.gguf', local_dir='./models/'))"
make -j && ./main -m ./models/ggml-model-q4_0.gguf -p "์ธ์ผ์ ์ด๋ค ํจ๊ณผ๊ฐ ์๋๊ฐ์? ##output:"
google colab์์ llama.cpp๋ฅผ ์ฌ์ฉํ์ฌ komt๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
https://colab.research.google.com/drive/1uLHXv-6NT7yj4FHECrZezfo5pVL-ht63?usp=sharing
python๊ณผ jupyter๋ฅผ ์ด์ฉํ ์์ ์ ๋๋ค.
$ python infer.py
Downloading (โฆ)/adapter_config.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 528/528 [00:00<00:00, 5.02MB/s]
Downloading (โฆ)lve/main/config.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 631/631 [00:00<00:00, 4.96MB/s]
Downloading pytorch_model.bin: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 27.0G/27.0G [04:29<00:00, 100MB/s]
Downloading (โฆ)neration_config.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 183/183 [00:00<00:00, 1.36MB/s]
Downloading adapter_model.bin: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 80.1M/80.1M [00:00<00:00, 82.7MB/s]
Downloading (โฆ)okenizer_config.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 749/749 [00:00<00:00, 6.66MB/s]
Downloading tokenizer.model: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 500k/500k [00:00<00:00, 111MB/s]
Downloading (โฆ)in/added_tokens.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 21.0/21.0 [00:00<00:00, 131kB/s]
Downloading (โฆ)cial_tokens_map.json: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 96.0/96.0 [00:00<00:00, 608kB/s]
/home/david/anaconda3/envs/komt/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:399: UserWarning: `num_beams` is set to 1. However, `early_stopping` is set to `True` -- this flag is only used in beam-based generation modes. You should set `num_beams>1` or unset `early_stopping`. This was detected when initializing the generation config instance, which means the corresponding file may hold incorrect parameterization and should be fixed.
warnings.warn(
/home/david/anaconda3/envs/komt/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:399: UserWarning: `num_beams` is set to 1. However, `early_stopping` is set to `True` -- this flag is only used in beam-based generation modes. You should set `num_beams>1` or unset `early_stopping`.
warnings.warn(
<s> ### instruction: ๊ณ ์์ด๋ ์ ๋ฌผ์ ์ซ์ดํ๋์?
### Response: ๊ณ ์์ด๋ ์ฌ๋๊ณผ ๋ฌ๋ฆฌ ๋ฌผ์ ์ซ์ดํฉ๋๋ค. ์ด๋ ๋ฌผ์ ๋
น์ ์๋ ํค์ด์ณ๋ฐ๊ณผ ๋ฌผ์ ๋์ ๋๋ฌธ์
๋๋ค. ๊ณ ์์ด๋ ํค์ด์ณ๋ฐ์ด ๋ฌผ์ ๋
น์ ์์ผ๋ฉด ๋ฌผ์ ๋ง์๊ณ ์ถ์ง ์์ํ๋ฉฐ, ๋ฌผ์ ๋์์๋ ๋ฏผ๊ฐํฉ๋๋ค. ์ด๋ฌํ ์ด์ ๋ก ๊ณ ์์ด๋ ๋ฌผ์ ์ซ์ดํ๊ฒ ๋์์ต๋๋ค.
๊ณ ์์ด๋ ์ฌ๋๊ณผ ๋ฌ๋ฆฌ ์ฒด์จ์ด ๋์ ์ฒด์จ์ ์ ์งํ๊ธฐ ์ํด ๋ง์ ์นผ๋ก๋ฆฌ๋ฅผ ํ์๋ก ํฉ๋๋ค. ๋ฐ๋ผ์ ๊ณ ์์ด๋ ๋ฌผ์ ๋ง์์ง ์๊ณ ๋ฌผ์ ์ซ์ดํฉ๋๋ค. ๊ณ ์์ด๋ ์ฒด์จ์ ์ ์งํ๊ธฐ ์ํด ๋ฌผ์ ์ญ์ทจํ์ง ์์ผ๋ฉฐ, ๋ฌผ์ ๋ง์๊ณ ์ถ์ง ์์ต๋๋ค.
๋ํ, ๊ณ ์์ด๋ ๋ฌผ์ ๋ง์๋ฉด ์์ด ์ฐจ๊ฐ์์ง๋ ๋ฑ ๋ฌผ์ ๋
น์ ์๋ ํค์ด์ณ๋ฐ ๋๋ฌธ์ ๋ฌผ์ ์ซ์ดํฉ๋๋ค. ํค์ด์ณ๋ฐ์ ๋ฌผ์ ๋
น์ฌ ์์
๊ณ ์์ด๋ ์ฌ๋๊ณผ ๋ฌ๋ฆฌ ๋ฌผ์ ์ซ์ดํฉ๋๋ค. ์ด๋ ๋ฌผ์ ๋
น์ ์๋ ํค์ด์ณ๋ฐ๊ณผ ๋ฌผ์ ๋์ ๋๋ฌธ์
๋๋ค. ๊ณ ์์ด๋ ํค์ด์ณ๋ฐ์ด ๋ฌผ์ ๋
น์ ์์ผ๋ฉด ๋ฌผ์ ๋ง์๊ณ ์ถ์ง ์์ํ๋ฉฐ, ๋ฌผ์ ๋์์๋ ๋ฏผ๊ฐํฉ๋๋ค. ์ด๋ฌํ ์ด์ ๋ก ๊ณ ์์ด๋ ๋ฌผ์ ์ซ์ดํ๊ฒ ๋์์ต๋๋ค.
๊ณ ์์ด๋ ์ฌ๋๊ณผ ๋ฌ๋ฆฌ ์ฒด์จ์ด ๋์ ์ฒด์จ์ ์ ์งํ๊ธฐ ์ํด ๋ง์ ์นผ๋ก๋ฆฌ๋ฅผ ํ์๋ก ํฉ๋๋ค. ๋ฐ๋ผ์ ๊ณ ์์ด๋ ๋ฌผ์ ๋ง์์ง ์๊ณ ๋ฌผ์ ์ซ์ดํฉ๋๋ค. ๊ณ ์์ด๋ ์ฒด์จ์ ์ ์งํ๊ธฐ ์ํด ๋ฌผ์ ์ญ์ทจํ์ง ์์ผ๋ฉฐ, ๋ฌผ์ ๋ง์๊ณ ์ถ์ง ์์ต๋๋ค.
vllm ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋์ ๊ฐ์ด conda ํ๊ฒฝ์ ์์ฑํํ์ requirements_vllm.txt์ผ๋ก ํจํค์ง๋ค์ ์ค์นํด์ผํฉ๋๋ค.
conda create -n vllm python=3.10
conda activate vllm
pip install -r requirements_vllm.txt
์์ ์ฝ๋๋ ์๋์ ๊ฐ์ด ์คํํํ์ ์ง๋ฌธ์ ์ ๋ ฅํ๋ฉด ๋ฉ๋๋ค.
$ python usage_komt_with_vllm.py
INFO 09-25 18:48:20 llm_engine.py:72] Initializing an LLM engine with config: model='davidkim205/komt-llama2-7b-v1', tokenizer='davidkim205/komt-llama2-7b-v1', tokenizer_mode=auto, trust_remote_code=False, dtype=torch.float16, download_dir=None, load_format=auto, tensor_parallel_size=1, seed=0)
INFO 09-25 18:48:20 tokenizer.py:30] For some LLaMA-based models, initializing the fast tokenizer may take a long time. To eliminate the initialization time, consider using 'hf-internal-testing/llama-tokenizer' instead of the original tokenizer.
INFO 09-25 18:48:36 llm_engine.py:199] # GPU blocks: 1048, # CPU blocks: 512
>์ ์ฃผ๋ ๋ฐ์ดํธ ์ฝ์ค ์๋ ค์ค
Processed prompts: 100%|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 1/1 [00:15<00:00, 15.30s/it]
Prompt: '### instruction: ์ ์ฃผ๋ ๋ฐ์ดํธ ์ฝ์ค ์๋ ค์ค\n\n### Response: ', Generated text: '์ ์ฃผ๋ ๋ฐ์ดํธ ์ฝ์ค ์๋ ค๋๋ฆฌ๊ฒ ์ต๋๋ค.\n1. ์์นจ์ ์ผ์ฐ ์ผ์ด๋์ ์ ์ฃผ์๊ณต์์์ ์์นจ ํด๋์ด๋ฅผ ๋ณด์ฉฐ ์ธ์ฌ๋ฅผ ๋๋ฆฝ๋๋ค.\n2. ์๊ณต์์ ๋์๋ค๋๋ฉฐ ์์ฐ์ ์๋ฆ๋ค์์ ๋ง๋ฝํฉ๋๋ค. ํนํ, ์ฉ๋๋ณด ํญํฌ๋ฅผ ๊ฑด๋ ๋ค๋๋ฉฐ ๋ฉ์ง ๊ฒฝ์น๋ฅผ ๊ฐ์ํฉ๋๋ค.\n3. ์คํ 1์์ฏค ์ ์ฃผ์์ ์ ๋ช
ํ ํฅ๊ธฐ๋ฅผ ๋งก์ ์ ์๋ ์ฑ์ฐ์ผ์ถ๋ด ๊ทผ์ฒ ํผ์ฆ์ ํ์ด๋ณด์ธ์. ์ฌ๊ธฐ์์๋ ๋
ธ๋๋ฐฉ, ์คํ์ฌ ๊ฐ์ฐ, ์์ปคํ ์ปจ์ํธ, ํ๋ผ์ฐ์ฑ ๋ฐ๊ฒฌ ์ฌ์ ๋ฑ ํฅ๋ฏธ๋ก์ด ์ฒดํ์ ํ ์ ์์ต๋๋ค.\n4. ์ ์ฃผํน์ ์ ๋ค์ํ ํด์ฐ๋ฌผ (ํด์ด, ๊น์น, ํด์ ๋ฑ)์ ๊ตฌ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด, ์์ฃผ์ง๋ค๋ฏธ๋ ์ ์ฃผ์์ ์ ํต์์ฅ์ ๋ฐฉ๋ฌธํด๋ณด์ธ์. ํด์ฐ๋ฌผ ์ฌ์ฐฐ ๊ทผ์ฒ์ ์์นํ ํน์์์ฅ์์๋ ์ ์ฃผ๊ฐ๊ทค์ ๋ง๋ณผ ์ ์์ต๋๋ค.\n5. ๋ง์ง๋ง์ผ๋ก ์ ๋
์๋ ์ฑ์ฐ์ผ์ถ๋ด์์ ํ๋ผ์ฐ์ ์ผ์ถ์ ๋ณผ ์ ์์ต๋๋ค. ์ผ์ถ์ ๊ฐ์ํ๋ฉฐ ๊ทธ ์๋ฆ๋ค์์ ๋ํ ๊ฐ์ฌ๋ฅผ ํํํฉ๋๋ค.\n\n์ด์ ์ ์ฃผํน๋ณ์ ๋งค๋ ฅ์ ์ฆ๊ธฐ์ค ์ค๋น๊ฐ ๋์
จ๋์? ํ๋ ์ผ์์์ ๋ฒ์ด๋ ์ฌ์ ๋ก์์ ๋๋ ์ ์๋ ์ ์ฃผ๋ ๋ฐ์ดํธ ์ฝ์ค๋ฅผ ์ฆ๊ธฐ๋ณด์ธ์.'
komt-llama2 ๋ชจ๋ธ์ ํ์ต์ํค๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค.
๋ ผ๋ฌธ๊ณผ ๋ฐฐํฌํ ๋ชจ๋ธ์ ์ฌ์ฉํ ๋ฐ์ดํฐ์ ์ค ๋ผ์ด์ผ์ค๊ฐ ์๋ KorQuAD 1.0 ๋ฐ์ดํฐ์ ์ datasets์ ์ถ๊ฐํ์ต๋๋ค.
๋ ผ๋ฌธ์ ๋ํ ์์ธํ ๋ด์ฉ์ ์๋ Korean Multi-task Instruction Tuning ๋ฅผ ์ฐธ๊ณ ํ์ธ์.
๋จผ์ github์์ ์ฝ๋๋ฅผ ๋ฐ์ํ ํจํค์ง๋ฅผ ์ค์นํฉ๋๋ค.(์ setup์ฐธ์กฐ)
finetune_with_lora.py๋ custom dataset์ ์ด์ฉํ์ฌ ๋ชจ๋ธ ํ์ต์ ์ํ ์ฝ๋์ ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์๋์ ๊ฐ์ด argument๊ฐ ์์๊ฒฝ์ฐ default๋ก davidkim205/komt-llama2-7b-v1๋ชจ๋ธ์ base๋ก komt_squad.json๋ก ํ์ต์ด ์งํ๋ฉ๋๋ค.
python finetune_with_lora.py
๋ชจ๋ธ์ด๋ dataset ์ด๋ batchsize๋ฑ์ ์๋์ ๊ฐ์ด ์์ ์ด ๊ฐ๋ฅํฉ๋๋ค.
python finetune_with_lora.py --model_name_or_path davidkim205/komt-llama2-7b-v1 --data_path datasets/komt_squad.json --num_train_epochs 1 --per_device_train_batch_size 1 --learning_rate 1e-5
๋ณด๋ค ์์ธํ argument์ ๋ํ ์์ธํ ์ค๋ช
์ python finetune_with_lora.py -h ํ์ธํ์ธ์.
finetune_with_lora.py๋ ๊ธฐ๋ณธ์ ์ผ๋ก 4-bit๋ก ์์ํํ์ฌ ํ์ต์ ํฉ๋๋ค. 8bit๋ก ์์ํํ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
python finetune_with_lora.py --bits 8
finetune_with_ds.py์ DeepSpeed๊ธฐ๋ฐ์ผ๋ก ZeRO-3 Offload์ ์ฌ์ฉํ์ฌ ํ์ต์ ํฉ๋๋ค. CPU Offloading์ ํตํ์ฌ GPU ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์ค์ง๋ง CPU ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ธฐ๋๋ฌธ์ hw ์ฌ์์ ๋ง๊ฒ ์กฐ์ ์ ํด์ผํฉ๋๋ค. deepspeed ํ์ผ์ configs/deepseed_config.json์ ์ถ๊ฐํ์์ต๋๋ค.
deepspeed๋ฅผ ์ด์ฉํ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด conda ํ๊ฒฝ์ ์ถ๊ฐํ๋ค์ ํด๋น ํจํค์ง๋ฅผ ์ค์นํด์ผ ํฉ๋๋ค.
conda create -n ds python=3.10
conda activate ds
pip install -r requirements_ds.txt
finetune_with_deepspeed ์ฌ์ฉ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ์ต๋๋ค.
deepspeed finetune_with_ds.py
argument ์์ ์ ์๋๋ฅผ ์ฐธ๊ณ ํ์ธ์.
deepspeed finetune_with_ds.py --model_name_or_path davidkim205/komt-llama2-7b-v1 --data_path datasets/komt_squad.json --num_train_epochs 1 --per_device_train_batch_size 1 --learning_rate 1e-5 --deepspeed configs/deepspeed_config.json
์์ฉ์๋น์ค๋ฅผ ์ํ Direct Preference Optimization๋ฅผ ์ด์ฉํ์ฌ ๋ชจ๋ธ ํ์ตํ ์ ์๋๋ก train ์ฝ๋์ ๋ชจ๋ธ์ ๊ณต๊ฐํฉ๋๋ค.
DPO ํ์ต์ด ์๋๋ ค๋ฉด SFT๋ฅผ ์ํด์ผ ํ๋๋ฐ ์ด๋ฏธ ํ์ต๋ komt๋ฅผ ์ด์ฉํ์ฌ ๋ชจ๋ธ์ ํ์ตํ์๊ณ , ๊ธฐ์กด ๋ชจ๋ธ๋๋น 5% ์ฑ๋ฅํฅ์์ด ์์์ผ๋ฉฐ ๋์ผํ ์ง๋ฌธ์ ๋์ผํ ๋ต๋ณ์ ํ ์ ์๋ ๋ชจ๋ธ์ ๊ฐ๋ฐํ์์ต๋๋ค.
ํ๊ธ ๋ฐ์ดํฐ์ ์ maywell/ko_Ultrafeedback_binarized ์ ์ฌ์ฉํ์์ต๋๋ค.
dpo_train.py ๋ฅผ ์คํํ๊ธฐ ์ํ์ฌ requirements_dpo.txt๋ฅผ ์ค์นํ์ฌ์ผ ํฉ๋๋ค. ์ค์น์์ ๋๋ค.
conda create -n dpo_train python=3.10
conda activate dpo_train
pip install -r requirements_dpo.txt
์ค์นํ accelerate config๋ฅผ ์ด์ฉํ์ฌ accelerate config ์ค์ ํฉ๋๋ค.
accelerate config
๊ทธ ํ์ accelerate launch๋ฅผ ํตํ์ฌ dpo_train์ ํฉ๋๋ค.
accelerate launch dpo_train.py
A100 1๋๊ธฐ์ค์ผ๋ก 9์๊ฐ ์ ๋ ๊ฑธ๋ฆฝ๋๋ค.
warnings.warn(
0%| | 1/1000 [00:36<10:13:09, 36.83s/it]Token indices sequence length is longer than the specified maximum sequence length for this model (1069 > 1024). Running this sequence through the model will result in indexing errors
{'loss': 0.6961, 'learning_rate': 5e-05, 'rewards/chosen': 0.004012207966297865, 'rewards/rejected': 0.007965649478137493, 'rewards/accuracies': 0.515625, 'rewards/margins': -0.003953440580517054, 'logps/rejected': -222.7124481201172, 'logps/chosen': -259.6094665527344, 'logits/rejected': -2.6427276134490967, 'logits/chosen': -2.6100172996520996, 'epoch': 0.01}
2%|โ | 17/1000 [09:31<8:50:11, 32.36s/it]
dpo์ ๋ํ ์์ธํ ๋ด์ฉ์ ๋ค์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์. https://arxiv.org/abs/2305.18290
chatgpt๋ฅผ ์ด์ฉํ์ฌ ์ง๋ฌธ๊ณผ ๋๋ต์๋ํ ํ๊ฐ๋ฅผ ์๋์ ๊ฐ์ด ์งํํ์์ต๋๋ค. ๋ชจ๋ธ ํ๊ฐ๋ฅผ ์ํ ์ง๋ฌธ๊ณผ ๋ต๋ณ chatgpt์ ํ๊ฐ ๊ฒฐ๊ณผ๋ eval_results๋ฅผ ์ฐธ๊ณ ํ์ธ์.
| model | score | average(0~5) | percentage |
|---|---|---|---|
| gpt-3.5-turbo(close) | 147 | 3.97 | 79.45% |
| naver Cue(close) | 140 | 3.78 | 75.67% |
| clova X(close) | 136 | 3.67 | 73.51% |
| WizardLM-13B-V1.2(open) | 96 | 2.59 | 51.89% |
| Llama-2-7b-chat-hf(open) | 67 | 1.81 | 36.21% |
| Llama-2-13b-chat-hf(open) | 73 | 1.91 | 38.37% |
| nlpai-lab/kullm-polyglot-12.8b-v2(open) | 70 | 1.89 | 37.83% |
| kfkas/Llama-2-ko-7b-Chat(open) | 96 | 2.59 | 51.89% |
| beomi/KoAlpaca-Polyglot-12.8B(open) | 100 | 2.70 | 54.05% |
| komt-llama2-7b-v1 (open)(ours) | 117 | 3.16 | 63.24% |
| komt-llama2-13b-v1 (open)(ours) | 129 | 3.48 | 69.72% |
| komt-llama-30b-v1 (open)(ours) | 129 | 3.16 | 63.24% |
| komt-mistral-7b-v1 (open)(ours) | 131 | 3.54 | 70.81% |
| komt-mistral-7b-v1-dpo (open)(ours) | 142 | 3.83 | 76.75% |
With the recent success of ChatGPT, numerous large language models have emerged in an attempt to catch up with ChatGPT's capabilities. However, it has become evident that these models still struggle to provide accurate responses in Korean or face challenges when generating Korean text. In this study, we introduce the multi-task instruction technique, which is based on supervised datasets from various tasks, to create training data for large language models, aiming to address these issues.
The recent Korean large language models, such as GPT-4-LLM, Dolly, and Vicuna, have predominantly relied on translated datasets. However, using translated datasets presents several challenges:
-
Language and Cultural Differences Languages and cultures have unique expressions, vocabularies, and grammatical structures. Using translated datasets can hinder the model's ability to understand and learn effectively due to these differences.
-
Translation Errors and Semantic Distortions Machine translations are not perfect and can introduce errors or distort the meaning of the original text. This can lead to the model learning incorrect information or failing to grasp the true meaning of the source data.
-
Data Quality The quality of translated data depends on the accuracy of the source data. If the source data is inaccurate or noisy, the translated data can suffer from the same issues.
-
Word Embedding Consistency Mapping words from different languages into a consistent embedding space can be challenging. This can result in the model failing to learn the correct relationships between words or failing to recognize semantic differences among translated words.
-
Data Quantity and Diversity Using translated foreign datasets may not provide sufficient quantity and diversity of data, depending on the language and topic domain. Obtaining the required data quantity and diversity can be challenging.
-
Difficulty in Understanding Context Translated data often fails to convey the original context accurately, making it difficult for the model to understand the real meaning and context of specific words or sentences.
-
Specialized Terminology and Idiomatic Expressions Specialized terminology and idiomatic expressions in specific fields may not be appropriately handled during translation, causing the model to perform poorly in certain subjects or domains.
-
Data Bias Translating data from various countries and cultures can introduce biases or cultural differences into the model, potentially increasing bias in the model's responses.
-
Performance Degradation When original data is translated, some information may be lost in the translation process, leading to a potential decrease in the model's performance compared to using the original data directly.
To address these challenges and improve dataset quality, we propose an Instruction Turning Framework (ITF) that leverages multi-task datasets and instruction tuning, inspired by Google's FLAN (Finetuned LANguage Models are zero-shot Learners) technique.
We have curated multi-task datasets based on various existing Korean datasets, specifically tailored to each task. We have avoided relying on translated datasets used in previous Korean large language models. Our dataset sources include:
- AIHub Dataset: 305,900 samples
- KISTI AI Dataset: 824,337 samples
- KorQuad Dataset: 66,181 samples
- Miscellaneous Datasets: 346,803 samples
- Total Dataset Size: 1,543,221 samples
Our ITF incorporates the instruction tuning technique proposed by Google's FLAN, resulting in improved zero-shot performance. We have publicly released the freely licensed KorQuad 1.0 dataset on GitHub. However, due to licensing policies, we cannot release the other datasets.
For objective model evaluation, we initially used EleutherAI's lm-evaluation-harness but obtained unsatisfactory results. Consequently, we conducted evaluations using ChatGPT, a widely used model, as described in Self-Alignment with Instruction Backtranslation and Three Ways of Using Large Language Models to Evaluate Chat .
| model | score | average(0~5) | percentage |
|---|---|---|---|
| gpt-3.5-turbo(close) | 147 | 3.97 | 79.45% |
| naver Cue(close) | 140 | 3.78 | 75.67% |
| clova X(close) | 136 | 3.67 | 73.51% |
| WizardLM-13B-V1.2(open) | 96 | 2.59 | 51.89% |
| Llama-2-7b-chat-hf(open) | 67 | 1.81 | 36.21% |
| Llama-2-13b-chat-hf(open) | 73 | 1.91 | 38.37% |
| nlpai-lab/kullm-polyglot-12.8b-v2(open) | 70 | 1.89 | 37.83% |
| kfkas/Llama-2-ko-7b-Chat(open) | 96 | 2.59 | 51.89% |
| beomi/KoAlpaca-Polyglot-12.8B(open) | 100 | 2.70 | 54.05% |
| komt-llama2-7b-v1 (open)(ours) | 117 | 3.16 | 63.24% |
| komt-llama2-13b-v1 (open)(ours) | 129 | 3.48 | 69.72% |
| komt-llama-30b-v1 (open)(ours) | 129 | 3.16 | 63.24% |
| komt-mistral-7b-v1 (open)(ours) | 131 | 3.54 | 70.81% |
In this study, we have proposed a method to optimize the Llama2 model for the Korean language. Experimental results demonstrate that the use of multi-task instruction outperforms other Korean-supporting Llama2 models, showcasing its superior performance. Furthermore, multi-task instruction exhibits excellent performance. In future research, we plan to leverage multi-task instruction to develop various service models and applications.
https://github.com/facebookresearch/llama