# DeepSeek-V3

在 CLORE.AI GPU 上运行 DeepSeek-V3 —— 这是一款在推理能力上表现卓越的最先进开源大语言模型。

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

{% hint style="info" %}
**更新：DeepSeek-V3-0324（2024年3月）** — DeepSeek-V3 的最新修订在代码生成、数学推理和通用问题解决方面带来显著改进。参见 [变更日志](#whats-new-in-deepseek-v3-0324) 部分以获取详细信息。
{% endhint %}

## 为什么选择 DeepSeek-V3？

* **最先进** - 可与 GPT-4o 和 Claude 3.5 Sonnet 竞争
* **671B 专家模型（MoE）** - 总参数 671B，每个 token 激活 37B（高效推理）
* **改进的推理能力** - DeepSeek-V3-0324 在数学和代码方面显著更好
* **高效** - MoE 架构相较于密集模型降低了计算成本
* **开源** - 完全开源权重，采用 MIT 许可证
* **长上下文** - 128K token 上下文窗口

## DeepSeek-V3-0324 的更新内容

DeepSeek-V3-0324（2024年3月修订）在关键领域引入了有意义的改进：

### 代码生成

* **在人类评测（HumanEval）上提高 +8-12%** 相比原始 V3
* 在多文件代码库和复杂重构任务上表现更佳
* 更好地理解现代框架（FastAPI、Pydantic v2、LangChain v0.3）
* 生成完整、可运行代码时更可靠，不易遗漏

### 数学推理

* **在 MATH-500 上提高 +5%** 基准测试
* 更好的逐步证明构建能力
* 多步骤问题的数值精度有所提升
* 增强了在解题过程中识别并纠正错误的能力

### 通用推理

* 更强的逻辑推导和因果推断能力
* 在多步骤规划任务上表现更好
* 在边缘案例和模糊提示上的表现更一致
* 在复杂、多约束请求上的指令遵循能力得到改进

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

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

**端口：**

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

**命令（需要多 GPU）：**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V3-0324 \
    --host 0.0.0.0 \
    --port 8000 \
    --tensor-parallel-size 8 \
    --trust-remote-code
```

## 访问您的服务

部署后，在以下位置查找您的 `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

# 获取版本
curl https://your-http-pub.clorecloud.net/version
```

{% hint style="warning" %}
**重要：** DeepSeek-V3 需要 **8x A100 80GB** GPU 并且下载时间较长。在模型下载期间，HTTP 502 可能会持续 15-30 分钟。
{% endhint %}

## 1024x1024

| A100              | 参数量  | 活动   | 所需显存   | HuggingFace                                                                                             |
| ----------------- | ---- | ---- | ------ | ------------------------------------------------------------------------------------------------------- |
| DeepSeek-V3-0324  | 671B | 37B  | 8x80GB | [deepseek-ai/DeepSeek-V3-0324](https://huggingface.co/deepseek-ai/DeepSeek-V3-0324)                     |
| DeepSeek-V3       | 671B | 37B  | 8x80GB | [deepseek-ai/DeepSeek-V3](https://huggingface.co/deepseek-ai/DeepSeek-V3)                               |
| DeepSeek-V3-Base  | 671B | 37B  | 8x80GB | [deepseek-ai/DeepSeek-V3-Base](https://huggingface.co/deepseek-ai/DeepSeek-V3-Base)                     |
| DeepSeek-V2.5     | 236B | 21B  | 4x80GB | [deepseek-ai/DeepSeek-V2.5](https://huggingface.co/deepseek-ai/DeepSeek-V2.5)                           |
| DeepSeek-V2-Lite  | 16B  | 2.4B | 16GB   | [deepseek-ai/DeepSeek-V2-Lite](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite)                     |
| DeepSeek-Coder-V2 | 236B | 21B  | 4x80GB | [deepseek-ai/DeepSeek-Coder-V2-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Instruct) |

## 硬件要求

### 全精度

| A100             | 最低            | 推荐           |
| ---------------- | ------------- | ------------ |
| DeepSeek-V3-0324 | 8x A100 80GB  | 8x H100 80GB |
| DeepSeek-V2.5    | 4x A100 80GB  | 4x H100 80GB |
| DeepSeek-V2-Lite | RTX 4090 24GB | 按日费率         |

### 量化（AWQ/GPTQ）

| A100             | 量化   | 显存     |
| ---------------- | ---- | ------ |
| DeepSeek-V3-0324 | INT4 | 4x80GB |
| DeepSeek-V2.5    | INT4 | 2×80GB |
| DeepSeek-V2-Lite | INT4 | 8GB    |

## 安装

### 使用 vLLM（推荐）

```bash
pip install vllm==0.7.3

# DeepSeek-V3-0324（最新，8 GPU）
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V3-0324 \
    --tensor-parallel-size 8 \
    --trust-remote-code \
    --host 0.0.0.0 \
    --port 8000

# 原始 V3（仍然可用）
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V3 \
    --tensor-parallel-size 8 \
    --trust-remote-code \
    --host 0.0.0.0 \
    --port 8000
```

### 使用 Transformers

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

model_name = "deepseek-ai/DeepSeek-V3-0324"

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

messages = [{"role": "user", "content": "用通俗的语言解释量子计算。"}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)

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

### 使用 Ollama

```bash
# 拉取 DeepSeek-V3（需要大量资源）
ollama pull deepseek-v3

# 或更轻量的变体
ollama pull deepseek-coder-v2:16b

# 运行
ollama run deepseek-v3
```

## API 使用

### 兼容 OpenAI 的 API（vLLM）

```python
from openai import OpenAI

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

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[
        {"role": "system", "content": "你是一个乐于助人的 AI 助手。"},
        {"role": "user", "content": "编写一个用于查找素数的 Python 函数。"}
    ],
    temperature=0.7,
    max_tokens=1000
)

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

### 流式传输

```python
stream = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": "解释机器学习"}],
    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": "deepseek-ai/DeepSeek-V3-0324",
        "messages": [
            {"role": "user", "content": "法国的首都是什么？"}
        ],
        "temperature": 0.7
    }'
```

## DeepSeek-V2-Lite（单 GPU）

针对硬件受限的用户：

```bash
# 使用 vLLM
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V2-Lite \
    --trust-remote-code \
    --host 0.0.0.0

# 使用 Ollama
ollama run deepseek-coder-v2:16b
```

```python
# 在单 GPU 上使用 Transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model = AutoModelForCausalLM.from_pretrained(
    "deepseek-ai/DeepSeek-V2-Lite",
    torch_dtype=torch.float16,
    device_map="cuda",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V2-Lite", trust_remote_code=True)
```

## 代码生成

DeepSeek-V3-0324 在代码方面是同类最佳：

```python
prompt = """编写一个包含以下功能的二叉搜索树（Binary Search Tree）Python 类：
- 插入（insert）
- 查找（search）
- 删除（delete）
- 中序遍历（in-order traversal）
包含类型提示和文档字符串。"""

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.2  # 对代码任务降低温度
)

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

V3-0324 在高级代码任务上表现出色：

```python
# 多文件重构
prompt = """我有一个 Flask 应用，所有代码都在 app.py（500 行）。
将其重构为使用应用工厂模式，并为以下内容使用蓝图（blueprints）：
- auth（登录、注册、登出）
- api（REST 接口）
- admin（仪表盘）
展示完整的文件结构和所有文件。"""

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.1,
    max_tokens=4000
)
```

## 数学与推理

```python
# 复杂数学问题
prompt = """证明对于任意整数 n >= 1，和 1^2 + 2^2 + ... + n^2 = n(n+1)(2n+1)/6 成立。
使用数学归纳法并清晰展示所有步骤。"""

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.1  # 对数学任务使用非常低的温度
)

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

## 多 GPU 配置

### 8x GPU（完整模型 — V3-0324）

```bash
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V3-0324 \
    --tensor-parallel-size 8 \
    --max-model-len 32768 \
    --gpu-memory-utilization 0.9 \
    --trust-remote-code
```

### 4x GPU（V2.5）

```bash
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V2.5 \
    --tensor-parallel-size 4 \
    --max-model-len 16384 \
    --trust-remote-code
```

## background = Image.open("studio\_bg.jpg")

### 吞吐量（tokens/秒）

| A100                  | GPU 数量       | 上下文 | 每秒标记数 |
| --------------------- | ------------ | --- | ----- |
| DeepSeek-V3-0324      | 8x H100      | 32K | \~85  |
| DeepSeek-V3-0324      | 8x A100 80GB | 32K | \~52  |
| DeepSeek-V3-0324 INT4 | 4x A100 80GB | 16K | \~38  |
| DeepSeek-V2.5         | 4x A100 80GB | 16K | \~70  |
| DeepSeek-V2.5         | 2x A100 80GB | 8K  | \~45  |
| DeepSeek-V2-Lite      | 512x512      | 8K  | \~40  |
| DeepSeek-V2-Lite      | 速度           | 4K  | \~25  |

### 首个标记时间（TTFT）

| A100             | 配置      | TTFT     |
| ---------------- | ------- | -------- |
| DeepSeek-V3-0324 | 8x H100 | \~750ms  |
| DeepSeek-V3-0324 | 8x A100 | \~1100ms |
| DeepSeek-V2.5    | 4x A100 | \~500ms  |
| DeepSeek-V2-Lite | 512x512 | \~150ms  |

### 内存使用

| A100             | 精度   | 所需显存    |
| ---------------- | ---- | ------- |
| DeepSeek-V3-0324 | FP16 | 8x 80GB |
| DeepSeek-V3-0324 | INT4 | 4x 80GB |
| DeepSeek-V2.5    | FP16 | 4x 80GB |
| DeepSeek-V2.5    | INT4 | 2x 80GB |
| DeepSeek-V2-Lite | FP16 | 20GB    |
| DeepSeek-V2-Lite | INT4 | 10GB    |

## 基准测试

### DeepSeek-V3-0324 与竞品对比

| 基准            | V3-0324 | V3（原始） | GPT-4o | Claude 3.5 Sonnet |
| ------------- | ------- | ------ | ------ | ----------------- |
| MMLU          | 88.5%   | 87.1%  | 88.7%  | 88.3%             |
| HumanEval     | 90.2%   | 82.6%  | 90.2%  | 92.0%             |
| MATH-500      | 67.1%   | 61.6%  | 76.6%  | 71.1%             |
| GSM8K         | 92.1%   | 89.3%  | 95.8%  | 96.4%             |
| LiveCodeBench | 72.4%   | 65.9%  | 71.3%  | 73.8%             |
| Codeforces 等级 | 1850    | 1720   | 1780   | 1790              |

*注意：MATH-500 从 V3 到 V3-0324 的提升为 +5.5 个百分点。*

## Docker Compose

```yaml
version: '3.8'

services:
  deepseek：
    image: vllm/vllm-openai:latest
    ports:
      - "8000:8000"
    volumes:
      - ~/.cache/huggingface:/root/.cache/huggingface
    environment:
      - HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
    command: >
      --model deepseek-ai/DeepSeek-V2-Lite
      --host 0.0.0.0
      --port 8000
      --trust-remote-code
      --gpu-memory-utilization 0.9
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
```

## GPU 要求汇总

| 模型变体                | 推荐配置              | 每小时成本   |
| ------------------- | ----------------- | ------- |
| 完整 DeepSeek-V3-0324 | 8x A100 80GB      | \~$2.00 |
| DeepSeek-V2.5       | 4x A100 80GB      | \~$1.00 |
| 开发/测试               | RTX 4090（V2-Lite） | \~$0.10 |
| 生产环境 API            | 8x H100 80GB      | \~$3.00 |

## 下载所有所需的检查点

典型 CLORE.AI 市场价格：

| GPU 配置        | 验证 CUDA 兼容性 | 费用估算     |
| ------------- | ----------- | -------- |
| RTX 4090 24GB | \~$0.10     | \~$2.30  |
| 按日费率          | \~$0.17     | \~$4.00  |
| 4 小时会话        | \~$0.25     | \~$6.00  |
| 4x A100 80GB  | \~$1.00     | \~$24.00 |
| 8x A100 80GB  | \~$2.00     | \~$48.00 |

*价格因提供者而异。查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *A100 40GB*

**A100 80GB**

* 使用 **竞价** 用于开发的市场（通常便宜 30-50%）
* 以获取当前费率。 **CLORE** 节省费用：
* 在扩展之前使用 DeepSeek-V2-Lite 进行测试

## # 使用固定种子以获得一致结果

### 内存不足

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

# 或使用量化
--quantization awq

# 针对 12GB GPU 的 V2-Lite
--gpu-memory-utilization 0.85
--max-model-len 4096
```

### 模型下载缓慢

```bash
# 预下载
huggingface-cli download deepseek-ai/DeepSeek-V3-0324

# 或使用镜像
export HF_ENDPOINT=https://hf-mirror.com
```

### trust\_remote\_code 错误

```bash
# 对于 DeepSeek 模型始终包含此标志
--trust-remote-code
```

### 多 GPU 无法工作

```bash
# 检查 NCCL
nvidia-smi topo -m

# 设置 NCCL 变量
export NCCL_DEBUG=INFO
export NCCL_P2P_DISABLE=0
```

## DeepSeek 与其他模型对比

| 特性   | DeepSeek-V3-0324 | Llama 3.1 405B | Mixtral 8x22B |
| ---- | ---------------- | -------------- | ------------- |
| 参数量  | 671B（37B 激活）     | 405B           | 176B（44B 激活）  |
| 上下文  | 128K             | 128K           | 64K           |
| 代码   | **优秀**           | 很棒             | 良好            |
| 数学   | **优秀**           | 良好             | 良好            |
| 最小显存 | 8x80GB           | 8x80GB         | 2×80GB        |
| 许可   | MIT 协议           | Llama 3.1      | Apache 2.0    |

**在以下情况使用 DeepSeek-V3：**

* 需要最佳的推理性能
* 代码生成为主要用途
* 数学/逻辑任务很重要
* 有可用的多 GPU 部署环境
* 希望获得完全开源的权重（MIT 许可证）

## 使用以下方式支付

* [vLLM](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/vllm) - 部署服务器
* [DeepSeek-R1](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/deepseek-r1) - 专注于推理的变体
* [DeepSeek Coder](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/deepseek-coder) - 面向代码的变体
* [Ollama](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/ollama) - 更简化的部署
* [微调大型语言模型](https://docs.clore.ai/guides/guides_v2-zh/xun-lian/finetune-llm) - 自定义训练


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
