victor70 commited on
Commit
963ad17
·
verified ·
1 Parent(s): 5ce70f9

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +53 -134
  2. pytorch_model.pt +3 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- license: mit
3
  language:
4
  - ko
5
  tags:
@@ -9,164 +9,83 @@ tags:
9
  - attention
10
  - griffin
11
  - language-model
12
- datasets:
13
- - wikipedia
14
- pipeline_tag: text-generation
15
  ---
16
 
17
- # HybriKo-117M
18
 
19
- Griffin 아키텍처에서 영감을 받은 한국어 하이브리드 언어 모델입니다.
20
 
21
- ## 모델 설명
22
 
23
- HybriKo는 Google의 Griffin 아키텍처에서 영감을 받아, RNN(Real-Gated Linear Recurrent Unit)과 Attention 메커니즘을 2:1 비율로 결합한 하이브리드 언어 모델입니다.
 
 
 
 
24
 
25
- ### 아키텍처
26
- - **타입**: Hybrid RNN-Attention (2:1 비율)
27
- - **파라미터**: 117.8M
28
- - **Hidden Dimension**: 768
29
- - **레이어**: 12개 (8 RNN + 4 Attention)
30
- - **Attention Heads**: 12개 (GQA, 3 KV heads)
31
- - **Vocabulary**: 32,000 (SentencePiece Unigram)
32
- - **최대 시퀀스 길이**: 512
33
 
34
- ### 레이어 패턴
35
- ```
36
- Layer 1-2: GriffinBlock (RGLRU 기반 RNN)
37
- Layer 3: AttentionBlock (RoPE 적용 Multi-Head Attention)
38
- Layer 4-5: GriffinBlock
39
- Layer 6: AttentionBlock
40
- ... (패턴 반복)
41
- ```
42
-
43
- ### 아키텍처 다이어그램
44
-
45
- ![HybriKo Architecture](Architecture.png)
46
-
47
- ## 학습
48
 
49
- - **데이터셋**: 한국어 위키피디아 (~509K 문서)
50
- - **학습 스텝**: 1,000
51
- - **배치 사이즈**: 16
52
- - **Learning Rate**: 3e-4
53
- - **하드웨어**: A100
54
 
55
- ### 학습 결과
56
- | 지표 | 값 |
57
- |------|-----|
58
- | 초기 Loss | 10.27 |
59
- | 최종 Loss | 3.65 |
60
- | 평균 Loss | 3.97 |
 
 
 
61
 
62
- ## 빠른 시작 (Google Colab)
 
 
 
 
63
 
64
- 아래 코드를 복사해서 바로 실행할 수 있습니다:
65
 
66
  ```python
67
- # 의존성 설치
68
- !pip install transformers sentencepiece -q
69
-
70
  import torch
71
- import sentencepiece as spm
72
- from huggingface_hub import hf_hub_download, list_repo_files
73
-
74
- # GPU 자동 감지
75
- device = "cuda" if torch.cuda.is_available() else "cpu"
76
- print(f"🖥️ 사용 디바이스: {device}")
77
-
78
- # 모델 코드 다운로드
79
- config_path = hf_hub_download("Yaongi/HybriKo-117M", "configuration_hybridko.py")
80
- model_path = hf_hub_download("Yaongi/HybriKo-117M", "modeling_hybridko.py")
81
 
82
- import sys, os
83
- sys.path.insert(0, os.path.dirname(config_path))
84
-
85
- from configuration_hybridko import HybriKoConfig
86
- from modeling_hybridko import HybriKoModel
87
-
88
- # 1. 모델 생성
89
- config = HybriKoConfig()
90
  model = HybriKoModel(config)
 
91
 
92
- # 2. 최신 체크포인트 자동 탐지 및 로드
93
- files = list_repo_files("Yaongi/HybriKo-117M")
94
- checkpoints = sorted([f for f in files if f.startswith("checkpoint_step_") and f.endswith(".pt")])
95
- latest_checkpoint = checkpoints[-1] if checkpoints else "checkpoint_step_1000.pt"
96
- print(f"📦 체크포인트 로드: {latest_checkpoint}")
97
-
98
- checkpoint_path = hf_hub_download("Yaongi/HybriKo-117M", latest_checkpoint)
99
- checkpoint = torch.load(checkpoint_path, map_location=device)
100
- model.load_state_dict(checkpoint["model_state_dict"])
101
- model = model.to(device)
102
- model.eval()
103
-
104
- # 3. 토크나이저 로드
105
- tokenizer_path = hf_hub_download("Yaongi/HybriKo-117M", "HybriKo_tok.model")
106
- sp = spm.SentencePieceProcessor()
107
- sp.Load(tokenizer_path)
108
-
109
- # 4. 텍스트 생성
110
- prompt = "한국의 수도는"
111
- input_ids = torch.tensor([[2] + sp.EncodeAsIds(prompt)]).to(device)
112
- output = model.generate(input_ids, max_new_tokens=50, temperature=0.8)
113
- print(sp.DecodeIds(output[0].tolist()))
114
- ```
115
 
116
- ## 여러 프롬프트 테스트
117
-
118
- ```python
119
- prompts = ["한국어", "대한민국", "서울", "인공지능", "오늘 날씨가"]
120
-
121
- for prompt in prompts:
122
- input_ids = torch.tensor([[2] + sp.EncodeAsIds(prompt)]).to(device) # 👈 .to(device) 추가
123
- output = model.generate(input_ids, max_new_tokens=30, temperature=0.8, top_k=50)
124
- generated = sp.DecodeIds(output[0].tolist())
125
- print(f"📝 {prompt}")
126
- print(f" → {generated}")
127
- print("-" * 50)
128
  ```
129
 
130
- ## 생성 파라미터
131
-
132
- | 파라미터 | 설명 | 권장 값 |
133
- |----------|------|---------|
134
- | `temperature` | 랜덤성 (낮을수록 결정적) | 0.7 - 1.0 |
135
- | `top_k` | 상위 K개 토큰만 샘플링 | 50 |
136
- | `top_p` | Nucleus 샘플링 임계값 | 0.9 |
137
- | `max_new_tokens` | 생성할 토큰 수 | 30 - 100 |
138
-
139
- ## 제한 사항
140
-
141
- ⚠️ **이 모델은 1,000 스텝만 학습된 개념 증명(Proof-of-Concept) 모델입니다.**
142
-
143
- 생성된 텍스트는 초기 학습 패턴(숫자/연도 많이 출력)을 보입니다. 더 나은 품질을 위해:
144
- - 10,000+ 스텝 학습
145
- - 1B+ 파라미터로 스케일업
146
- - 특정 태스크에 파인튜닝
147
-
148
- ## 레포지토리 파일
149
 
150
- | 파일 | 설명 |
151
- |------|------|
152
- | `checkpoint_step_*.pt` | 모델 가중치 |
153
- | `HybriKo_tok.model` | SentencePiece 토크나이저 |
154
- | `HybriKo_tok.vocab` | 토크나이저 어휘 |
155
- | `config.json` | HuggingFace 설정 |
156
- | `configuration_hybridko.py` | Config 클래스 |
157
- | `modeling_hybridko.py` | 모델 아키텍처 |
158
 
159
- ## 인용
160
 
161
  ```bibtex
162
- @misc{hybridko2026,
163
- title={HybriKo: 한국어 하이브리드 언어 모델},
164
- author={Yaongi Team},
165
- year={2026},
166
- url={https://huggingface.co/Yaongi/HybriKo-117M}
167
  }
168
  ```
169
 
170
- ## 라이선스
171
 
172
- MIT License
 
1
  ---
2
+ license: apache-2.0
3
  language:
4
  - ko
5
  tags:
 
9
  - attention
10
  - griffin
11
  - language-model
 
 
 
12
  ---
13
 
14
+ # HybriKo: Korean Hybrid Language Model
15
 
16
+ A Griffin-inspired hybrid architecture combining RNN and Attention mechanisms for Korean language modeling.
17
 
18
+ ## Model Details
19
 
20
+ - **Parameters**: 117.8M
21
+ - **Architecture**: 2:1 RNN-to-Attention ratio (Griffin-inspired)
22
+ - **Context Length**: 1024 tokens
23
+ - **Vocab Size**: 32,000 (SentencePiece)
24
+ - **Training Data**: Korean Wikipedia
25
 
26
+ ## Training Results (Exp3)
 
 
 
 
 
 
 
27
 
28
+ | Phase | Steps | Loss | PPL |
29
+ |-------|-------|------|-----|
30
+ | Phase 1 | 0-10K | 1.80 | ~6.0 |
31
+ | Phase 2 | 10K-30K | 1.60 | ~4.95 |
 
 
 
 
 
 
 
 
 
 
32
 
33
+ ## Architecture
 
 
 
 
34
 
35
+ ```
36
+ HybriKo (117.8M params)
37
+ ├── Embedding (32000 → 768)
38
+ ├── Layers (12x)
39
+ │ ├── Layer 1,2: GriffinBlock (RNN)
40
+ │ ├── Layer 3: AttentionBlock
41
+ │ └── (pattern repeats)
42
+ └── LM Head (weight-tied)
43
+ ```
44
 
45
+ Key features:
46
+ - **RGLRU**: Real-Gated Linear Recurrent Unit
47
+ - **GQA**: Grouped Query Attention (1:4 KV reduction)
48
+ - **Flash Attention 2**: Optimized attention computation
49
+ - **GeGLU**: Gated activation in FFN
50
 
51
+ ## Usage
52
 
53
  ```python
 
 
 
54
  import torch
55
+ from hybridko.model import HybriKoModel, HybriKoConfig
56
+ from hybridko.data import load_tokenizer
 
 
 
 
 
 
 
 
57
 
58
+ # Load model
59
+ config = HybriKoConfig.from_yaml("config.yaml")
 
 
 
 
 
 
60
  model = HybriKoModel(config)
61
+ model.load_state_dict(torch.load("pytorch_model.pt"))
62
 
63
+ # Load tokenizer
64
+ tokenizer = load_tokenizer("HybriKo_tok.model")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ # Generate
67
+ from hybridko.inference import generate_with_cache
68
+ output = generate_with_cache(model, tokenizer, "한국의 수도는", max_tokens=50)
69
+ print(output)
 
 
 
 
 
 
 
 
70
  ```
71
 
72
+ ## Files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ - `pytorch_model.pt`: Model weights (450MB)
75
+ - `config.yaml`: Model configuration
76
+ - `HybriKo_tok.model`: SentencePiece tokenizer
77
+ - `HybriKo_tok.vocab`: Tokenizer vocabulary
 
 
 
 
78
 
79
+ ## Citation
80
 
81
  ```bibtex
82
+ @misc{hybridko2024,
83
+ title={HybriKo: Korean Hybrid Language Model},
84
+ year={2024},
85
+ url={https://huggingface.co/gyunggyung/HybriKo-117M}
 
86
  }
87
  ```
88
 
89
+ ## License
90
 
91
+ Apache 2.0
pytorch_model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e02a596f9dc1a993cd1aa0a65022a5d4ec95409620be3c43f2829432e93b5077
3
+ size 471349067