pathcosmos commited on
Commit
cceae9d
ยท
verified ยท
1 Parent(s): 29fc577

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +309 -84
README.md CHANGED
@@ -3,6 +3,8 @@ language:
3
  - ko
4
  - en
5
  license: mit
 
 
6
  tags:
7
  - mamba2
8
  - hybrid
@@ -12,49 +14,226 @@ tags:
12
  - dpo
13
  - slerp
14
  - orpo
15
- library_name: pytorch
16
- pipeline_tag: text-generation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ---
18
 
19
- # EVAFRILL-Mo 3B โ€” Hybrid Mamba-2 + Transformer
20
 
21
- **A 3-billion-parameter hybrid Mamba-2 + Transformer language model built from scratch.**
22
 
23
- Inspired by the NVIDIA [Nemotron-H](https://arxiv.org/abs/2504.03624) architecture. Pretrained on 55B tokens across Korean, English, code, and math using 7ร— NVIDIA B200 GPUs.
24
 
25
- ## Model Variants
26
 
27
- This repository contains **7 model versions** representing each stage of the training pipeline, plus training data and scripts for full reproducibility.
28
 
29
- | Variant | Directory | Size | Description | Recommended |
30
- |---------|-----------|------|-------------|:-----------:|
31
- | **SLERP** | `slerp/` | 6.3GB | SFT + DPO merged (ฮฑ=0.5) | โญ **Yes** |
32
- | Pretrain | `pretrain/` | 12.6GB | Base model (319K steps, 55B tokens) | |
33
- | SFT v2 | `sft-v2/` | 6.3GB | Instruction-tuned (65K steps) | |
34
- | DPO R1 | `dpo-r1/` | 6.3GB | Preference-aligned Round 1 | |
35
- | DPO R2 | `dpo-r2/` | 6.3GB | Conservative fine-tuning Round 2 | |
36
- | ORPO | `orpo/` | 6.3GB | SFT+alignment simultaneous (experimental) | |
37
- | DPO R3 | `dpo-r3/` | 6.3GB | Repetition-targeted (experimental) | |
38
 
39
- ## Training Pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  ```
42
  Pretrain (55B tokens, 7ร—B200, 60h)
43
- โ†“
44
- SFT v2 (65K steps, H100 MIG, 5 days)
45
- โ†“
46
- DPO Round 1 (3K steps, LoRA, loss 0.693โ†’0.565)
47
- โ†“
48
- DPO Round 2 (2K steps, conservative, loss 0.692โ†’0.689)
49
- โ†“
50
- SLERP Merge (ฮฑ=0.5, SFT 50% + DPO 50%) โ† RECOMMENDED
51
- โ†“
52
- ORPO Experiment (10K steps, alternative approach)
53
- โ†“
54
- DPO Round 3 (1K steps, repetition-targeted experiment)
55
  ```
56
 
57
- ## Architecture
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  ```
60
  Type: Hybrid Mamba-2 + Transformer
@@ -65,82 +244,128 @@ Vocabulary: 64,000 (custom SentencePiece)
65
  Max seq length: 4,096
66
  ```
67
 
68
- ## Benchmark Results (SLERP, recommended model)
69
-
70
- | Metric | Value |
71
- |--------|-------|
72
- | Greedy 3-gram repetition | 74.5% (โ†’ 5.5% with rep_penalty=1.2) |
73
- | hellaswag (0-shot) | 34.6% |
74
- | arc_easy (0-shot) | 32.0% |
75
- | belebele_kor (0-shot) | 23.6% |
76
- | global_mmlu_ko (0-shot) | 23.7% |
77
 
78
- **Recommended inference**: `temperature=0.7, repetition_penalty=1.2`
79
 
80
- ## SFTโ†’DPOโ†’SLERP vs ORPO Comparison
81
-
82
- | Metric | SLERP | ORPO | Winner |
83
- |--------|:-----:|:----:|:------:|
84
- | Greedy repetition | **74.5%** | 87.1% | SLERP |
85
- | Chat quality | โœ… Fluent | โŒ Broken | SLERP |
86
- | hellaswag | **39.0%** | 35.0% | SLERP |
87
- | Training time | 5d+8h | **12.8h** | ORPO |
88
 
89
- ORPO's weakness: insufficient SFT learning at 10K steps (vs SFT's 65K).
 
 
 
 
 
 
 
 
90
 
91
- ## Repository Structure
92
 
93
  ```
94
- โ”œโ”€โ”€ slerp/ # โญ Recommended final model
95
- โ”œโ”€โ”€ pretrain/ # Base pretrained model
96
- โ”œโ”€โ”€ sft-v2/ # SFT instruction-tuned
97
- โ”œโ”€โ”€ dpo-r1/ # DPO Round 1 + LoRA weights
98
- โ”œโ”€โ”€ dpo-r2/ # DPO Round 2 + LoRA weights
99
- โ”œโ”€โ”€ orpo/ # ORPO experiment + LoRA weights
100
- โ”œโ”€โ”€ dpo-r3/ # DPO Round 3
101
- โ”œโ”€โ”€ data/ # Preference datasets for reproducibility
102
- โ”‚ โ”œโ”€โ”€ combined_preference.jsonl (684K pairs, 2.6GB)
103
- โ”‚ โ””โ”€โ”€ repetition_preference.jsonl (105 pairs, self-generated)
104
- โ”œโ”€โ”€ configs/ # Training YAML configs
105
- โ”‚ โ”œโ”€โ”€ korean_3b_sft_1gpu.yaml
106
- โ”‚ โ”œโ”€โ”€ dpo_3b_1gpu.yaml
107
- โ”‚ โ””โ”€โ”€ orpo_3b_1gpu.yaml
108
- โ””โ”€โ”€ scripts/ # Training & evaluation code
109
- โ”œโ”€โ”€ dpo.py, orpo_native.py, sft.py
110
- โ”œโ”€โ”€ lora.py, merge_checkpoints.py
111
- โ”œโ”€โ”€ evafrill_eval.py
112
- โ””โ”€โ”€ generate_repetition_preference.py
113
  ```
114
 
115
- ## Usage
116
 
117
- ```python
118
- # This is a custom architecture โ€” use the project's native loading code
119
- # Clone: https://github.com/pathcosmos/EVAFRILL-Mo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
 
121
  import torch
122
  from model.transformer import LLM
123
  from tokenizers import Tokenizer
124
 
125
- model = LLM.from_pretrained("checkpoints/3b_dpo/checkpoint-slerp")
126
- model = model.to(device="cuda:0", dtype=torch.bfloat16)
 
 
 
 
 
127
  model.eval()
128
 
129
  tok = Tokenizer.from_file("tokenizer/korean_sp/tokenizer.json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  ```
131
 
132
- ## Limitations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
- - **3B scale**: Factual accuracy and complex reasoning are limited
135
- - **GGUF/Ollama**: Not possible due to custom hybrid Mamba-2 architecture
136
- - **vLLM**: Theoretically possible but requires custom weight key mapping
137
- - **Greedy repetition**: ~74.5% without rep_penalty (use rep_penalty=1.2)
 
138
 
139
- ## Links
140
 
141
  - **GitHub**: [pathcosmos/EVAFRILL-Mo](https://github.com/pathcosmos/EVAFRILL-Mo)
142
- - **Paper reference**: [Nemotron-H](https://arxiv.org/abs/2504.03624)
143
 
144
- ## License
145
 
146
- MIT
 
3
  - ko
4
  - en
5
  license: mit
6
+ library_name: pytorch
7
+ pipeline_tag: text-generation
8
  tags:
9
  - mamba2
10
  - hybrid
 
14
  - dpo
15
  - slerp
16
  - orpo
17
+ - nemotron-h
18
+ datasets:
19
+ - heegyu/orca-math-korean-preference-cleaned
20
+ - nayohan/preference-collection-ko-full
21
+ - kuotient/orca-math-word-problems-193k-korean
22
+ - FreedomIntelligence/alpaca-gpt4-korean
23
+ - heegyu/orca_ko
24
+ - HAERAE-HUB/KOFFQA-GuardInstruct-v1
25
+ model-index:
26
+ - name: EVAFRILL-Mo-3B
27
+ results:
28
+ - task:
29
+ type: text-generation
30
+ name: Text Generation
31
+ dataset:
32
+ type: hellaswag
33
+ name: HellaSwag (0-shot, limit=500)
34
+ metrics:
35
+ - name: Accuracy
36
+ type: accuracy
37
+ value: 34.6
38
+ - task:
39
+ type: text-generation
40
+ dataset:
41
+ type: arc_easy
42
+ name: ARC-Easy (0-shot, limit=500)
43
+ metrics:
44
+ - name: Accuracy
45
+ type: accuracy
46
+ value: 32.0
47
+ - task:
48
+ type: text-generation
49
+ dataset:
50
+ type: belebele
51
+ name: Belebele Korean (0-shot, limit=500)
52
+ metrics:
53
+ - name: Accuracy
54
+ type: accuracy
55
+ value: 23.6
56
+ - task:
57
+ type: text-generation
58
+ dataset:
59
+ type: mmlu
60
+ name: Global MMLU Korean (0-shot, limit=500)
61
+ metrics:
62
+ - name: Accuracy
63
+ type: accuracy
64
+ value: 23.7
65
  ---
66
 
67
+ > [ํ•œ๊ตญ์–ด](#ํ•œ๊ตญ์–ด) | [English](#english)
68
 
69
+ ---
70
 
71
+ # ํ•œ๊ตญ์–ด
72
 
73
+ ## EVAFRILL-Mo 3B โ€” ํ•˜์ด๋ธŒ๋ฆฌ๋“œ Mamba-2 + Transformer
74
 
75
+ ### ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ
76
 
77
+ EVAFRILL-Mo 3B๋Š” NVIDIA [Nemotron-H](https://arxiv.org/abs/2504.03624) ์•„ํ‚คํ…์ฒ˜์—์„œ ์˜๊ฐ์„ ๋ฐ›์•„ **๋ฐ‘๋ฐ”๋‹ฅ๋ถ€ํ„ฐ ์ง์ ‘ ๊ตฌํ˜„ํ•œ** 30์–ต ํŒŒ๋ผ๋ฏธํ„ฐ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์–ธ์–ด ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
78
+
79
+ - 7ร— NVIDIA B200 GPU๋กœ 55B ํ† ํฐ ์‚ฌ์ „ํ•™์Šต (์•ฝ 60์‹œ๊ฐ„)
80
+ - ํ•œ๊ตญ์–ดยท์˜์–ดยท์ฝ”๋“œยท์ˆ˜ํ•™ ํ˜ผํ•ฉ ๋ฐ์ดํ„ฐ์…‹ ์‚ฌ์šฉ
81
+ - SFT โ†’ DPO โ†’ SLERP ์ „์ฒด ํŒŒ์ดํ”„๋ผ์ธ์„ ๋‹จ์ผ ํ”„๋กœ์ ํŠธ์—์„œ ์ง์ ‘ ๊ตฌํ˜„
82
+ - ์™ธ๋ถ€ ํ”„๋ ˆ์ž„์›Œํฌ(Transformers Trainer, TRL) ์—†์ด PyTorch ๋„ค์ดํ‹ฐ๋ธŒ๋กœ ๊ตฌํ˜„
 
 
 
83
 
84
+ ### ์•„ํ‚คํ…์ฒ˜
85
+
86
+ ```
87
+ Type: Hybrid Mamba-2 + Transformer
88
+ Parameters: 2.94B (2,975,397,632)
89
+ Layers: 26 (24ร— Mamba-2 SSM + 2ร— Attention GQA)
90
+ d_model: 3,072
91
+ Vocabulary: 64,000 (custom SentencePiece)
92
+ Max seq length: 4,096
93
+ ```
94
+
95
+ Mamba-2 SSM ๋ธ”๋ก์ด ์žฅ๊ฑฐ๋ฆฌ ์˜์กด์„ฑ์„ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ , 2๊ฐœ์˜ GQA Attention ๋ธ”๋ก์ด ์ „์—ญ ์ปจํ…์ŠคํŠธ๋ฅผ ๋ณด์™„ํ•ฉ๋‹ˆ๋‹ค.
96
+ ํ‘œ์ค€ Transformer ๋Œ€๋น„ ์ถ”๋ก  ์‹œ KV ์บ์‹œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํฌ๊ฒŒ ์ ˆ๊ฐํ•ฉ๋‹ˆ๋‹ค.
97
+
98
+ ### ๋ชจ๋ธ ๋ฒ„์ „
99
+
100
+ ์ด ์ €์žฅ์†Œ์—๋Š” ํ•™์Šต ํŒŒ์ดํ”„๋ผ์ธ ๊ฐ ๋‹จ๊ณ„์˜ ์ฒดํฌํฌ์ธํŠธ **7์ข…**์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.
101
+
102
+ | ๋ฒ„์ „ | ๋””๋ ‰ํ† ๋ฆฌ | ํฌ๊ธฐ | ์„ค๋ช… | ๊ถŒ์žฅ |
103
+ |------|----------|------|------|:----:|
104
+ | **SLERP** | `slerp/` | 6.3 GB | SFT + DPO R2 ๊ตฌ๋ฉด ์„ ํ˜• ๋ณด๊ฐ„ (ฮฑ=0.5) | โญ |
105
+ | Pretrain | `pretrain/` | 12.6 GB | ๊ธฐ๋ฐ˜ ๋ชจ๋ธ (319K ์Šคํ…, 55B ํ† ํฐ) | |
106
+ | SFT v2 | `sft-v2/` | 6.3 GB | ๋ช…๋ น์–ด ํŒŒ์ธํŠœ๋‹ (65K ์Šคํ…) | |
107
+ | DPO R1 | `dpo-r1/` | 6.3 GB | ์„ ํ˜ธ๋„ ์ •๋ ฌ 1๋ผ์šด๋“œ (3K ์Šคํ…) | |
108
+ | DPO R2 | `dpo-r2/` | 6.3 GB | ๋ณด์ˆ˜์  ํŒŒ์ธํŠœ๋‹ 2๋ผ์šด๋“œ (2K ์Šคํ…) | |
109
+ | ORPO | `orpo/` | 6.3 GB | SFT+์ •๋ ฌ ๋™์‹œ ํ•™์Šต ์‹คํ—˜ (10K ์Šคํ…) | |
110
+ | DPO R3 | `dpo-r3/` | 6.3 GB | ๋ฐ˜๋ณต ์–ต์ œ ํŠนํ™” ์‹คํ—˜ (1K ์Šคํ…) | |
111
+
112
+ ### ํ•™์Šต ํŒŒ์ดํ”„๋ผ์ธ
113
 
114
  ```
115
  Pretrain (55B tokens, 7ร—B200, 60h)
116
+ ๏ฟฝ๏ฟฝโ”€โ–บ SFT v2 (65K steps, H100 MIG, 5์ผ)
117
+ โ”œโ”€โ–บ DPO R1 (3K steps) โ”€โ–บ DPO R2 (2K steps)
118
+ โ”‚ โ””โ”€โ–บ SLERP Merge (ฮฑ=0.5) โญ ์ตœ์ข… ๊ถŒ์žฅ
119
+ โ””โ”€โ–บ ORPO (10K steps, ์‹คํ—˜)
120
+ โ””โ”€โ–บ DPO R3 (1K steps, ๋ฐ˜๋ณต ํŠนํ™” ์‹คํ—˜)
 
 
 
 
 
 
 
121
  ```
122
 
123
+ ๊ฐ ํ™”์‚ดํ‘œ๋Š” ๋…๋ฆฝ๋œ ์ฒดํฌํฌ์ธํŠธ๋กœ ์ €์žฅ๋˜์–ด, ์ž„์˜์˜ ๋‹จ๊ณ„๋ถ€ํ„ฐ ์žฌํ˜„ยท๋น„๊ต๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
124
+
125
+ ### ๋ฒค์น˜๋งˆํฌ ๊ฒฐ๊ณผ
126
+
127
+ **ํ‰๊ฐ€ ๋Œ€์ƒ: SLERP ๋ชจ๋ธ** (0-shot, limit=500)
128
+
129
+ | ๋ฒค์น˜๋งˆํฌ | ์ •ํ™•๋„ |
130
+ |----------|:------:|
131
+ | HellaSwag | 34.6% |
132
+ | ARC-Easy | 32.0% |
133
+ | Belebele ํ•œ๊ตญ์–ด | 23.6% |
134
+ | Global MMLU ํ•œ๊ตญ์–ด | 23.7% |
135
+
136
+ **๋ฐ˜๋ณต ์ƒ์„ฑ ์–ต์ œ** (greedy decoding ๊ธฐ์ค€)
137
+
138
+ | ์„ค์ • | 3-gram ๋ฐ˜๋ณต๋ฅ  |
139
+ |------|:-------------:|
140
+ | rep_penalty ์—†์Œ | 74.5% |
141
+ | rep_penalty=1.2 | **5.5%** |
142
+
143
+ ๊ถŒ์žฅ ์ถ”๋ก  ํŒŒ๋ผ๋ฏธํ„ฐ: `temperature=0.7, repetition_penalty=1.2`
144
+
145
+ ### DPO vs ORPO ๋น„๊ต
146
+
147
+ | ์ง€ํ‘œ | SLERP (SFTโ†’DPO) | ORPO | ์šฐ์„ธ |
148
+ |------|:---------------:|:----:|:----:|
149
+ | Greedy ๋ฐ˜๋ณต๋ฅ  | 74.5% | 87.1% | SLERP |
150
+ | ๋Œ€ํ™” ํ’ˆ์งˆ | ์ž์—ฐ์Šค๋Ÿฌ์›€ | ๋ถ€์ž์—ฐ์Šค๋Ÿฌ์›€ | SLERP |
151
+ | HellaSwag | **39.0%** | 35.0% | SLERP |
152
+ | ํ•™์Šต ์‹œ๊ฐ„ | 5์ผ+8์‹œ๊ฐ„ | **12.8์‹œ๊ฐ„** | ORPO |
153
+
154
+ ORPO์˜ ์•ฝ์ : SFT 65K ์Šคํ… ๋Œ€๋น„ 10K ์Šคํ…๋งŒ ํ•™์Šต๋˜์–ด ๊ธฐ๋ฐ˜ ๋ช…๋ น์–ด ์ดํ•ด๊ฐ€ ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.
155
+
156
+ ### ์‚ฌ์šฉ๋ฒ•
157
+
158
+ ```python
159
+ import torch
160
+ from model.transformer import LLM
161
+ from tokenizers import Tokenizer
162
+
163
+ # ์ปค์Šคํ…€ ์•„ํ‚คํ…์ฒ˜์ด๋ฏ€๋กœ ์ €์žฅ์†Œ ํด๋ก  ํ›„ ์‚ฌ์šฉ
164
+ # git clone https://github.com/pathcosmos/EVAFRILL-Mo
165
+
166
+ device = "cuda" if torch.cuda.is_available() else "cpu"
167
+
168
+ model = LLM.from_pretrained("hf_export/slerp")
169
+ model = model.to(device=device, dtype=torch.bfloat16)
170
+ model.eval()
171
+
172
+ tok = Tokenizer.from_file("tokenizer/korean_sp/tokenizer.json")
173
+
174
+ prompt = "์ธ๊ณต์ง€๋Šฅ์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?"
175
+ ids = tok.encode(prompt).ids
176
+ input_ids = torch.tensor([ids], device=device)
177
+
178
+ with torch.no_grad():
179
+ output = model.generate(
180
+ input_ids,
181
+ max_new_tokens=256,
182
+ temperature=0.7,
183
+ repetition_penalty=1.2,
184
+ )
185
+
186
+ print(tok.decode(output[0].tolist()))
187
+ ```
188
+
189
+ ### ์žฌํ˜„ ์ž๋ฃŒ
190
+
191
+ | ๊ฒฝ๋กœ | ๋‚ด์šฉ |
192
+ |------|------|
193
+ | `data/combined_preference.jsonl` | ์„ ํ˜ธ๋„ ํ•™์Šต ๋ฐ์ดํ„ฐ (684K ์Œ, 2.6 GB) |
194
+ | `data/repetition_preference.jsonl` | ๋ฐ˜๋ณต ์–ต์ œ ์„ ํ˜ธ๋„ ๋ฐ์ดํ„ฐ (105 ์Œ, ์ž๋™ ์ƒ์„ฑ) |
195
+ | `configs/korean_3b_sft_1gpu.yaml` | SFT H100 MIG ์„ค์ • |
196
+ | `configs/dpo_3b_1gpu.yaml` | DPO ํ•™์Šต ์„ค์ • |
197
+ | `configs/orpo_3b_1gpu.yaml` | ORPO ํ•™์Šต ์„ค์ • |
198
+ | `scripts/dpo.py` | DPO ํ•™์Šต ์ฝ”๋“œ |
199
+ | `scripts/orpo_native.py` | ORPO ํ•™์Šต ์ฝ”๋“œ |
200
+ | `scripts/sft.py` | SFT ํ•™์Šต ์ฝ”๋“œ |
201
+ | `scripts/evafrill_eval.py` | ๋ฒค์น˜๋งˆํฌ ํ‰๊ฐ€ ์ฝ”๋“œ |
202
+ | `scripts/merge_checkpoints.py` | SLERP ์ฒดํฌํฌ์ธํŠธ ๋ณ‘ํ•ฉ |
203
+
204
+ ### ์ œํ•œ์‚ฌํ•ญ
205
+
206
+ - **3B ๊ทœ๋ชจ ํ•œ๊ณ„**: ์‚ฌ์‹ค ์ •ํ™•๋„ยท๋ณต์žกํ•œ ์ถ”๋ก ์— ํ•œ๊ณ„๊ฐ€ ์žˆ์œผ๋ฉฐ, ๋Œ€ํ˜• ๋ชจ๋ธ ๋Œ€๋น„ ์„ฑ๋Šฅ์ด ๋‚ฎ์Šต๋‹ˆ๋‹ค.
207
+ - **GGUF/Ollama ๋ถˆ๊ฐ€**: ์ปค์Šคํ…€ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ Mamba-2 ์•„ํ‚คํ…์ฒ˜๋กœ ํ‘œ์ค€ ๋ณ€ํ™˜ ํˆด์„ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
208
+ - **vLLM ์ œํ•œ์ **: ์ด๋ก ์ƒ ๊ฐ€๋Šฅํ•˜๋‚˜ ์ปค์Šคํ…€ weight key ๋งคํ•‘์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
209
+ - **๋ฐ˜๋ณต ์ƒ์„ฑ**: greedy decoding ์‹œ ๋ฐ˜๋ณต๋ฅ ์ด ๋†’์œผ๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ `repetition_penalty=1.2` ์ด์ƒ์„ ์„ค์ •ํ•˜์„ธ์š”.
210
+ - **์–ธ์–ด ํŽธ์ค‘**: ํ•œ๊ตญ์–ดยท์˜์–ด ์™ธ ์–ธ์–ด๋Š” ์„ฑ๋Šฅ์ด ๋ณด์žฅ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
211
+
212
+ ### ๋งํฌ
213
+
214
+ - **GitHub**: [pathcosmos/EVAFRILL-Mo](https://github.com/pathcosmos/EVAFRILL-Mo)
215
+ - **์ฐธ์กฐ ๋…ผ๋ฌธ**: [Nemotron-H: A Family of Accurate and Efficient Hybrid Mamba-Transformer Models](https://arxiv.org/abs/2504.03624)
216
+
217
+ ### ๋ผ์ด์„ ์Šค
218
+
219
+ MIT License โ€” ์ƒ์—…์  ์ด์šฉยท์ˆ˜์ •ยท์žฌ๋ฐฐํฌ ๋ชจ๋‘ ์ž์œ ๋กญ์Šต๋‹ˆ๋‹ค.
220
+
221
+ ---
222
+
223
+ # English
224
+
225
+ ## EVAFRILL-Mo 3B โ€” Hybrid Mamba-2 + Transformer
226
+
227
+ ### Introduction
228
+
229
+ EVAFRILL-Mo 3B is a 3-billion-parameter hybrid language model built **entirely from scratch**, inspired by NVIDIA's [Nemotron-H](https://arxiv.org/abs/2504.03624) architecture.
230
+
231
+ - Pretrained on 55B tokens using 7ร— NVIDIA B200 GPUs (~60 hours)
232
+ - Mixed Korean, English, code, and math datasets
233
+ - Full SFT โ†’ DPO โ†’ SLERP pipeline implemented in pure PyTorch โ€” no Transformers Trainer or TRL
234
+ - Designed as a Korean-first model with strong multilingual capability
235
+
236
+ ### Architecture
237
 
238
  ```
239
  Type: Hybrid Mamba-2 + Transformer
 
244
  Max seq length: 4,096
245
  ```
246
 
247
+ Mamba-2 SSM blocks handle long-range dependencies efficiently while two GQA Attention blocks provide global context.
248
+ Compared to standard Transformers, this architecture significantly reduces KV cache memory during inference.
 
 
 
 
 
 
 
249
 
250
+ ### Model Variants
251
 
252
+ This repository contains **7 checkpoints** representing each stage of the training pipeline.
 
 
 
 
 
 
 
253
 
254
+ | Variant | Directory | Size | Description | Recommended |
255
+ |---------|-----------|------|-------------|:-----------:|
256
+ | **SLERP** | `slerp/` | 6.3 GB | Spherical interpolation of SFT + DPO R2 (ฮฑ=0.5) | โญ |
257
+ | Pretrain | `pretrain/` | 12.6 GB | Base model (319K steps, 55B tokens) | |
258
+ | SFT v2 | `sft-v2/` | 6.3 GB | Instruction-tuned (65K steps) | |
259
+ | DPO R1 | `dpo-r1/` | 6.3 GB | Preference-aligned Round 1 (3K steps) | |
260
+ | DPO R2 | `dpo-r2/` | 6.3 GB | Conservative fine-tuning Round 2 (2K steps) | |
261
+ | ORPO | `orpo/` | 6.3 GB | Simultaneous SFT+alignment experiment (10K steps) | |
262
+ | DPO R3 | `dpo-r3/` | 6.3 GB | Repetition-targeted experiment (1K steps) | |
263
 
264
+ ### Training Pipeline
265
 
266
  ```
267
+ Pretrain (55B tokens, 7ร—B200, 60h)
268
+ โ””โ”€โ–บ SFT v2 (65K steps, H100 MIG, 5 days)
269
+ โ”œโ”€โ–บ DPO R1 (3K steps) โ”€โ–บ DPO R2 (2K steps)
270
+ โ”‚ โ””โ”€โ–บ SLERP Merge (ฮฑ=0.5) โญ Final Recommended
271
+ โ””โ”€โ–บ ORPO (10K steps, experimental)
272
+ โ””โ”€โ–บ DPO R3 (1K steps, repetition experiment)
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  ```
274
 
275
+ Every arrow corresponds to a separate saved checkpoint, enabling reproduction and comparison from any stage.
276
 
277
+ ### Benchmark Results
278
+
279
+ **Evaluated on: SLERP model** (0-shot, limit=500)
280
+
281
+ | Benchmark | Accuracy |
282
+ |-----------|:--------:|
283
+ | HellaSwag | 34.6% |
284
+ | ARC-Easy | 32.0% |
285
+ | Belebele Korean | 23.6% |
286
+ | Global MMLU Korean | 23.7% |
287
+
288
+ **Repetition suppression** (greedy decoding)
289
+
290
+ | Setting | 3-gram repetition rate |
291
+ |---------|:----------------------:|
292
+ | No rep_penalty | 74.5% |
293
+ | rep_penalty=1.2 | **5.5%** |
294
+
295
+ Recommended inference parameters: `temperature=0.7, repetition_penalty=1.2`
296
+
297
+ ### DPO vs ORPO Comparison
298
+
299
+ | Metric | SLERP (SFTโ†’DPO) | ORPO | Winner |
300
+ |--------|:---------------:|:----:|:------:|
301
+ | Greedy repetition | 74.5% | 87.1% | SLERP |
302
+ | Chat quality | Fluent | Broken | SLERP |
303
+ | HellaSwag | **39.0%** | 35.0% | SLERP |
304
+ | Training time | 5d+8h | **12.8h** | ORPO |
305
+
306
+ ORPO's weakness: only 10K steps of training vs SFT's 65K โ€” insufficient base instruction-following before alignment kicks in.
307
+
308
+ ### Usage
309
 
310
+ ```python
311
  import torch
312
  from model.transformer import LLM
313
  from tokenizers import Tokenizer
314
 
315
+ # Requires cloning the repository (custom architecture โ€” not loadable via AutoModel)
316
+ # git clone https://github.com/pathcosmos/EVAFRILL-Mo
317
+
318
+ device = "cuda" if torch.cuda.is_available() else "cpu"
319
+
320
+ model = LLM.from_pretrained("hf_export/slerp")
321
+ model = model.to(device=device, dtype=torch.bfloat16)
322
  model.eval()
323
 
324
  tok = Tokenizer.from_file("tokenizer/korean_sp/tokenizer.json")
325
+
326
+ prompt = "What is artificial intelligence?"
327
+ ids = tok.encode(prompt).ids
328
+ input_ids = torch.tensor([ids], device=device)
329
+
330
+ with torch.no_grad():
331
+ output = model.generate(
332
+ input_ids,
333
+ max_new_tokens=256,
334
+ temperature=0.7,
335
+ repetition_penalty=1.2,
336
+ )
337
+
338
+ print(tok.decode(output[0].tolist()))
339
  ```
340
 
341
+ ### Reproducibility
342
+
343
+ | Path | Contents |
344
+ |------|----------|
345
+ | `data/combined_preference.jsonl` | Preference training data (684K pairs, 2.6 GB) |
346
+ | `data/repetition_preference.jsonl` | Repetition-suppression preference data (105 pairs, auto-generated) |
347
+ | `configs/korean_3b_sft_1gpu.yaml` | SFT config for H100 MIG |
348
+ | `configs/dpo_3b_1gpu.yaml` | DPO training config |
349
+ | `configs/orpo_3b_1gpu.yaml` | ORPO training config |
350
+ | `scripts/dpo.py` | DPO training code |
351
+ | `scripts/orpo_native.py` | ORPO training code |
352
+ | `scripts/sft.py` | SFT training code |
353
+ | `scripts/evafrill_eval.py` | Benchmark evaluation code |
354
+ | `scripts/merge_checkpoints.py` | SLERP checkpoint merging |
355
+
356
+ ### Limitations
357
 
358
+ - **3B scale**: Factual accuracy and complex multi-step reasoning are limited compared to larger models.
359
+ - **GGUF/Ollama**: Not supported โ€” custom hybrid Mamba-2 architecture cannot be converted with standard tools.
360
+ - **vLLM**: Theoretically possible but requires custom weight key mapping.
361
+ - **Greedy repetition**: ~74.5% 3-gram repetition rate without `repetition_penalty` โ€” always use `repetition_penalty >= 1.2`.
362
+ - **Language coverage**: Performance is not guaranteed for languages other than Korean and English.
363
 
364
+ ### Links
365
 
366
  - **GitHub**: [pathcosmos/EVAFRILL-Mo](https://github.com/pathcosmos/EVAFRILL-Mo)
367
+ - **Reference paper**: [Nemotron-H: A Family of Accurate and Efficient Hybrid Mamba-Transformer Models](https://arxiv.org/abs/2504.03624)
368
 
369
+ ### License
370
 
371
+ MIT License โ€” free to use, modify, and distribute commercially.