> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/qwen25.md).

# Qwen2.5

在 Clore.ai GPU 上运行阿里巴巴的 Qwen2.5 多语言 LLM

运行阿里巴巴的 Qwen2.5 系列模型——在 CLORE.AI GPU 上具备出色代码和数学能力的强大多语言 LLM。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 为什么选择 Qwen2.5？

* **多样化规格** - 0.5B 到 72B 参数
* **多语言** - 包含中文在内的 29 种语言
* **长上下文** - 最多 128K token
* **专用变体** - Coder、Math 版本
* **开源** - Apache 2.0 许可证

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
vllm/vllm-openai:latest
```

**端口：**

```
22/tcp
8000/http
```

**命令：**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-7B-Instruct \
    --host 0.0.0.0 \\
    --port 8000
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

### 验证是否正常工作

```bash
# 检查服务是否就绪
curl https://your-http-pub.clorecloud.net/health

# 列出可用模型
curl https://your-http-pub.clorecloud.net/v1/models
```

{% hint style="warning" %}
如果你收到 HTTP 502，请等待 5-15 分钟——模型仍在从 HuggingFace 下载。
{% endhint %}

## Qwen3 推理模式

{% hint style="info" %}
**Qwen3 新增：** 部分 Qwen3 模型支持推理模式，会将模型的思考过程以 `<think>` 标签形式显示在最终答案之前。
{% endhint %}

通过 vLLM 使用 Qwen3 模型时，响应可能包含推理内容：

```json
{
  "content": "<think>\n让我一步一步想一想...\n</think>\n\n答案是..."
}
```

使用带推理的 Qwen3：

```bash
vllm serve Qwen/Qwen3-0.6B --host 0.0.0.0 --port 8000
```

## 模型变体

### 基础模型

| 模型                   | 参数   | 显存（FP16） | 上下文  | 备注       |
| -------------------- | ---- | -------- | ---- | -------- |
| Qwen2.5-0.5B         | 0.5B | 2GB      | 32K  | 边缘端/测试   |
| Qwen2.5-1.5B         | 1.5B | 4GB      | 32K  | 极轻量      |
| Qwen2.5-3B           | 3B   | 8GB      | 32K  | 预算       |
| Qwen2.5-7B           | 7B   | 16GB     | 128K | 均衡       |
| Qwen2.5-14B          | 14B  | 32GB     | 128K | 高质量      |
| Qwen2.5-32B          | 32B  | 70GB     | 128K | 非常高质量    |
| Qwen2.5-72B          | 72B  | 150GB    | 128K | **最佳质量** |
| Qwen2.5-72B-Instruct | 72B  | 150GB    | 128K | 聊天/指令调优  |

### 专用变体

| 模型                         | 重点 | 最适合        | 显存（FP16） |
| -------------------------- | -- | ---------- | -------- |
| Qwen2.5-Coder-7B-Instruct  | 代码 | 编程、调试      | 16GB     |
| Qwen2.5-Coder-14B-Instruct | 代码 | 复杂代码任务     | 32GB     |
| Qwen2.5-Coder-32B-Instruct | 代码 | **最佳代码模型** | 70GB     |
| Qwen2.5-Math-7B-Instruct   | 数学 | 计算、证明      | 16GB     |
| Qwen2.5-Math-72B-Instruct  | 数学 | 研究级数学      | 150GB    |
| Qwen2.5-Instruct           | 聊天 | 通用助手       | 因情况而异    |

## 硬件要求

{% hint style="warning" %}
**Clore.ai 市场上未列出多 GPU 的 80GB 级机型。** 目前列出的最大配置是 4× RTX PRO 6000 Blackwell（每张 96GB，共 380GB）以及 8–11× RTX 5090（每张 32GB）。A100 / H200 / B200 容量可按 [裸机](https://clore.ai/bare-metal) 需求提供。部署前请查看 [GPU 价格与可用性](/guides/guides_v2-zh/ru-men-zhi-nan/pricing.md) 。
{% endhint %}

| 模型        | 最低 GPU        | 推荐           | 显存（Q4） |
| --------- | ------------- | ------------ | ------ |
| 0.5B-3B   | RTX 3060 12GB | RTX 3080     | 2-6GB  |
| 7B        | RTX 3090 24GB | RTX 4090     | 6GB    |
| 14B       | A100 40GB     | A100 80GB    | 12GB   |
| 32B       | A100 80GB     | 2x A100 40GB | 22GB   |
| 72B       | 2x A100 80GB  | 4x A100 80GB | 48GB   |
| Coder-32B | A100 80GB     | 2x A100 40GB | 22GB   |

## 安装

### 使用 vLLM（推荐）

```bash
pip install vllm==0.7.3

python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-7B-Instruct \
    --host 0.0.0.0 \\
    --port 8000
```

### 使用 Ollama

```bash
# 标准模型
ollama pull qwen2.5:7b
ollama pull qwen2.5:14b
ollama pull qwen2.5:32b
ollama pull qwen2.5:72b       # 新增：最大的 Qwen2.5

# 专用版
ollama pull qwen2.5-coder:7b
ollama pull qwen2.5-coder:32b  # 新增：最佳代码模型

# 运行聊天
ollama run qwen2.5:7b
```

### 使用 Transformers

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "Qwen/Qwen2.5-7B-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto"
)

messages = [{"role": "user", "content": "你好！"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([text], return_tensors="pt").to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

## API 使用

### OpenAI 兼容 API

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="not-needed"
)

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "用简单的话解释机器学习。"}
    ],
    temperature=0.7,
    max_tokens=500
)

print(response.choices[0].message.content)
```

### 流式输出

```python
stream = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[{"role": "user", "content": "写一首关于 AI 的诗"}],
    stream=True
)

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

### cURL

```bash
curl http://localhost:8000/v1/chat/completions \\
    -H "Content-Type: application/json" \\
    -d '{
        "model": "Qwen/Qwen2.5-7B-Instruct",
        "messages": [
            {"role": "user", "content": "什么是 Python？"}
        ]
    }'
```

## Qwen2.5-72B-Instruct

旗舰级 Qwen2.5 模型——该系列中规模最大、能力最强的模型。它在许多基准测试中可与 GPT-4 竞争，并且在 Apache 2.0 许可证下完全开源。

### 通过 vLLM 运行（多 GPU）

```bash
# 4x A100 80GB 配置
vllm serve Qwen/Qwen2.5-72B-Instruct \
    --host 0.0.0.0 \\
    --port 8000 \\
    --tensor-parallel-size 4 \\
    --max-model-len 32768 \\
    --gpu-memory-utilization 0.9

# AWQ 量化——可运行于 2x A100 80GB
vllm serve Qwen/Qwen2.5-72B-Instruct-AWQ \
    --host 0.0.0.0 \\
    --port 8000 \\
    --tensor-parallel-size 2 \\
    --quantization awq \
    --max-model-len 32768
```

### 通过 Ollama 运行

```bash
# 拉取 72B 模型（Q4 需要 48GB+ VRAM）
ollama pull qwen2.5:72b

# 运行交互式会话
ollama run qwen2.5:72b

# API 访问
curl http://localhost:11434/api/chat -d '{
  "model": "qwen2.5:72b",
  "messages": [{"role": "user", "content": "分析这个复杂场景..."}],
  "stream": false
}'
```

### Python 示例

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")

# 72B 模型擅长复杂分析任务
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-72B-Instruct",
    messages=[
        {
            "role": "system",
            "content": "你是一名专家分析师。请提供详细、细致的回答。"
        },
        {
            "role": "user",
            "content": """比较 transformer 和 
            用于序列建模的状态空间模型（SSM）的架构差异。包括效率权衡。"""
        }
    ],
    temperature=0.7,
    max_tokens=2000
)

print(response.choices[0].message.content)
```

## Qwen2.5-Coder-32B-Instruct

当前可用的最佳开源代码模型。Qwen2.5-Coder-32B-Instruct 在许多编程基准上与 GPT-4o 持平甚至更强，支持 40+ 种编程语言。

### 通过 vLLM 运行

```bash
# 单张 A100 80GB
vllm serve Qwen/Qwen2.5-Coder-32B-Instruct \
    --host 0.0.0.0 \\
    --port 8000 \\
    --max-model-len 16384 \\
    --gpu-memory-utilization 0.9

# 双 RTX 4090（每张 24GB = 共 48GB，使用 Q4 量化）
vllm serve Qwen/Qwen2.5-Coder-32B-Instruct-AWQ \
    --host 0.0.0.0 \\
    --port 8000 \\
    --tensor-parallel-size 2 \\
    --quantization awq
```

### 通过 Ollama 运行

```bash
# 拉取 Coder-32B（Q4 需要约 22GB VRAM）
ollama pull qwen2.5-coder:32b

# 运行
ollama run qwen2.5-coder:32b

# 使用代码提示词测试
ollama run qwen2.5-coder:32b "使用 aiohttp 编写一个 Python 异步网页爬虫"
```

### 代码生成示例

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")

# 全栈代码生成
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Coder-32B-Instruct",
    messages=[
        {
            "role": "system",
            "content": "你是一名专家软件工程师。请编写干净、可投入生产的代码，并带有适当的错误处理和文档。"
        },
        {
            "role": "user",
            "content": """编写一个 Python FastAPI 服务：
1. 接受 POST /summarize，请求体为 JSON {"text": "...", "max_length": 150}
2. 使用本地 Ollama 实例对文本进行摘要
3. 返回 {"summary": "...", "original_length": N, "summary_length": N}
4. 包含适当的错误处理、使用 Pydantic 的输入验证，以及异步支持"""
        }
    ],
    temperature=0.1,  # 代码使用低温度
    max_tokens=3000
)

print(response.choices[0].message.content)
```

````python
# 代码审查与调试
code_to_review = """
def find_duplicates(lst):
    seen = []
    duplicates = []
    for item in lst:
        if item in seen:
            duplicates.append(item)
        seen.append(item)
    return duplicates
"""

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Coder-32B-Instruct",
    messages=[
        {
            "role": "user",
            "content": f"审查这段 Python 代码的性能问题并提出改进建议：\n\n```python\n{code_to_review}\n```"
        }
    ],
    temperature=0.3
)

print(response.choices[0].message.content)
````

## Qwen2.5-Coder

针对代码生成进行了优化：

```bash
# 使用 vLLM
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-Coder-7B-Instruct \
    --host 0.0.0.0

# 使用 Ollama
ollama run qwen2.5-coder:7b
```

```python
prompt = """编写一个 Python 函数：
1. 接受一个数字列表
2. 返回中位数
3. 优雅地处理空列表
包含类型提示和文档字符串。"""

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Coder-7B-Instruct",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.2
)

print(response.choices[0].message.content)
```

## Qwen2.5-Math

专为数学推理而设计：

```bash
# 使用 vLLM
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-Math-7B-Instruct \
    --host 0.0.0.0
```

```python
prompt = """逐步求解：
求出所有满足以下条件的 x 值：x^3 - 6x^2 + 11x - 6 = 0"""

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Math-7B-Instruct",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.1
)

print(response.choices[0].message.content)
```

## 多语言支持

Qwen2.5 支持 29 种语言：

```python
# 中文
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[{"role": "user", "content": "用中文解释什么是人工智能"}]
)

# 日语
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[{"role": "user", "content": "请用日语解释什么是人工智能"}]
)

# 韩语
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[{"role": "user", "content": "请用韩语解释人工智能"}]
)
```

## 长上下文（128K）

```python
# 读取长文档
with open("long_document.txt", "r") as f:
    document = f.read()

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[
        {"role": "user", "content": f"请总结这份文档：\n\n{document}"}
    ],
    max_tokens=2000
)
```

## 量化

### Ollama 的 GGUF 格式

```bash
# 4 位量化
ollama pull qwen2.5:7b-instruct-q4_K_M
ollama pull qwen2.5:72b-instruct-q4_K_M   # 72B 的 4 位量化（约 48GB）

# 8 位量化
ollama pull qwen2.5:7b-instruct-q8_0

# Coder 变体
ollama pull qwen2.5-coder:32b-instruct-q4_K_M
```

### 使用 vLLM 的 AWQ

```bash
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-72B-Instruct-AWQ \
    --quantization awq \
    --tensor-parallel-size 2
```

### 使用 llama.cpp 的 GGUF

```bash
# 下载 GGUF
wget https://huggingface.co/Qwen/Qwen2.5-7B-Instruct-GGUF/resolve/main/qwen2.5-7b-instruct-q4_k_m.gguf

# 运行服务器
./llama-server -m qwen2.5-7b-instruct-q4_k_m.gguf \
    --host 0.0.0.0 \\
    --port 8080 \
    -ngl 35
```

## 多 GPU 设置

### 张量并行

```bash
# 4 张 GPU 上运行 72B
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-72B-Instruct \
    --tensor-parallel-size 4 \\
    --max-model-len 32768

# 2 张 GPU 上运行 32B
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-32B-Instruct \
    --tensor-parallel-size 2

# 2 张 GPU 上运行 Coder-32B
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-Coder-32B-Instruct \
    --tensor-parallel-size 2 \\
    --max-model-len 16384
```

## 性能

### 吞吐量（tokens/秒）

| 模型                | RTX 3090 | RTX 4090 | A100 40GB | A100 80GB |
| ----------------- | -------- | -------- | --------- | --------- |
| Qwen2.5-0.5B      | 250      | 320      | 380       | 400       |
| Qwen2.5-3B        | 150      | 200      | 250       | 280       |
| Qwen2.5-7B        | 75       | 100      | 130       | 150       |
| Qwen2.5-7B Q4     | 110      | 140      | 180       | 200       |
| Qwen2.5-14B       | -        | 55       | 70        | 85        |
| Qwen2.5-32B       | -        | -        | 35        | 50        |
| Qwen2.5-72B       | -        | -        | 20 (2x)   | 40 (2x)   |
| Qwen2.5-72B Q4    | -        | -        | -         | 55 (2x)   |
| Qwen2.5-Coder-32B | -        | -        | 32        | 48        |

### 首个 token 时间（TTFT）

| 模型  | RTX 4090 | A100 40GB  | A100 80GB  |
| --- | -------- | ---------- | ---------- |
| 7B  | 60ms     | 40ms       | 35ms       |
| 14B | 120ms    | 80ms       | 60ms       |
| 32B | -        | 200ms      | 140ms      |
| 72B | -        | 400ms (2x) | 280ms (2x) |

### 上下文长度 vs VRAM（7B）

| 上下文  | FP16 | Q8   | Q4   |
| ---- | ---- | ---- | ---- |
| 8K   | 16GB | 10GB | 6GB  |
| 32K  | 24GB | 16GB | 10GB |
| 64K  | 40GB | 26GB | 16GB |
| 128K | 72GB | 48GB | 28GB |

## 基准

| 模型                | MMLU  | HumanEval | GSM8K | MATH  | LiveCodeBench |
| ----------------- | ----- | --------- | ----- | ----- | ------------- |
| Qwen2.5-7B        | 74.2% | 75.6%     | 85.4% | 55.2% | 42.1%         |
| Qwen2.5-14B       | 79.7% | 81.1%     | 89.5% | 65.8% | 51.3%         |
| Qwen2.5-32B       | 83.3% | 84.2%     | 91.2% | 72.1% | 60.7%         |
| Qwen2.5-72B       | 86.1% | 86.2%     | 93.2% | 79.5% | 67.4%         |
| Qwen2.5-Coder-7B  | 72.8% | 88.4%     | 86.1% | 58.4% | 64.2%         |
| Qwen2.5-Coder-32B | 83.1% | **92.7%** | 92.3% | 76.8% | **78.5%**     |

## Docker Compose

```yaml
version: '3.8'

services:
  qwen:
    image: vllm/vllm-openai:latest
    ports:
      - "8000:8000"
    volumes:
      - ~/.cache/huggingface:/root/.cache/huggingface
    command: >
      --model Qwen/Qwen2.5-7B-Instruct
      --host 0.0.0.0
      --port 8000
      --gpu-memory-utilization 0.9
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
```

## 成本估算

CLORE.AI 市场的典型费率：

| GPU           | 小时费率    | 最适合              |
| ------------- | ------- | ---------------- |
| RTX 3090 24GB | \~$0.06 | 7B 模型            |
| RTX 4090 24GB | \~$0.10 | 7B-14B 模型        |
| A100 40GB     | \~$0.17 | 14B-32B 模型       |
| A100 80GB     | \~$0.25 | 32B 模型、Coder-32B |
| 2x A100 80GB  | \~$0.50 | 72B 模型           |
| 4x A100 80GB  | \~$1.00 | 72B 最大上下文        |

*价格因提供商而异。查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

**节省费用：**

* 使用 **竞价** 适用于灵活工作负载的市场
* 使用 **CLORE** 代币支付
* 测试时先从较小的模型（7B）开始

## 故障排查

### 内存不足

```bash
# 减少上下文
--max-model-len 8192

# 启用内存优化
--gpu-memory-utilization 0.85

# 使用量化模型
ollama pull qwen2.5:7b-instruct-q4_K_M
```

### 生成缓慢

```bash
# 启用 flash attention
pip install flash-attn

# 使用 vLLM 以获得更高吞吐量
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-7B-Instruct \
    --enable-prefix-caching
```

### 中文字符显示

```python
# 确保 UTF-8 编码
import sys
sys.stdout.reconfigure(encoding='utf-8')
```

### 未找到模型

```bash
# 检查模型名称
huggingface-cli search Qwen/Qwen2.5

# 常见名称：
# Qwen/Qwen2.5-7B-Instruct
# Qwen/Qwen2.5-72B-Instruct       ← 新增
# Qwen/Qwen2.5-Coder-7B-Instruct
# Qwen/Qwen2.5-Coder-32B-Instruct ← 新增
# Qwen/Qwen2.5-Math-7B-Instruct
```

## Qwen2.5 与其他模型对比

| 功能  | Qwen2.5-7B | Qwen2.5-72B | Llama 3.1 70B | GPT-4o |
| --- | ---------- | ----------- | ------------- | ------ |
| 上下文 | 128K       | 128K        | 128K          | 128K   |
| 多语言 | 优秀         | 优秀          | 好             | 优秀     |
| 代码  | 优秀         | 优秀          | 好             | 优秀     |
| 数学  | 优秀         | 优秀          | 好             | 优秀     |
| 中文  | 优秀         | 优秀          | 较差            | 好      |
| 许可证 | Apache 2.0 | Apache 2.0  | Llama 3.1     | 专有     |
| 成本  | 免费         | 免费          | 免费            | 付费 API |

**在以下情况下使用 Qwen2.5：**

* 需要中文支持
* 数学/代码任务优先
* 需要长上下文
* 希望使用 Apache 2.0 许可证
* 需要最佳开源代码模型（Coder-32B）

## 下一步

* [vLLM](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md) - 生产部署
* [Ollama](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md) - 易于本地部署
* [DeepSeek-V3](/guides/guides_v2-zh/yu-yan-mo-xing/deepseek-v3.md) - 更大的推理模型
* [DeepSeek-R1](/guides/guides_v2-zh/yu-yan-mo-xing/deepseek-r1.md) - 开源推理模型
* [微调 LLM](/guides/guides_v2-zh/xun-lian/finetune-llm.md) - 定制训练


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/qwen25.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
