Gemma3 MoE
This repository provides a Mixture-of-Experts (MoE) variant of Gemma-3, where the standard FFN layers are replaced with a top-k gated MoE architecture.
โ ๏ธ This model requires trust_remote_code=True because it uses a custom configuration and model implementation (gemma3_moe).
This model is intended for research and experimentation, with a focus on:
- Korean reasoning and reading comprehension
- Fact-checking and factual consistency judgment
- Multilingual instruction-following
- Analysis of MoE routing and expert specialization
Model Overview
- Base model: Gemma-3
- Architecture: Decoder-only Transformer with MoE FFN
- Experts per layer: Configurable (e.g. 8 experts)
- Routing: Top-k soft routing
- Auxiliary loss: Router load-balancing loss
- Framework: PyTorch
- Model format: safetensors
Architecture Details
- Each Transformer FFN block is replaced with an MoE layer
- A lightweight router maps hidden states to expert logits
- Top-k experts are selected per token
- Expert outputs are merged via weighted summation
- Router logits are retained for auxiliary balancing loss computation
This design enables implicit expert specialization across:
- Logical and step-by-step reasoning
- Factual QA and verification
- Creative and conversational responses
- Code-related patterns
Training Data
The model was fine-tuned using a streaming-based mixed SFT dataset, explicitly balanced across languages and task types.
Language Distribution
- Korean: ~55%
- English: ~35%
- Code: ~10%
Datasets were interleaved with fixed probabilities and shuffled using a streaming buffer.
English Instruction Data (35%)
- Open-Orca / OpenOrca
- Subset: ~50K samples
- General instruction-following
- Multi-step reasoning and explanation tasks
Korean Instruction Data (55%)
Korean data was diversified with a strong emphasis on reasoning accuracy and factual correctness.
| Category | Dataset | Purpose | Weight |
|---|---|---|---|
| Logic / Reasoning | kyujinpy/KOpen-platypus |
Step-by-step reasoning | 20% |
| QA | kikikara/ko_QA_dataset |
General QA | 20% |
| MRC | Custom iterable | Reading comprehension | 25% |
| Fact-checking | Custom iterable | Factual verification / hallucination reduction | 20% |
| Creative | beomi/KoAlpaca-v1.1a |
Conversational & creative tasks | 15% |
๐ Fact-checking data was intentionally up-weighted to strengthen factual grounding.
Code Instruction Data (10%)
- sahil2801 / CodeAlpaca-20k
- Subset: ~15K samples
- Code generation and explanation tasks
Data Processing
- Unified SFT formatting across all datasets
- Streaming mode to reduce memory usage
- Final shuffle buffer size: 10,000
- Fixed-probability interleaving to preserve domain balance
Training Strategy
This model was trained with parameter-groupโspecific optimization, explicitly separating shared parameters, expert FFNs, and router parameters.
Different learning rates and regularization settings were applied to encourage stable MoE specialization and balanced routing behavior.
Optimizer Parameter Groups
def get_moe_param_groups(model):
attention_params = []
expert_params = []
router_params = []
for name, param in model.named_parameters():
if not param.requires_grad:
continue
# Router parameters
if "mlp.router" in name:
router_params.append(param)
# Expert FFN parameters
elif "mlp.experts" in name:
expert_params.append(param)
# Attention, embeddings, layer norms, etc.
else:
attention_params.append(param)
return [
{"params": attention_params, "lr": 2e-6, "weight_decay": 0.0},
{"params": expert_params, "lr": 1e-5, "weight_decay": 0.1},
{"params": router_params, "lr": 2e-5, "weight_decay": 0.0},
]
Fact-check Test
User Prompt
๋ค์ ์์ฝ๋ฌธ์ด ์๋ฌธ์ ๋น์ถ์ด ์ฌ์ค์ธ์ง ํ๋จํ์์ค. ์ฌ์ค ์ฌ๋ถ์ ํ๋จ ๊ทผ๊ฑฐ๋ฅผ ํจ๊ป ์ ์ํ์์ค.
[์๋ฌธ] ์ฌํด๋ถํฐ ๊ฐ๋งน๋ณธ๋ถ ์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ด ์๊ฐ์์์ 30์ผ ์ด๋ด๋ก ๋จ์ถ๋ ์ ๋ง์ด๋ค. ์์ธ์๋ ์ฌํด 1์1์ผ๋ถํฐ ๊ฐ๋งน๋ณด๋ถ ์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ ๋ฌด๋ฅผ ๊ณต์ ๊ฑฐ๋์์ํ๋ก๋ถํฐ ์ด์๋ฐ์ ์์ธ, ์ธ์ฒ, ๊ฒฝ๊ธฐ ๋ฑ 3๊ฐ ์ง์์ฒด๊ฐ ์ฒ๋ฆฌํ๋ค๊ณ 16์ผ ๋ฐํ๋ค. ๊ฐ๋งน์ ๋ณด๊ณต๊ฐ์๋ ๊ฐ๋งน์ ์ฐฝ์ ํฌ๋ง์๊ฐ ๊ณ์ฝ์ ์์ ๊ฐ๋งน๋ณธ๋ถ์ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ ๋ฌธ์๋ก, ๊ณ์ฝ์ฒด๊ฒฐ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ ๋ฐ ํฐ ์ญํ ์ ํ๋ค. ๊ธฐ์กด์ ๊ฐ๋งน์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ด ๊ณต์ ์์์๋ง ๊ฐ๋ฅํด ๊ธธ๊ฒ๋ ์๊ฐ์์ ์์๋๋ค. ํ์ง๋ง ์ฌํด ์ง์์ฒด์์ ์ ๋ฌด ๋ถ๋ด์ผ๋ก ๋ฑ๋ก๊ธฐ๊ฐ์ด 30์ผ ์ด๋ด๋ก ๋จ์ถ๋๋ค. ์์ธ์๋ ๋ณธ์ฌ์ ํํฉ์ ํ์ ํ ์ ์๋ ์ฌ๋ฌด์ฌํญ, ํฌ์์์ต๋ฅ ๋ฑ์ด ํฌํจ๋ผ ์๋ ์๋ฃ์ด๋๋งํผ ์ข ๋ ๊ผผ๊ผผํ๊ฒ ์ฒด๊ณ์ ์ผ๋ก ์ฌ์ฌํ๊ณ ๋ฑ๋กํด ๊ฐ๋งน์ ์ฐฝ์ ํฌ๋ง์๋ค์ด ์ฐฝ์ ์ ๋ํ ํฉ๋ฆฌ์ ์ด๊ณ ์ ์คํ ๊ฒฐ์ ์ ํ ์ ์๋๋ก ๋๊ฒ ๋ค๊ณ ๋ฐํ๋ค. ์์ธ์์ฌ ๊ฐ๋งน๋ณธ๋ถ ์ค ์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ ์ํ๋ ์ ์ฒด๋ ์์ธ์ ๊ณต์ ๊ฒฝ์ ๋ด๋น๊ด ๊ฐ๋งน์ ๋ณดํ์ผ๋ก ์ฐํธ ๋๋ ๋ฐฉ๋ฌธ์ ์(์ค๊ตฌ ๋ฌด๊ต๋ก 21 ์์ธ์์ฒญ ๋ฌด๊ต๋ณ๊ด 8์ธต)ํ๊ฑฐ๋ ๊ณต์ ๊ฑฐ๋์์ํ ๊ฐ๋งน์ฌ์ ๊ฑฐ๋ ํํ์ด์ง๋ก ์ ์ฒญํ๋ฉด ๋๋ค. ํํธ ์๋ ์ค๋ 18์ผ ์คํ 2์ ์์ธ์์ฒญ ๋ค๋ชฉ์ ํ์์ ๊ฐ๋งน๋ณธ๋ถ ๋์ ์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ ๋ฌด ์ค๋ช ํ๋ฅผ ๊ฐ์ตํ๋ค.
[์์ฝ๋ฌธ] ์์ธ์๋ ์ฌํด 1์1์ผ๋ถํฐ ๊ฐ๋งน๋ณด๋ถ ์ ๋ณด๊ณต๊ฐ์ ๋ฑ๋ก์ ๋ฌด๋ฅผ ๊ณต์ ๊ฑฐ๋์์ํ๋ก๋ถํฐ ์ด์๋ฐ์ ์์ธ, ์ธ์ฒ, ๊ฒฝ๊ธฐ ๋ฑ 3๊ฐ ์ง์์ฒด๊ฐ ์ฒ๋ฆฌํ๋ค๊ณ 16์ผ ๋ฐํ์ผ๋ฉฐ, ๊ฐ๋งน์ ๋ณด๊ณต๊ฐ์๋ ๊ฐ๋งน์ ์ฐฝ์ ํฌ๋ง์๊ฐ ๊ณ์ฝ์ ์์ ๊ฐ๋งน๋ณธ๋ถ์ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ ๋ฌธ์๋ก, ๊ณ์ฝ์ฒด๊ฒฐ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ ๋ฐ ํฐ ์ญํ ์ ํ๋ค.
Test Result (Model Output)
ํ๋จ: ์ฌ์ค
์ค๋ฅ ์ ํ: ํ๊ธ ๋ง์ถค๋ฒ, ๋์ด์ฐ๊ธฐ ์ค๋ฅ
๊ทผ๊ฑฐ: ์์ฝ๋ฌธ์๋ '1์1์ผ๋ถํฐ'๋ผ๋ ํํ์ด ์์ผ๋ฉฐ, ์ด๋ '1์ 1์ผ๋ถํฐ'๋ก ์์ ๋์ด์ผ ํ๋ค. ํด๋น ์ค๋ฅ๋ [1] ํ๊ธ ๋ง์ถค๋ฒ, ๋์ด์ฐ๊ธฐ ์ค๋ฅ์ ํด๋นํ๋ค. ์ด๋ฌํ ์ค๋ฅ๋ ์๋ฏธ๋ ์ฌ์ค ๊ด๊ณ์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
QA Test
User Prompt
์๋ฅด์ ์์ถ ํ๋ก๊ทธ๋จ์ ๋ณต์ ๊ธฐ๋ฅ๊ณผ ๋ค์ค๋ณผ๋ฅจ ์์ถ ๊ธฐ๋ฅ์ ๋ฌด์์ธ๊ฐ์?
Test Result (Model Output)
์๋ฅด์ ์์ถ ํ๋ก๊ทธ๋จ์ ๋ณต์ ๊ธฐ๋ฅ๊ณผ ๋ค์ค๋ณผ๋ฅจ ์์ถ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. ๋ณต์ ๊ธฐ๋ฅ์ ์์๋ ์์ถ ํ์ผ์ ๋ณต์ํ์ฌ ์๋์ ์์ถ ํ์ผ๋ก ๋ณต์ํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ฉฐ, ๋ค์ค๋ณผ๋ฅจ ์์ถ ๊ธฐ๋ฅ์ ์์ถ ํ์ผ์ ์ฌ๋ฌ ๊ฐ์ ์์ ๋ณผ๋ฅจ์ผ๋ก ๋๋๊ณ , ๊ฐ ๋ณผ๋ฅจ์ ๋ํด ๋ค๋ฅธ ์์ถ ์๊ณ ๋ฆฌ์ฆ์ ์ ์ฉํ์ฌ ์์ถ๋ฅ ์ ๋์ผ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. ๊ฐ์ธ์ ์ผ๋ก, ์ด๋ฌํ ๊ธฐ๋ฅ๋ค์ ์์ถ ํ์ผ์ ์์ ๋ณต์๊ณผ ํจ์จ์ ์ธ ์์ถ์ ๊ฐ๋ฅํ๊ฒ ํด์ฃผ์ด ๋งค์ฐ ์ ์ฉํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
MRC Test
User Prompt
[๋ด์ค/๋ณธ๋ฌธ] ํ๊ตญ์ฒญ์๋ ๋จ์ฒดํ์ํ์ ์ฌ์ฑ๊ฐ์กฑ๋ถ๋ 22์ผ๋ถํฐ 28์ผ๊น์ง ์์ธ๊ณผ ์ถฉ๋ถ ๊ดด์ฐ์์ '๊ตญ์ ์ฒญ์๋ ํฌ๋ผ'์ ์ฐ๋ค๊ณ 21์ผ ๋ฐํ๋ค. ํ๊ตญ ๋ฏธ๊ตญ ์บ๋๋ค ํธ์ฃผ ๋ฑ ์ ์ธ๊ณ 32๊ฐ๊ตญ 75์ฌ๋ช ์ ๋ํ์, ์ฒญ์๋ ๋ค์ด ๋ชจ์ฌ ์ ์ธ๊ณ์ ํ์๋ฌธ์ ์ ๋ํ ๋์๊ณผ ํด๊ฒฐ์ฑ ์ ๋ชจ์ํ๋ ์๋ฆฌ๋ค. ์ด๋ฒ ํฌ๋ผ์ ์ฃผ์ ๋ '์ฒญ์๋ ๊ณผ ๋ด๋ฏธ๋์ด'๋ค. ์ค๋งํธํฐ SNS ํ๋ธ๋ฆฟPC ๋ฑ ์๋ก์ด ์ปค๋ฎค๋์ผ์ด์ ๋งค์ฒด์ธ '๋ด๋ฏธ๋์ด'์ ๋ํ ์ฑ์ฐฐ๊ณผ ๋ฌธ์ ์ ์ ๋ํด ํ ๋ก ํ๋ค. ๊ธฐ์กฐ๊ฐ์ฐ์ ์์์ผ๋ก ๊ตญ๊ฐ๋ณ ์ฃผ์ ๊ด๋ จ ์ฌ๋ก๋ฐํ, ๊ทธ๋ฃน ํ ๋ก ๋ฐ ์ ์ฒด์ดํ, '์ฒญ์๋ ์ ์ธ๋ฌธ' ์์ฑ ๋ฐ ์ฑํ ๋ฑ ๋ค์ํ ํ๋ก๊ทธ๋จ์ ์ด์ํ๋ค. ๊ฐํ์์ 22์ผ ์์ธ ๋ฐฉํ๋์ ์๋ ๊ตญ์ ์ฒญ์๋ ์ผํฐ ๊ตญ์ ํ์์ฅ์์ ํ๋ค. ์ ์ธ๊ณ 32๊ฐ๊ตญ ๋ํ์ใ์ฒญ์๋ ์ฐธ๊ฐ์์ ์ ๊ตญ์ ์ฒญ์๋ ๊ธฐ๊ด๋จ์ฒด์ฅ๊ณผ ์ฒญ์๋ ์ง๋์ ์ฌ์ฑ๊ฐ์กฑ๋ถ ์ฃผํ์ธ๊ต์ฌ์ ๋ฑ 100์ฌ๋ช ์ด ์ฐธ์ํ ์์ ์ด๋ค. 23์ผ์๋ ์ ์๋ฏธ๋ํฌ๋ผ ๋ฐ์์ ๋ํ๊ฐ '๋ด๋ฏธ๋์ด์ ๊ท ํ ์๋ ๋ฐ์ ์ ์ํ ์ฒญ์๋ ์ ์ญํ '์ ๋ํด ๊ธฐ์กฐ๊ฐ์ฐ์ ํ๋ค. ๋ด๋ฏธ๋์ด์ ์ฌ๋ฐ๋ฅธ ํ์ฉ๋ฐฉ์๊ณผ ์ฒญ์๋ ๋ฌธํ์ ํ์ฑ์ ๋ํด ์ค๋ช ํ ๊ณํ์ด๋ค. 27์ผ ํํ์์์๋ '์ฒญ์๋ ์ ์ธ๋ฌธ'์ ์ฑํํ๋ค. ์ ์ธ๋ฌธ์๋ ์ ์ธ๊ณ์ ์ผ๋ก ๋ด๋ฏธ๋์ด์ ๋ฐ๋์งํ ๋ฐ์ ์ ์ด๊ตฌํ๋ฉฐ ๊ฐ๊ตญ ์ฒญ๋ ๋ค์ด ํจ๊ป ์ค์ฒํ ์ ์๋ ๋ด์ฉ ๋ฑ์ด ๋ด๊ธธ ์์ ์ด๋ค. ํ๊ตญ์ฒญ์๋ ๋จ์ฒดํ์ํ๋ ํฌ๋ผ์ด ๋๋ ๋ค UN ๋ฑ ๊ตญ์ ๊ธฐ๊ตฌ์ ์ฐธ๊ฐ์ ๊ฐ๊ตญ ์ ๋ถ ๋ฑ ๊ตญ์ ์ฌํ์ ์ ์ธ๋ฌธ์ ์ ๋ฌํ ์์ ์ด๋ค.
[์ง์] ์์ธ๊ณผ ์ถฉ๋ถ ๊ดด์ฐ์์ '๊ตญ์ ์ฒญ์๋ ํฌ๋ผ'์ ์ฌ๋ ๊ณณ์?
Test Result (Model Output)
ํ๊ตญ์ฒญ์๋ ๋จ์ฒดํ์ํ์ ์ฌ์ฑ๊ฐ์กฑ๋ถ
CODE Test
User Prompt
Create an array of length 5 which contains all even numbers between 1 and 10.
Test Result (Model Output)
arr = [2, 4, 6, 8, 10]
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"chyungwon/police-report-analysis-model-MoE-3X8",
trust_remote_code=True,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(
"chyungwon/police-report-analysis-model-MoE-3X8",
trust_remote_code=True,
)
inputs = tokenizer("MoE(Mixture-of-Experts) ๋ชจ๋ธ์ด ๋จธ์ผ?", return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=64)
print('out : ', tokenizer.decode(outputs[0], skip_special_tokens=True))
out : ๊ฐ์ธ์ ์ผ๋ก, MoE(Mixture-of-Experts) ๋ชจ๋ธ์ ๋ณต์กํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ๋งค์ฐ ํจ๊ณผ์ ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ํ์ง๋ง, ๋ชจ๋ธ์ ๋ณต์ก์ฑ๊ณผ ํ์ต ๋ฐ์ดํฐ์ ์์ด ๋ง์ ๋จ์ ๋ ๊ณ ๋ คํด์ผ ํฉ๋๋ค.
Model Card Authors
(์ฃผ)์ธ์ ๋ณด
ํํ์ด์ง : http://www.ijbinfo.com
์ ๋ณดํต์ ์ฐ์
์งํฅ์์ ์ง์์ ๋ฐ์์ ์งํํ์ต๋๋ค.
Model Card Contact
(์ฃผ)์ธ์ ๋ณด
์ฃผ์ : ์์ธ์ ๊ธ์ฒ๊ตฌ ๊ฐ์ฐ๋ 60-5 ๊ฐ์๊ทธ๋ ์ดํธ๋ฐธ๋ฆฌA๋ 805ํธ
์ฐ๋ฝ์ฒ : TEL : 02-3397-7765 FAX : 02-3397-7769 E-mail : sales@injungbo.co.kr
๋ด๋น์ : ์ฅํ์(chyungwon@ijbinfo.com)
- Downloads last month
- 8