Instructions to use punsaisuwan/frankenmoe-python-typescript with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use punsaisuwan/frankenmoe-python-typescript with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir frankenmoe-python-typescript punsaisuwan/frankenmoe-python-typescript
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
v2: Full update - add reasoning expert, streaming, safety notes
Browse files
README.md
CHANGED
|
@@ -1,45 +1,110 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
-
base_model: mistralai/Mistral-Small-3.1-24B-Instruct-2503
|
| 4 |
tags:
|
| 5 |
-
-
|
| 6 |
-
-
|
| 7 |
-
- mixture-of-experts
|
| 8 |
-
- code-generation
|
| 9 |
-
- python
|
| 10 |
-
- typescript
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# FrankenMoE: Python + TypeScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
`
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
## Experts
|
| 21 |
|
| 22 |
-
| Expert | Language | Rank | Target Modules |
|
| 23 |
|---|---|---|---|---|
|
| 24 |
-
| expert-1-python
|
| 25 |
-
| expert-2-typescript | TypeScript | 8 | default (incl. MoE switch layers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
## Usage
|
| 28 |
|
| 29 |
-
ต้องมี Base Model 4-bit อยู่ในเครื่อง
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
python frankenmoe_dispatcher.py
|
| 33 |
-
\`\`\`
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
## Training Details
|
| 40 |
|
| 41 |
-
- **Expert 1 (Python)**:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
| 3 |
tags:
|
| 4 |
+
- mlx
|
| 5 |
+
- lora
|
| 6 |
+
- mixture-of-experts
|
| 7 |
+
- code-generation
|
| 8 |
+
- python
|
| 9 |
+
- typescript
|
| 10 |
+
- reasoning
|
| 11 |
+
- streaming
|
| 12 |
+
base_model: mistralai/Mistral-Small-3.1-24B-Instruct-2503
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# FrankenMoE: Multi-Expert LoRA System (Python + TypeScript + Reasoning)
|
| 16 |
+
|
| 17 |
+
Triple LoRA adapters ที่ fine-tune บน 4-bit quantized MLX version ของ
|
| 18 |
+
`mistralai/Mistral-Small-3.1-24B-Instruct-2503` แยกตามความเชี่ยวชาญ
|
| 19 |
+
พร้อม Orchestrator ที่รองรับ Weighted Routing, LLM Fallback Classification,
|
| 20 |
+
Streaming Output, และ Multi-layer Safety Guard สำหรับป้องกัน
|
| 21 |
+
Repetition Loop และ Persona Drift
|
| 22 |
|
| 23 |
+
> **v2 Update:** เพิ่ม Expert 3 (Reasoning + Thai Translation Pipeline),
|
| 24 |
+
> เปลี่ยนจาก `frankenmoe_dispatcher.py` เดิมมาเป็น `moe_orchestrator.py`
|
| 25 |
+
> ที่มี Streaming Support และ Safety Net ที่ผ่านการทดสอบ Multi-turn
|
| 26 |
+
> มากกว่า 15 Turns โดยไม่พบ Repetition Loop
|
| 27 |
|
| 28 |
## Experts
|
| 29 |
|
| 30 |
+
| Expert | Language/Domain | Rank | Target Modules | Notes |
|
| 31 |
|---|---|---|---|---|
|
| 32 |
+
| expert-1-python | Python | 16 | q,k,v,o_proj | แก้ปัญหา rank/capacity ไม่พอจาก v1 |
|
| 33 |
+
| expert-2-typescript | TypeScript | 8 | default (incl. MoE switch layers) | แก้ NaN loss + Catastrophic Interference |
|
| 34 |
+
| expert-3-reasoning | General Reasoning (EN to TH) | - | default | มี Auto-translate pipeline เป็นภาษาไทย |
|
| 35 |
+
|
| 36 |
+
## Key Features
|
| 37 |
+
|
| 38 |
+
- **Weighted + LLM Fallback Routing**: ระบบเลือก Expert ด้วย Keyword Scoring
|
| 39 |
+
ก่อน ถ้ากำกวมจะใช้ Base Model เป็น Classifier ช่วยตัดสิน
|
| 40 |
+
- **Streaming Output**: Python/TypeScript Expert รองรับ Token-by-token
|
| 41 |
+
Streaming ผ่าน `query_stream()` เพื่อลด Perceived Latency
|
| 42 |
+
- **Repetition Guard**: ตรวจจับ Generation Loop ด้วย Sliding Window
|
| 43 |
+
(ทุก ~50 Token ระหว่าง Stream) และ Retry-once Policy สำหรับ Non-stream
|
| 44 |
+
- **Persona Enforcement**: บังคับสรรพนามและคำลงท้ายให้สม่ำเสมอ
|
| 45 |
+
("ผม" / "ครับ") ตลอดทุก Turn
|
| 46 |
+
- **Auto Thai Translation**: Reasoning Expert แปลผลลัพธ์เป็นไทยอัตโนมัติ
|
| 47 |
+
พร้อม Code-block Preservation (ป้องกันโค้ดถูกแปลผิดเพี้ยน)
|
| 48 |
|
| 49 |
## Usage
|
| 50 |
|
| 51 |
+
ต้องมี Base Model 4-bit อยู่ในเครื่อง:
|
| 52 |
+
|
| 53 |
+
pip install mlx-lm huggingface_hub[hf_xet]
|
| 54 |
+
huggingface-cli download --local-dir frankenmoe-python-typescript punsaisuwan/frankenmoe-python-typescript
|
| 55 |
+
|
| 56 |
+
### Interactive Chat (Streaming)
|
| 57 |
+
|
| 58 |
+
python moe_orchestrator.py
|
| 59 |
+
|
| 60 |
+
### Python API
|
| 61 |
|
| 62 |
+
from moe_orchestrator import MoEOrchestrator
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
orchestrator = MoEOrchestrator(
|
| 65 |
+
base_model_path="./output-moe-mlx-4bit",
|
| 66 |
+
adapter_paths={
|
| 67 |
+
"python": "./adapters/expert-1-python",
|
| 68 |
+
"typescript": "./adapters/expert-2-typescript",
|
| 69 |
+
"reasoning": "./adapters/expert-3-reasoning",
|
| 70 |
+
}
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Non-streaming (สำหรับ Automated Test / Batch)
|
| 74 |
+
response = orchestrator.query("เขียนฟังก์ชัน fibonacci ด้วย Python")
|
| 75 |
+
print(response)
|
| 76 |
+
|
| 77 |
+
# Streaming (สำหรับ Interactive Use)
|
| 78 |
+
for chunk in orchestrator.query_stream("เขียนฟังก์ชัน fibonacci ด้วย Python"):
|
| 79 |
+
print(chunk, end="", flush=True)
|
| 80 |
|
| 81 |
## Training Details
|
| 82 |
|
| 83 |
+
- **Expert 1 (Python)**: อัปเกรดจาก v1 (rank=8, broken) เป็น rank=16,
|
| 84 |
+
scale=8.0, ครอบคลุม 4 attention projections เพื่อแก้ปัญหา
|
| 85 |
+
capacity ไม่พอสำหรับ code generation ที่ซับซ้อน
|
| 86 |
+
- **Expert 2 (TypeScript)**: แก้ NaN loss ผ่าน `SAFE_PAD_TOKEN_ID=198`
|
| 87 |
+
และแก้ Catastrophic Interference ระหว่าง function/type guard bias
|
| 88 |
+
ด้วย dataset rebalancing + ลด learning rate เป็น 1.5e-5
|
| 89 |
+
- **Expert 3 (Reasoning)**: Train แยกจาก Code Experts เพื่อป้องกัน
|
| 90 |
+
Cross-domain Interference พร้อม Pipeline แปลไทยที่แยก Code Block
|
| 91 |
+
ออกก่อนแปล (ป้องกันโค้ดถูกแปลผิด) แล้วค่อยประกอบกลับ
|
| 92 |
+
|
| 93 |
+
## Safety and Stability Notes
|
| 94 |
+
|
| 95 |
+
ระบบผ่านการทดสอบ Multi-turn Conversation 15 Turns โดยไม่พบ
|
| 96 |
+
Repetition Loop และไม่ต้องพึ่ง Safety Net Fallback แม้แต่ครั้งเดียว
|
| 97 |
+
(`REPETITION_PENALTY=1.15` เป็นค่าที่ผ่านการ Tune แล้วว่าดีที่สุด)
|
| 98 |
+
|
| 99 |
+
ปัญหาเล็กน้อยที่ทราบอยู่ (Known Minor Issues):
|
| 100 |
+
- Code fence อาจปิดไม่ครบในบาง Edge Case
|
| 101 |
+
- พบ CJK character leak ในระดับต่ำมาก ไม่กระทบความเข้าใจ
|
| 102 |
+
|
| 103 |
+
## Requirements
|
| 104 |
+
|
| 105 |
+
mlx-lm
|
| 106 |
+
huggingface_hub[hf_xet]
|
| 107 |
+
|
| 108 |
+
## License
|
| 109 |
+
|
| 110 |
+
Apache 2.0 (ตาม Base Model)
|