# MiMo-V2-Flash

> MiMo-V2-Flash 是一个 **3090 亿参数的专家混合（Mixture-of-Experts）模型** 语言模型，每个标记激活 150 亿参数。采用先进的投机性解码（EAGLE/MTP）构建，提供 **每秒 150+ 标记** 在 8×H100 上同时保持前沿级别的性能。以 **MIT 许可证**, 它代表了高效大规模推理的前沿。

## 概览

* **模型规模**: 总计 309B / 每标记激活 15B 参数（MoE）
* **许可证**: MIT（完全商业可用）
* **上下文**: 32K 标记
* **性能**: 在推理基准上处于最先进水平
* **显存（VRAM）**: 约 320GB FP16（最低要求 4×A100 80GB）
* **速度**: 在 8×H100 上使用投机性解码可达 150+ 标/秒

## 为什么选择 MiMo-V2-Flash？

**突破性速度**: MiMo-V2-Flash 通过 EAGLE（用于更大语言模型效率的外推算法）和 MTP（多标记预测）实现了前所未有的推理速度。传统模型一次生成一个标记，而 MiMo-V2 并行预测并验证多个标记。

**生产就绪的规模**: 在 309B 参数下，MiMo-V2-Flash 可与最大型前沿模型竞争，同时仍可在现实硬件配置上部署。15B 的激活参数确保了尽管参数总量巨大但推理仍然高效。

**先进架构**: 除了标准的 MoE 外，MiMo-V2-Flash 在模型架构中原生整合了投机性解码。这不是训练后优化——它被构建进基础中，从而保证加速。

**企业级质量**: MIT 许可且无使用限制。可大规模部署、微调或集成到商业产品中而无需担心许可问题。

## GPU 推荐配置

| 设置              | 显存（VRAM） | 性能           | 每日费用\*   |
| --------------- | -------- | ------------ | -------- |
| **4×A100 80GB** | 320GB    | \~80 标/秒     | \~$16.00 |
| **8×A100 40GB** | 320GB    | \~70 标/秒     | \~$28.00 |
| **2×H100**      | 160GB    | \~90 标/秒     | \~$12.00 |
| **8×H100**      | 640GB    | **150+ 标/秒** | \~$48.00 |
| 4×H200          | 564GB    | \~120 标/秒    | \~$32.00 |

**最佳性价比**: 4×A100 80GB 在每美元性能方面表现优秀。 **极致性能**: 8×H100 释放全部投机性解码潜能。

\*估算自 Clore.ai 市场价格

## 推荐使用 SGLang 部署

SGLang 为 MiMo-V2-Flash 的投机性解码特性提供最佳支持：

### 安装 SGLang

```bash
pip install "sglang[all]>=0.3.0"
# 或 最新 版本
pip install git+https://github.com/sgl-project/sglang.git
```

### 支持 MTP 的多 GPU 设置

```bash
python -m sglang.launch_server \
  --model-path mimo-ai/MiMo-V2-Flash \
  --tp-size 8 \
  --enable-mtp \
  --mtp-max-draft-tokens 8 \
  --mtp-acceptance-rate 0.8 \
  --mem-fraction-static 0.85 \
  --dtype float16 \
  --context-length 32768 \
  --served-model-name mimo-v2-flash
```

### 使用 OpenAI API 发起查询

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:30000/v1", 
    api_key="EMPTY"
)

response = client.chat.completions.create(
    model="mimo-v2-flash",
    messages=[
        {"role": "system", "content": "You are an expert AI researcher."},
        {"role": "user", "content": "Explain the EAGLE speculative decoding algorithm and why it enables faster inference"}
    ],
    max_tokens=1024,
    temperature=0.7,
    stream=True  # 推荐以获得最佳延迟
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end='', flush=True)
```

## 使用 vLLM 部署

vLLM 也支持带投机性解码的 MiMo-V2-Flash：

```bash
pip install vllm>=0.6.0

vllm serve mimo-ai/MiMo-V2-Flash \
  --tensor-parallel-size 8 \
  --speculative-model mimo-ai/MiMo-V2-Flash-Draft \
  --speculative-max-model-len 32768 \
  --speculative-draft-tensor-parallel-size 2 \
  --use-v2-block-manager \
  --dtype float16 \
  --served-model-name mimo-v2-flash \
  --trust-remote-code
```

## Docker 模板

```dockerfile
FROM nvidia/cuda:12.1-devel-ubuntu22.04

# 安装依赖
RUN apt-get update && \
    apt-get install -y python3.10 python3-pip git && \
    rm -rf /var/lib/apt/lists/*

# 安装具有 MTP 支持的 SGLang
RUN pip install "sglang[all]>=0.3.0" transformers

# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7

# 预下载模型（可选，可节省启动时间）
# RUN python3 -c "from transformers import AutoModel; AutoModel.from_pretrained('mimo-ai/MiMo-V2-Flash', trust_remote_code=True)"

EXPOSE 30000

CMD ["python", "-m", "sglang.launch_server", \
     "--model-path", "mimo-ai/MiMo-V2-Flash", \
     "--host", "0.0.0.0", \
     "--port", "30000", \
     "--tp-size", "8", \
     "--enable-mtp", \
     "--mtp-max-draft-tokens", "8", \
     "--dtype", "float16"]
```

在所有 GPU 上运行：

```bash
docker build -t mimo-v2-flash .
docker run --gpus all -p 30000:30000 \
  --shm-size=64g \
  --ulimit memlock=-1 \
  --ulimit stack=67108864 \
  mimo-v2-flash
```

## 高级配置

### 优化投机性解码

根据你的工作负载微调投机性参数：

```bash
# 用于代码生成（更高接受率）
python -m sglang.launch_server \
  --model-path mimo-ai/MiMo-V2-Flash \
  --tp-size 8 \
  --enable-mtp \
  --mtp-max-draft-tokens 12 \
  --mtp-acceptance-rate 0.9 \
  --temperature 0.1

# 用于创意写作（较低接受率）
python -m sglang.launch_server \
  --model-path mimo-ai/MiMo-V2-Flash \
  --tp-size 8 \
  --enable-mtp \
  --mtp-max-draft-tokens 6 \
  --mtp-acceptance-rate 0.7 \
  --temperature 0.8
```

### 内存优化

对于内存受限的设置：

```bash
# 降低内存使用（较慢但适配 4×A100）
python -m sglang.launch_server \
  --model-path mimo-ai/MiMo-V2-Flash \
  --tp-size 4 \
  --mem-fraction-static 0.75 \
  --context-length 16384 \
  --dtype float16 \
  --disable-cuda-graph  # 节省显存
```

## 基准示例

测试 MiMo-V2-Flash 的速度优势：

```python
import time
from openai import OpenAI

client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")

def benchmark_generation():
    start_time = time.time()
    
    response = client.chat.completions.create(
        model="mimo-v2-flash",
        messages=[
            {"role": "user", "content": "Write a detailed explanation of quantum computing in exactly 500 words"}
        ],
        max_tokens=600,
        temperature=0.1,
        stream=False
    )
    
    end_time = time.time()
    content = response.choices[0].message.content
    
    tokens = len(content.split())  # 粗略的标记估计
    duration = end_time - start_time
    tokens_per_second = tokens / duration
    
    print(f"Generated {tokens} tokens in {duration:.2f}s")
    print(f"Speed: {tokens_per_second:.1f} tokens/second")
    
    return tokens_per_second

# 运行基准
speed = benchmark_generation()
print(f"\nMiMo-V2-Flash achieved {speed:.1f} tok/s")
```

## 给 Clore.ai 用户的提示

* **多 GPU 为必需**: MiMo-V2-Flash 最少需要 4×A100 80GB。单 GPU 部署不可行。
* **NVLink 优势**: 选择在 GPU 之间具有 NVLink 的 Clore.ai 主机以获得最佳多 GPU 通信性能。
* **内存（RAM）要求**: 使用 8 块 GPU 时确保系统 RAM 256GB+ 以保证平稳运行。
* **投机性调优**: 调整 `mtp-max-draft-tokens` 基于你的用例 — 对于重复性任务取更高值，对创意工作取更低值。
* **上下文长度**: 32K 上下文为最优。更长的上下文会降低投机性解码的效果。

## 故障排除

| 问题                                | 解决方案                                                  |
| --------------------------------- | ----------------------------------------------------- |
| `内存不足错误（OutOfMemoryError）` 在启动时出现 | 减少 `mem-fraction-static` 或 `tp-size`                  |
| GPU 间通信缓慢                         | 验证 NVLink： `nvidia-ml-py3` 或 `nvidia-smi topo -m`     |
| MTP 未加速                           | 检查 `mtp-acceptance-rate` — 过高的值会禁用投机机制                |
| 模型加载超时                            | 预下载： `huggingface-cli download mimo-ai/MiMo-V2-Flash` |
| 标记接受率差                            | 检查温度设置 — 非常低或非常高的温度会降低接受率                             |

## 性能比较

| 模型                | 规模       | 速度（8×H100）   | 质量    |
| ----------------- | -------- | ------------ | ----- |
| GPT-4 Turbo       | \~1.7T   | \~15-25 标/秒  | ★★★★★ |
| Claude Sonnet 3.5 | \~200B   | \~25-35 标/秒  | ★★★★★ |
| **MiMo-V2-Flash** | **309B** | **150+ 标/秒** | ★★★★☆ |
| Llama 3.1 405B    | 405B     | \~30-45 标/秒  | ★★★★☆ |

MiMo-V2-Flash 在保持竞争质量的同时，实现了比可比模型 3-5 倍的加速。

## 资源

* [Hugging Face 上的 MiMo-V2-Flash](https://huggingface.co/mimo-ai/MiMo-V2-Flash)
* [EAGLE 论文](https://arxiv.org/abs/2401.15077)
* [SGLang 文档](https://sgl-project.github.io/start/install.html)
* [多标记预测（Multi-Token Prediction）](https://arxiv.org/abs/2404.19737)
* [投机性解码指南](https://huggingface.co/blog/assisted-generation)
