|
Download README.md from JosephLee/modu-llm: direct link, hf CLI and curl.
- Browser
- Download file 7.19 kB
-
https://huggingface.co/JosephLee/modu-llm/resolve/main/README.md
- Command line
-
hf download hf://JosephLee/modu-llm/README.md
-
curl -L -o README.md https://huggingface.co/JosephLee/modu-llm/resolve/main/README.md
7.19 kB
| license: cc-by-4.0 | |
| language: | |
| - ko | |
| library_name: pytorch | |
| pipeline_tag: text-generation | |
| datasets: | |
| - psymon/Tiny-Ko-Stories | |
| - JosephLee/tiny-ko-stories-sft | |
| - JosephLee/tiny-ko-stories-feedback | |
| tags: | |
| - korean | |
| - children-stories | |
| - gpt | |
| - education | |
| - from-scratch | |
| - dpo | |
| # modu-llm: ํ๊ตญ์ด ์ด๋ฆฐ์ด ์ด์ผ๊ธฐ๋ฅผ ์ฐ๋ ์์ GPT | |
| ใ๋ชจ๋์ LLM with ํ์ด์ฌใ(์ด์ํธ)์ ์ค์ต ๋ชจ๋ธ ํ์ผ์ ๋๋ค. ์ฑ ์์ ์ฒ์๋ถํฐ ๋ง๋ ์ฝ 609๋ง ๊ฐ ํ๋ผ๋ฏธํฐ์ ๊ธ์ ๋จ์ GPT๋ฅผ ํ๊ตญ์ด ์ด๋ฆฐ์ด ์ด์ผ๊ธฐ๋ก ์ฌ์ ํ์ตํ๊ณ , ์์ฒญ-์ด์ผ๊ธฐ ์ง์ผ๋ก ํ์ธํ๋ํ ๋ค, ์ ํธ ๋ฐ์ดํฐ ์ง์ผ๋ก ํ ๋ฒ ๋ ํ์ต(ํผ๋๋ฐฑ ํ์ต, DPO)ํ์ต๋๋ค. | |
| ์ค์ต ์ฝ๋์ ๋ ธํธ๋ถ: https://github.com/yhlee1627/modu-llm-v2 | |
| ## ํ์ผ | |
| | ํ์ผ | ๋ด์ฉ | ์ฑ ์์ ์ฐ๋ ๊ณณ | | |
| |---|---|---| | |
| | `pretrain.pt` | ์ฌ์ ํ์ต์ ๋ง์น ๋ชจ๋ธ๊ณผ ์ตํฐ๋ง์ด์ ์ํ (27,251๋ฒ ํ์ต) | 1~7์ฅยท13~14์ฅ์ ์ด์ผ๊ธฐ LLM, 11ยท12์ฅ | | |
| | `ckpt_step250.pt`, `ckpt_step1000.pt`, `ckpt_step3000.pt` | ์ฌ์ ํ์ต ๋์ค์ ๋ชจ๋ธ (์ตํฐ๋ง์ด์ ์์) | 2์ฅ, 6์ฅ, 7์ฅ ๋์ดํฐ | | |
| | `sft.pt` | ์์ฒญ-์ด์ผ๊ธฐ ์ง์ผ๋ก ํ์ธํ๋ํ ๋ชจ๋ธ๊ณผ ์ตํฐ๋ง์ด์ ์ํ (3,400๋ฒ ํ์ต) | 2์ฅ, 12์ฅ | | |
| | `feedback.pt` | ํ์ธํ๋ ๋ชจ๋ธ์ ์ ํธ ๋ฐ์ดํฐ ์ง์ผ๋ก ํ ๋ฒ ๋ ํ์ตํ ๋ชจ๋ธ (์ตํฐ๋ง์ด์ ์์) | 2์ฅ | | |
| ๊ฐ ํ์ผ์ `torch.save`๋ก ์ ์ฅํ ๋์ ๋๋ฆฌ์ด๊ณ `cfg`(๋ชจ๋ธ ์ค์ ), `model`(๊ฐ์ค์น), `optimizer`, `step`, `history`(์์ค ๊ธฐ๋ก)๋ฅผ ๋ด๊ณ ์์ต๋๋ค. `feedback.pt`์ `step`๊ณผ `history`๋ ์ถ๋ฐ์ ์ธ `sft.pt`์ ๊ฐ์ ๊ทธ๋๋ก ๋ ๊ฒ์ ๋๋ค. | |
| ## ๋ชจ๋ธ | |
| | ํญ๋ชฉ | ๊ฐ | | |
| |---|---| | |
| | ๊ตฌ์กฐ | GPT(๋์ฝ๋ ์ ์ฉ Transformer), ๊ตฌ์กฐ๋ nanoGPT ์ฐธ๊ณ | | |
| | ํ ํฐ | ๊ธ์ ํ๋ = ํ ํฐ ํ๋. ๊ณ ์ ๊ธ์ ์ฌ์ 2,453์(์์ฃผ ์ฐ๋ ํ๊ธ 2,350์ + ์๋ฌธยท์ซ์ยท๊ธฐํธ + ์ด์ผ๊ธฐ ๋ ํ์ `ยง`) | | |
| | ๋ฌธ๋งฅ ๊ธธ์ด | 384๊ธ์ | | |
| | ๋ฒกํฐ ๊ธธ์ด / ํค๋ / ์ธต | 256 / 4 / 6 | | |
| | ํ๋ผ๋ฏธํฐ | 6,091,157๊ฐ | | |
| ## ํ์ต | |
| **์ฌ์ ํ์ต** (`pretrain.pt`) | |
| - ๋ฐ์ดํฐ: [Tiny-Ko-Stories](https://huggingface.co/datasets/psymon/Tiny-Ko-Stories) ์์ชฝ ์ด์ผ๊ธฐ 200,000ํธ(์ฝ 7,160๋ง ๊ธ์), 90%๋ ํ์ต์ฉ, 10%๋ ๊ฒ์ฆ์ฉ | |
| - Google Colab T4 GPU์์ 30๋ถ(27,251๋ฒ ํ์ต), ๋ฐฐ์น 32, AdamW(ํ์ต๋ฅ 5e-4), ๋ฐ์ ๋ฐ๋(float16 autocast) | |
| - ๋๋ฌ์ ๋ ์์ค: ํ์ต 0.751, ๊ฒ์ฆ 0.771 | |
| **ํ์ธํ๋** (`sft.pt`) | |
| - ๋ฐ์ดํฐ: [Tiny-Ko-Stories SFT](https://huggingface.co/datasets/JosephLee/tiny-ko-stories-sft) ํ์ต์ฉ 43,852์, ๊ฒ์ฆ์ฉ 2,308์ | |
| - `pretrain.pt`์์ ์ด์ด ํ์ต, T4์์ 5๋ถ, AdamW(ํ์ต๋ฅ 1e-4) | |
| - ๊ฒ์ฆ ์์ค์ด ๊ฐ์ฅ ๋ฎ์๋ 3,400๋ฒ์งธ(๊ฒ์ฆ 0.665)๋ฅผ ์ ์ฅ | |
| **ํผ๋๋ฐฑ ํ์ต** (`feedback.pt`) | |
| - ๋ฐ์ดํฐ: [Tiny-Ko-Stories Feedback](https://huggingface.co/datasets/JosephLee/tiny-ko-stories-feedback) ์ ํธ ๋ฐ์ดํฐ 920์. ์ฌ๋์ด ํ๋ํ๋ ๊ณ ๋ฅด๋ ๋์ ๊ท์น์ผ๋ก ๋ ์ข์ ๋ต์ ๊ณจ๋์ต๋๋ค. ์์ฒญ์ด ์ด์ผ๊ธฐ ๋ถํ์ด๋ฉด ์ด์ผ๊ธฐ๊ฐ, ์ด์ผ๊ธฐ๊ฐ ์๋ ์ง๋ฌธ์ด๋ฉด "๊ทธ ์ง๋ฌธ์ ๋ต์ ๋ชฐ๋ผ์. โฆ"๋ผ๋ ๋ต์ด ๋ ์ข์ ๋ต์ ๋๋ค. | |
| - `sft.pt`์์ ์์ํด DPO(beta 0.1)๋ก ํ์ตํ์ต๋๋ค. ๊ธฐ์ค ๋ชจ๋ธ์ `sft.pt`์ ๋๋ค. DPO๋ง์ผ๋ก๋ ์ง์ด๋ธ ์ด์ผ๊ธฐ๋ฅผ ๋ฐ์ด๋ด๊ธฐ๋ง ํ๊ณ ๋ชจ๋ฅธ๋ค๋ ๋ต์ด ๋์ค์ง ์์์, ๋ ์ข์ ๋ต์ ๊ธ์๋น ์์ค๋ ํจ๊ป ์ค์์ต๋๋ค(๊ฐ์ค์น 1.0). | |
| - AdamW(ํ์ต๋ฅ 5e-5), ์ง 16๊ฐ์ฉ 174๋ฒ(๋ฐ์ดํฐ ์ธ ๋ฐํด), CPU์์ ์ฝ 7๋ถ | |
| - ํ์ต ๋ฐ์ดํฐ์ ์๋ ์ง๋ฌธ 8๊ฐ๋ฅผ ์ธ ๋ฒ์ฉ ๋ฌผ์ผ๋ฉด 24๋ฒ ๊ฐ์ด๋ฐ 21๋ฒ ๋ชจ๋ฅธ๋ค๊ณ ๋ตํ๊ณ , ์ด์ผ๊ธฐ ๋ถํ 5๊ฐ๋ฅผ ์ธ ๋ฒ์ฉ ํ๋ฉด 15๋ฒ ๋ชจ๋ ์ด์ผ๊ธฐ๋ฅผ ์๋๋ค. ์์ฒญ-์ด์ผ๊ธฐ ํ์ธ์ฉ ๋ฐ์ดํฐ์ ์์ค์ 0.645(ํ์ธํ๋)์์ 0.657๋ก ๊ฑฐ์ ๊ฐ์ต๋๋ค. | |
| ## ์ฐ๋ ๋ฒ | |
| ```python | |
| %pip install -q git+https://github.com/yhlee1627/modu-llm-v2 | |
| from modu_llm import load_story_llm | |
| fb = load_story_llm("feedback") # "pretrain", "sft", "feedback", "step250" โฆ | |
| fb.ask("๋ํ๋ฏผ๊ตญ์ ์๋๋ ์ด๋์ผ?", length=150) | |
| fb.ask("ํ ๋ผ๊ฐ ๋์ค๋ ์งง์ ์ด์ผ๊ธฐ๋ฅผ ์จ ์ค", length=150) | |
| ``` | |
| ๋ถํ์ ์ง์ ๋ค๋ฃจ๋ ค๋ฉด ๋ค์์ฒ๋ผ ๋ถ๋ฌ์ต๋๋ค. | |
| ```python | |
| from modu_llm import Vocab, load_checkpoint, get_file, generate, format_pair | |
| vocab = Vocab.build() | |
| model, _, step, _ = load_checkpoint(get_file("sft.pt"), "cpu") | |
| print(generate(model, vocab, format_pair("์ฒ์์์ ํ ๋ผ ๋ณด๋ฆฌ๊ฐ ๋์ค๋ ์ด์ผ๊ธฐ๋ฅผ ๋ค๋ ค์ค"), max_new_tokens=300)) | |
| ``` | |
| `get_file`์ ๊ตฌ๊ธ ๋๋ผ์ด๋ธ๋ ํ์ฌ ํด๋์ ๊ฐ์ ์ด๋ฆ์ ํ์ผ์ด ์์ผ๋ฉด ๊ทธ๊ฒ์ ์ฐ๊ณ , ์์ผ๋ฉด ์ด ์ ์ฅ์์์ ๋ด๋ ค๋ฐ์ต๋๋ค. | |
| ## ํ๊ณ์ ์ฐ์ | |
| - ๊ต์ก์ฉ ๋ชจ๋ธ์ ๋๋ค. LLM์ด ์ด๋ป๊ฒ ์์ง์ด๋์ง ๋ฐฐ์ฐ๋ ค๊ณ ๋ง๋ ๊ฒ์ผ๋ก, ์ค์ ์๋น์ค์ ์ฐ๊ธฐ์๋ ์๋ง์ง ์์ต๋๋ค. | |
| - ์ด๋ฆฐ์ด ์ด์ผ๊ธฐ๋ง ๋ฐฐ์ ์ต๋๋ค. ์ฌ์ ํ์ตยทํ์ธํ๋ ๋ชจ๋ธ์ ์ฌ์ค ์ง๋ฌธ, ๊ณ์ฐ, ์์ด ์์ฒญ์๋ ์ด๋ฆฐ์ด ์ด์ผ๊ธฐ๋ก ๋ตํฉ๋๋ค. ํผ๋๋ฐฑ ํ์ต ๋ชจ๋ธ์ ์ด๋ฐ ์ง๋ฌธ์ ๋๊ฐ ๋ชจ๋ฅธ๋ค๊ณ ๋ตํ์ง๋ง ๋ ๊ทธ๋ ์ง๋ ์๊ณ , ์ ์ง์์ ๋ฐฐ์ด ๊ฒ๋ ์๋๋๋ค. | |
| - ์์ ์ฅ์น๊ฐ ์์ต๋๋ค. ํ์ต ๋ฐ์ดํฐ๋ ์ฌ๋ฌ AI ๋ชจ๋ธ๋ก ๋ง๋ ํฉ์ฑ ๋ฐ์ดํฐ์ด๋ฉฐ, ์๋ณธ ๋ฐ์ดํฐ ์นด๋์ ๊ถ์ฅํ์ง ์๋ ์ฉ๋(์ฌ์ค ์ง์์๋ต, ์ฌ๋ ๊ฒ์ ์์ด ์ด๋ฆฐ์ด์๊ฒ ์ง์ ์ ๊ณต ๋ฑ)๊ฐ ์ด ๋ชจ๋ธ์๋ ๊ทธ๋๋ก ์ ์ฉ๋ฉ๋๋ค. | |
| - ์ฌ์ ์ ์๋ ๊ธ์(์์ฃผ ์ฐ์ง ์๋ ํ๊ธ, ํ์, ์ด๋ชจํฐ์ฝ ๋ฑ)๋ ๊ฑด๋๋๋๋ค. | |
| ## ๋ผ์ด์ ์ค์ ์ถ์ฒ | |
| ์ด ๋ชจ๋ธ ํ์ผ๋ค์ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)์ผ๋ก ๊ณต๊ฐํฉ๋๋ค. ์ฐ๊ฑฐ๋ ๋๋ ๋๋ ์ด ์ ์ฅ์์ ํ์ต ๋ฐ์ดํฐ์ ์ถ์ฒ๋ฅผ ํจ๊ป ๋ฐํ ์ฃผ์ธ์. | |
| - ํ์ต ๋ฐ์ดํฐ: Tiny-Ko-Stories (psymon), CC BY 4.0, https://huggingface.co/datasets/psymon/Tiny-Ko-Stories | |
| - ํ์ธํ๋ ๋ฐ์ดํฐ: Tiny-Ko-Stories SFT (JosephLee), CC BY 4.0, https://huggingface.co/datasets/JosephLee/tiny-ko-stories-sft | |
| - ์ ํธ ๋ฐ์ดํฐ: Tiny-Ko-Stories Feedback (JosephLee), CC BY 4.0, https://huggingface.co/datasets/JosephLee/tiny-ko-stories-feedback | |
| - ๋ชจ๋ธ ๊ตฌ์กฐ ์ฐธ๊ณ : nanoGPT (Andrej Karpathy), MIT, https://github.com/karpathy/nanoGPT | |
| - ์ค์ต ์ฝ๋: https://github.com/yhlee1627/modu-llm-v2, MIT | |
| ์ถ์ฒ ํ๊ธฐ ์: | |
| ``` | |
| modu-llm (JosephLee), CC BY 4.0, https://huggingface.co/JosephLee/modu-llm | |
| โ trained on Tiny-Ko-Stories (psymon), CC BY 4.0 | |
| ``` | |
| --- | |
| **English summary.** Model files for the Korean book *๋ชจ๋์ LLM with ํ์ด์ฌ* (Everyone's LLM with Python). A 6.1M-parameter character-level GPT trained from scratch on 200,000 Korean children's stories from [Tiny-Ko-Stories](https://huggingface.co/datasets/psymon/Tiny-Ko-Stories), fine-tuned on requestโstory pairs ([Tiny-Ko-Stories SFT](https://huggingface.co/datasets/JosephLee/tiny-ko-stories-sft)), then trained with DPO on 920 rule-chosen preference pairs ([Tiny-Ko-Stories Feedback](https://huggingface.co/datasets/JosephLee/tiny-ko-stories-feedback)) so that it declines non-story questions instead of making up a story. For education only. Licensed under CC BY 4.0; please credit this repository and the training data. | |