|
|
--- |
|
|
license: mit |
|
|
pipeline_tag: text-generation |
|
|
library_name: mlx |
|
|
base_model: moonshotai/Kimi-Linear-48B-A3B-Instruct |
|
|
tags: |
|
|
- mlx |
|
|
- quantization |
|
|
- mxfp4 |
|
|
- mixture-of-experts |
|
|
--- |
|
|
<div align="center"> |
|
|
<h1><em><strong>Kimi-Linear-48B-A3B-Instruct ยท MXFP4 ยท 32-Group (MLX)</strong></em></h1> |
|
|
<strong>moonshotai/Kimi-Linear-48B-A3B-Instruct</strong> ๊ธฐ๋ณธ ๋ชจ๋ธ์ <code>mlx-lm 0.28.4</code><br> |
|
|
MXFP4 ๊ทธ๋ฃน์ฌ์ด์ฆ 32 ์ค์ ์ ๋ง์ถฐ ์์ํํ ๊ฒฐ๊ณผ๋ฌผ๊ณผ ํ๊น
ํ์ด์ค ์
๋ก๋์ฉ ๋ฉํ๋ฐ์ดํฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.<br> |
|
|
๋ชจ๋ ๊ฐ์ค์น์ ๋ถ๊ฐ ํ์ผ์ Apple Silicon์ฉ MLX ๋ฐํ์๊ณผ ์ฆ์ ํธํ๋ฉ๋๋ค. |
|
|
|
|
|
[ํ๊ตญ์ด](./README-kr.md) | [English](./README.md) |
|
|
|
|
|
</div> |
|
|
|
|
|
## ๋ชจ๋ธ ์์ฝ |
|
|
|
|
|
- **์ํคํ
์ฒ**: `config.json`์ ์ ์๋ KimiLinear MoE ๋์ฝ๋ ์ ์ฉ ํธ๋์คํฌ๋จธ (27 ๋ ์ด์ด, ํ๋ ์ฌ์ด์ฆ 2304, ์ดํ
์
ํค๋ 32๊ฐ, ์ ๋ฌธ๊ฐ 256๋ช
, ํ ํฐ๋น 8๋ช
ํ์ฑํ). |
|
|
- **์ปจํ
์คํธ ๊ธธ์ด**: ์ ํ ์ดํ
์
๊ธฐ๋ฐ ๋ธ๋ก์ผ๋ก ์ฝ 100๋ง ํ ํฐ ์์ค๊น์ง ํ๋๋์ด ์์ผ๋ฉฐ, ์ค์ ์๋์ฐ๋ `--max-kv-size` ๋ฑ ๋ฐํ์ ๋ฉ๋ชจ๋ฆฌ ์ค์ ์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋๋ค. |
|
|
- **ํ ํฌ๋์ด์ **: `tiktoken` ๊ธฐ๋ฐ BPE (`tokenizer_config.json`, `tiktoken.model`)์ด๋ฉฐ ํน์ ํ ํฐ ID๋ ํ์ผ ๋ด๋ถ์ ์ ์๋์ด ์์ด ์นด๋์์ ํ๋์ฝ๋ฉํ์ง ์์ต๋๋ค. |
|
|
- **์ฑํ
ํ
ํ๋ฆฟ**: ๊ณต์ Kimi ํด ํธ์ถ ํ๋ฆ์ ๋ฐ์ํ ๋ค์ค ํด ํ
ํ๋ฆฟ์ด `chat_template.jinja`์ ํฌํจ๋์ด ์์ต๋๋ค. |
|
|
- **๋ผ์ด์ ์ค**: ์
์คํธ๋ฆผ `moonshotai/Kimi-Linear-48B-A3B-Instruct`์ ๋์ผํ๊ฒ MIT. |
|
|
|
|
|
## ์์ํ ์ธ๋ถ ์ ๋ณด |
|
|
|
|
|
- **ํด๋ง**: `python3 -m mlx_lm.convert -q` (mlx-lm 0.28.4 ์ด์)์ผ๋ก MXFP4 ๊ฐ์ค์น๋ฅผ ์์ฑ. |
|
|
- **ํฌ๋งท**: MXFP4 4๋นํธ / ๊ทธ๋ฃน์ฌ์ด์ฆ 32๊ฐ ๋ชจ๋ ์ฃผ์ ์ ํ ๊ณ์ธต์ ์ ์ฉ๋ฉ๋๋ค. |
|
|
- **์์ธ**: Mixture-of-Experts ๊ฒ์ดํธ ํ๋ก์ ์
์ ๋ผ์ฐํ
์์ ์ฑ์ ์ํด 8๋นํธ / ๊ทธ๋ฃน์ฌ์ด์ฆ 64๋ก ์ ์ง๋๋ฉฐ `quantization_config` ๋ด์ ์ ๋ถ ๋ช
์๋์ด ์์ต๋๋ค. |
|
|
- **์ค๋ ๊ตฌ์ฑ**: `model-0000n-of-00005.safetensors` 5๊ฐ์ `model.safetensors.index.json`์ผ๋ก ์คํธ๋ฆฌ๋ฐ ๋ก๋๋ฅผ ์ง์ํฉ๋๋ค. |
|
|
- **๋ฉ๋ชจ๋ฆฌ**: Apple Silicon ํตํฉ ๋ฉ๋ชจ๋ฆฌ ์ฝ 26~29โฏGB ์์ค์์ ๊ฐ์ค์น๋ฅผ ์์ฉํ๋ฉฐ, KV ์บ์๋ ์ปจํ
์คํธ ๊ธธ์ด์ ๋ฐ๋ผ ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์๊ตฌํฉ๋๋ค. |
|
|
|
|
|
`config.json` ๋ฏธ๋ฆฌ๋ณด๊ธฐ: |
|
|
|
|
|
```json |
|
|
"quantization_config": { |
|
|
"group_size": 32, |
|
|
"bits": 4, |
|
|
"mode": "mxfp4", |
|
|
"model.layers.1.mlp.gate": {"group_size": 64, "bits": 8}, |
|
|
"model.layers.2.mlp.gate": {"group_size": 64, "bits": 8}, |
|
|
"model.layers.3.mlp.gate": {"group_size": 64, "bits": 8}, |
|
|
"...": "26๋ฒ ๋ ์ด์ด๊น์ง ๋์ผ ํจํด" |
|
|
} |
|
|
``` |
|
|
|
|
|
## ํฌํจ ํ์ผ |
|
|
|
|
|
| ํ์ผ | ์ฉ๋ | |
|
|
| -------------------------------------------------------------------------------------------- | -------------------------------- | |
|
|
| `config.json`, `generation_config.json`, `configuration_kimi.py` | HF ์ค์ + ๋ง์ถค MLX Config ํด๋์ค | |
|
|
| `model-0000*-of-00005.safetensors`, `model.safetensors.index.json` | ์์ํ๋ MXFP4 ์ค๋ | |
|
|
| `modeling_kimi.py` | `KimiLinearForCausalLM` ๊ตฌํ | |
|
|
| `tokenizer_config.json`, `special_tokens_map.json`, `tiktoken.model`, `tokenization_kimi.py` | ํ ํฌ๋์ด์ ์์ฐ | |
|
|
| `chat_template.jinja` | `apply_chat_template`์ฉ ํ
ํ๋ฆฟ | |
|
|
| `README.md`, `README-kr.md` | ์๋ฌธ/๊ตญ๋ฌธ ๋ชจ๋ธ ์นด๋ | |
|
|
|
|
|
## ์ฌ์ฉ ์๋ ๋ฐ ์ ํ |
|
|
|
|
|
- **๊ถ์ฅ ์ฌ์ฉ์ฒ**: Apple Silicon ํ๊ฒฝ์์ ๋ค๊ตญ์ด ์ด์์คํดํธ, ํด ํธ์ถ, ๋กฑ์ปจํ
์คํธ RAG. |
|
|
- **๋น๊ถ์ฅ ์ฌ์ฉ์ฒ**: ์๋ฃยท๋ฒ๋ฅ ยท๊ธ์ต ๋ฑ ๊ฒ์ฆ์ด ํ์ํ ๊ฒฐ์ ํน์ ํํฐ๋ง๋์ง ์์ ์ํ ์ง์ ์ฒ๋ฆฌ. |
|
|
- **์์ **: ๊ธฐ๋ณธ ๋ชจ๋ธ์ ์์ ํ๋กํ์ ๊ทธ๋๋ก ๋ฐ๋ฅด๋ฏ๋ก, ์ ํ ๋ฐฐํฌ ์ ์ถ๊ฐ ํํฐ๋ง๊ณผ RLHF ๊ณ์ธต์ ๊ถ์ฅํฉ๋๋ค. |
|
|
- **๋ณด์**: `modeling_kimi.py`์ ์ปค์คํ
๋ชจ๋์ด ์์ผ๋ฏ๋ก CLI ์คํ ์ `--trust-remote-code`, ํ์ด์ฌ API์์๋ `trust_remote_code=True`๋ฅผ ๋ฐ๋์ ์ฌ์ฉํ๊ณ ๋ฏผ๊ฐ ๋ฐ์ดํฐ๋ ์คํ๋ผ์ธ/๊ฒฉ๋ฆฌ ํ๊ฒฝ์์ ๋ค๋ฃจ์ธ์. |
|
|
|
|
|
## MLX ์ฌ์ฉ ๋ฐฉ๋ฒ |
|
|
|
|
|
1. macOS 13.6+ / Apple Silicon์์ MLX ํด ์ค์น: |
|
|
```bash |
|
|
pip install -U mlx-lm # ํน์ main: pip install -U "git+https://github.com/ml-explore/mlx-lm.git@main" |
|
|
# ์คํ๋ผ์ธ ์บ์ ์ ์ฉ: |
|
|
# HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 ... |
|
|
``` |
|
|
2. CLI ์ฑํ
(ํ
ํ๋ฆฟยท์ ์ง ๊ท์น ์๋ ์ ์ฉ): |
|
|
```bash |
|
|
mlx_lm.chat \ |
|
|
--model /path/to/Kimi-Linear-48B-A3B-Instruct-MXFP4-GS32-MLX \ |
|
|
--trust-remote-code \ |
|
|
--max-tokens 512 --temperature 0.7 --top-p 0.9 |
|
|
``` |
|
|
_256K ํ ํฐ ์ด์ ์คํ ์ `--max-kv-size 262144`(๋๋ ํ์์ ๋ฐ๋ผ ๋ ํฐ ๊ฐ)์ ์ถ๊ฐํ์ธ์._ |
|
|
3. ํ์ด์ฌ ์์: |
|
|
|
|
|
```python |
|
|
from mlx_lm import load, generate |
|
|
from mlx_lm.sample_utils import make_sampler, make_logits_processors |
|
|
|
|
|
model, tok = load( |
|
|
"/path/to/Kimi-Linear-48B-A3B-Instruct-MXFP4-GS32-MLX", |
|
|
trust_remote_code=True, |
|
|
) |
|
|
|
|
|
messages = [{"role": "user", "content": "Kimi Linear ๊ตฌ์กฐ๋ฅผ ๊ฐ๋จํ ์์ฝํด์ค."}] |
|
|
prompt = tok.apply_chat_template(messages, add_generation_prompt=True) |
|
|
|
|
|
sampler = make_sampler(temperature=0.7, top_p=0.9) |
|
|
procs = make_logits_processors(repetition_penalty=1.1, repetition_context_size=64) |
|
|
|
|
|
print( |
|
|
generate( |
|
|
model, |
|
|
tok, |
|
|
prompt, |
|
|
max_tokens=512, |
|
|
sampler=sampler, |
|
|
logits_processors=procs, |
|
|
) |
|
|
) |
|
|
``` |
|
|
|
|
|
_ํ๋ธ๋ฅผ ์ฐ์ง ์์์ผ ํ๋ค๋ฉด ์คํ ์ ์ `HF_HUB_OFFLINE=1`, `TRANSFORMERS_OFFLINE=1`์ ์ค์ ํ์ธ์._ |
|
|
|
|
|
## ๋ณํ ๋ฉ๋ชจ |
|
|
|
|
|
- ์๋ณธ ์ฒดํฌํฌ์ธํธ: 2025-11-07 UTC ๊ธฐ์ค `moonshotai/Kimi-Linear-48B-A3B-Instruct`. |
|
|
- ์ค์ ์ฌ์ฉ ์ปค๋งจ๋: |
|
|
```bash |
|
|
python3 -m mlx_lm.convert \ |
|
|
--hf-path moonshotai/Kimi-Linear-48B-A3B-Instruct \ |
|
|
--q-bits 4 -q \ |
|
|
--group-size 32 \ |
|
|
-o Kimi-Linear-48B-A3B-Instruct-MXFP4-GS32-MLX |
|
|
``` |
|
|
- ์์ํ ์ดํ `mlx_lm.chat` ์ํฐํฐ ๊ฒ์ฌ์ `safetensors` ์ฒดํฌ์ฌ์ผ๋ก ๋ฌด๊ฒฐ์ฑ์ ๊ฒ์ฆํ์ต๋๋ค. |
|
|
|
|
|
## ๋ฌด๊ฒฐ์ฑ & ๊ฒ์ฆ |
|
|
|
|
|
์
๋ก๋ ํ์๋ ๋ก์ปฌ์์ ์ค๋ ๋ฌด๊ฒฐ์ฑ์ ์ฌํ์ธํ์ธ์: |
|
|
|
|
|
```bash |
|
|
cd /path/to/Kimi-Linear-48B-A3B-Instruct-MXFP4-GS32-MLX |
|
|
shasum -a 256 model-*.safetensors > SHA256SUMS |
|
|
shasum -c SHA256SUMS |
|
|
``` |
|
|
|
|
|
## ์ถ๊ฐ ํ |
|
|
|
|
|
- `modeling_kimi.py` ์ปค์คํ
๋ ์ด์ด๋ฅผ ๋ฑ๋กํ๋ ค๋ฉด ํญ์ `--trust-remote-code`๋ฅผ ํฌํจํ์ธ์. |
|
|
- `mlx_lm.cache_prompt`์ `--max-kv-size` ์กฐํฉ์ ํ์ฉํ๋ฉด 1M๊ธ ํ๋กฌํํธ์์๋ ํตํฉ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์์ ์ ์ผ๋ก ์ ์ดํ ์ ์์ต๋๋ค. |
|
|
|
|
|
## ๋ฌดํํ ๊ฐ์ฌ |
|
|
|
|
|
- **Moonshot AI** โ Kimi ํจ๋ฐ๋ฆฌ์ Kimi Linear ์ํคํ
์ฒ ๊ณต๊ฐ๋ ์ธ์ ๋ ๊ณ ๋ง์ต๋๋ค. [Moonshot AI GitHub](https://github.com/moonshotai), [Kimi Linear](https://github.com/MoonshotAI/Kimi-Linear), ๊ธฐ์ ๋ฆฌํฌํธ๋ฅผ ์ฐธ๊ณ ํ์ธ์. |
|
|
- **Apple Machine Learning Research** โ ์ง์์ ์ธ ์
๋ฐ์ดํธ๋ฅผ ํตํ ์ง์ ๋๋ถ์ ์ด์ฌํ ํ์ตํ๊ณ ์์ต๋๋ค. ๊ณ ๋ง์ต๋๋ค. [MLX](https://github.com/ml-explore/mlx), [MLX-LM](https://github.com/ml-explore/mlx-lm). |
|
|
- **MLX Community** โ MLX ๊ฐ์ค์น์ ์์ ๋ฅผ ์ธ์ ๋ ๋น ๋ฅด๊ฒ ๊ณต์ ํด์ฃผ์ด ๊ณ ๋ง์ต๋๋ค. ์ธ์ ๋ ์ฐธ๊ณ ํ๊ณ ์์ต๋๋ค. [mlx-community HF](https://huggingface.co/mlx-community). |
|
|
|
|
|
_์ ์ ๊ฐ์ด ๊ฐ์ธ์ผ๋ก์จ ์๋ก์ด ๋์ ์ ์ง์ํ์๋ ๋ชจ๋ ํ๊ตญ์ธ๋ค์ ์์ํฉ๋๋ค. ์ง์งํฉ์๋ค. (ํ๋ญ~)_ |
|
|
|
|
|
## ์ธ์ฉ ์๋ด |
|
|
|
|
|
์ด ๋ชจ๋ธ์ ์ฌ์ฉํ๋ค๋ฉด Moonshot AI์ ๋ณธ ์์ํ ๋ฆด๋ฆฌ์ค๋ฅผ ๋ฌธ์๋ ์ฐ๊ตฌ ๊ฒฐ๊ณผ์ ํจ๊ป ์ธ์ฉํด์ฃผ์ธ์. |
|
|
|