记一次 8xA100 80G 部署 DeepSeek-V4-Flash-0731 模型

最近有需求,需要本地部署一个 DeepSeek V4 Flash,而给到的资源有 8x A100 80G 的卡,这恐怕是我这一生中摸过最贵的机器之一了。

看上去 8 张,每张有 80G,理论上就有 640G 的显存是吧,但实际上这块卡的架构并不算新,所以真部署起来问题还是很多的。

nvidia-smi 的输出如下:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 590.48.01              Driver Version: 590.48.01      CUDA Version: 13.1     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA A100-SXM4-80GB          Off |   00000000:27:00.0 Off |                    0 |
| N/A   32C    P0             61W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   1  NVIDIA A100-SXM4-80GB          Off |   00000000:2A:00.0 Off |                    0 |
| N/A   28C    P0             59W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   2  NVIDIA A100-SXM4-80GB          Off |   00000000:51:00.0 Off |                    0 |
| N/A   29C    P0             63W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   3  NVIDIA A100-SXM4-80GB          Off |   00000000:57:00.0 Off |                    0 |
| N/A   32C    P0             58W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   4  NVIDIA A100-SXM4-80GB          Off |   00000000:9E:00.0 Off |                    0 |
| N/A   32C    P0             58W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   5  NVIDIA A100-SXM4-80GB          Off |   00000000:A4:00.0 Off |                    0 |
| N/A   29C    P0             58W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   6  NVIDIA A100-SXM4-80GB          Off |   00000000:C7:00.0 Off |                    0 |
| N/A   29C    P0             56W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   7  NVIDIA A100-SXM4-80GB          Off |   00000000:CA:00.0 Off |                    0 |
| N/A   31C    P0             59W /  400W |       0MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+

部署计划

我原先想用 vllm 进行部署,随后失败了,换 sglang,最后也已失败告终,不过即便如此还是把过程发一下吧,说不定有富哥能 H100、H200 需要用到呢?

vLLM 部署

vLLM(GitHub) 是一个开源的项目,旨在高效地进行大模型推理、服务,但在 A100 这种不支持 FP8 的环境上,DeepGEMM 会给你整坠机,最终以失败告终。

1.00

我们首先要进行一个 vLLM 的安装,这里注意 Python 需要 3.12,我试了 3.11 和 3.10 都会在类型注释上报语法错误,我试了接近 4 个小时,Python 你牛大了!

python --version
# 应当输出 Python 3.12 或者更高版本

然后我们只需要用 pip 来安装 vllm 这个包即可,下面的代码带上了源,以照顾互联网连通性不佳或者在特殊环境的小伙伴们:

pip install vllm -i https://pypi.mirrors.ustc.edu.cn/simple/

# 其中,不知为何,我也懒得深究,这机子还需要安装魔搭才能把 vLLM 跑起来:
pip install modelscope

这样就能把 vLLM 以及一些所需的其他依赖都装了,这机子既然装了 ModelScope,那模型也在上面下载算了,下面的命令将模型拉取到 ds4f0731 目录下:

modelscope download --model deepseek-ai/DeepSeek-V4-Flash-0731 --local_dir ds4f0731

启动命令如下:

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
VLLM_USE_DEEP_GEMM=0 \
vllm serve $(pwd)/ds4f0731 \
    --served-model-name DeepSeek-V4-Flash \
    --tensor-parallel-size 8 \
    --kv-cache-dtype fp8 \
    --trust-remote-code \
    --enforce-eager \
    --host 0.0.0.0 \
    --port 8000 | tee vllm-ds4f0731.log

# 大家有更新架构的硬件跑的话,可以将 `VLLM_USE_DEEP_GEMM=0` 的环境变量去掉,
# 再将 `--enforce-eager` 命令行参数去掉,以保证 Cudagraphs 啥的能启动,
# 提升推理的效率

然后坠机😡:

(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018]     tf32_hc_prenorm_gemm(
(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018]   File "/path/to/vllm/utils/deep_gemm.py", line 635, in tf32_hc_prenorm_gemm
(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018]     return _tf32_hc_prenorm_gemm_impl(
(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018] RuntimeError: Assertion error (/workspace/.deps/deepgemm-src/csrc/apis/hyperconnection.hpp:56): Unsupported architecture
(Worker_TP4 pid=577093) ERROR 08-12 22:48:51 [multiproc_executor.py:1018] Traceback (most recent call last):
(Worker_TP4 pid=577093) (Worker_TP6 pid=577095) ERROR 08-12 22:48:51 [multiproc_executor.py:1018] WorkerProc hit an exception.

行吧,vLLM 不带我们 Ampere 架构的老东西玩了,下意识我就想换 SGLang 去了。

SGLang 部署

SGLang(GitHub) 同样是一个高性能的模型推理、服务框架,等我环境搭建完了我才知道它也不支持 A100。


0.33

部署过程跟 vLLM 一样,不过我这次起步就 Python 3.12 了,没往下测过兼容性,命令如下:

pip install sglang -i https://pypi.mirrors.ustc.edu.cn/simple/

安装完毕后,迫不及待的进行一次理的推:

python -m sglang.launch_server \
    --model-path $(pwd)/dpskv4f \
    --tp 8 \
    --host 0.0.0.0 \
    --port 30000 | tee sglang-dpskv4f.log

再次坠机:

ValueError: The checkpoint you are trying to load has model type 
`deepseek_v4` but Transformers does not recognize this architecture. 
This could be because of an issue with the checkpoint, or because 
your version of Transformers is out of date.

You can update Transformers with the command `pip install --upgrade transformers`. 
If this does not work, and the checkpoint is very new, then there 
may not be a release version that supports this model yet. In this case, 
you can get the most up-to-date code by installing Transformers 
from source with the command `pip install git+https://github.com/huggingface/transformers.git`

我去,用户彻底怒了😡,出来吧,我最后的倔强 llama.cpp!

llama.cpp 部署

llama.cpp 是一款中间忘了后面忘了反正就是跟前面两个差不多的东西,但是兼容性更强吧(But at what cost?)。

它需要 gguf 格式的模型,所以我们重新拉一次模型吧,使用这条命令将模型拉取到 ds4f0731gguf 下:

modelscope download --model unsloth/DeepSeek-V4-Flash-0731-GGUF --include "UD-Q8_K_XL/*" --local_dir ds4f0731gguf

这里使用了 Q8_K_XL 规格的模型,这样可以尽量无损的跑模型,当然你也可以换 Q3_K_M 这种规格更小的模型(在上面将 UD-Q8_K_XL 改成 UD-Q3_K_M 即可)。

好消息,llama.cpp 用的是 C++ 写的,而不是 Python,所以我们终于不用从 PyPI 及其镜像站拉取那么大一坨依赖了,Native 科技,小子!

下载 Prebuilt 的 llama.cpp

发现一个叫 llamaup 的项目,大家的服务器要是支持的话,可以直接到这里找预构建的 CUDA llama.cpp,可以看到,网页上的 CUDA 最低版本是 13.4,虽然有 sm80 的构建,但是返回开头看看,这服务器的 CUDA Driver 是 13.1。

再见了所有的 Prebuilt!

自己构建 llama.cpp

自己动手,丰衣足食!服务器似乎有 nvcc 等 CUDA Toolkit,我们可以自己构建 llama.cpp。

我们需要 CMake 3.18,大家要是软件源里的 CMake 比较旧的话,自寻方法安装到更新的 CMake 吧。其次 gcc 8.5.0 是构建不了的,因为 llama.cpp 依赖了 C++17 才有的 <filesystem>,尝试用这个版本的 gcc 构建会因为缺头文件构建不下去,所以服务器的 gcc 比较老的话,就自行想办法安装更新的 gcc 吧。

我的服务器配置了 Miniconda,加上了国内的镜像源,所以我们可以用 Conda 来方便的安装上面提到所需的东西:

# 安装 CMake
conda install -c conda-forge cmake

# 安装 gcc
conda install -c conda-forge gcc_linux-64 gxx_linux-64

若使用 conda 来安装了 gcc/g++,我们还需要看一眼它们的目录:

ls $CONDA_PREFIX/bin/*gcc*
# 输出类似:
# /path/to/x86_64-conda-linux-gnu-gcc     /path/to/x86_64-conda-linux-gnu-gcc-nm
# /path/to/x86_64-conda-linux-gnu-gcc-ar  /path/to/x86_64-conda-linux-gnu-gcc-ranlib

我们可以看到 ls 的结果,第一项为 xxxx-gcc,我们需要记住它的全路径。

就以我为例,是 /path/to/x86_64-conda-linux-gnu-gcc。

于是我们需要覆盖一下编译器:

export CC=/path/to/x86_64-conda-linux-gnu-gcc
export CXX=/path/to/x86_64-conda-linux-gnu-g++

接下来,就要开始构建了,这一步需要用到 git:

# Git 拉取代码
git clone https://github.com/ggml-org/llama.cpp

# 进入路径
cd llama.cpp

# CMake 配置
cmake -B build \
    -DGGML_CUDA=ON \
    -DCMAKE_CUDA_ARCHITECTURES=80 \
    -DLLAMA_BUILD_SERVER=ON \
    -DLLAMA_BUILD_TESTS=OFF \
    -DLLAMA_BUILD_EXAMPLES=OFF \
    -DCMAKE_BUILD_TYPE=Release

# 构建 llama-server
cmake --build build --target llama-server -j

等待构建结束后,我们就可以看到 build/bin 目录下有 llama-server 的二进制文件了。

# ls build/bin/
libggml-base.so         libggml-cpu.so.0       libggml-cuda.so.0.19.0  libllama-common.so        libllama.so        libmtmd.so.0      llama-minicpmv-cli
libggml-base.so.0       libggml-cpu.so.0.19.0  libggml.so              libllama-common.so.0      libllama.so.0      libmtmd.so.0.1.0  llama-qwen2vl-cli
libggml-base.so.0.19.0  libggml-cuda.so        libggml.so.0            libllama-common.so.0.1.0  libllama.so.0.1.0  llama-gemma3-cli  llama-server
libggml-cpu.so          libggml-cuda.so.0      libggml.so.0.19.0       libllama-server-impl.so   libmtmd.so         llama-llava-cli

# cd build/bin && ./llama-server
0.01.653.234 I cmn  common_param: common_params_print_info: verbosity = 3 (adjust with the `-lv N` CLI arg)
0.01.654.324 I srv   load_models: Loaded 0 cached model presets
0.01.654.328 I srv    operator(): Available models (0) (*: custom preset)
0.01.654.448 W srv  llama_server: -----------------
0.01.654.450 W srv  llama_server: CORS is set to allow all origins ('*') and no API key is set
0.01.654.450 W srv  llama_server: this can be a security risk (cross-origin attacks)
0.01.654.450 W srv  llama_server: more info: https://github.com/ggml-org/llama.cpp/pull/25655
0.01.654.451 W srv  llama_server: -----------------
0.01.654.463 W srv  llama_server: -----------------
0.01.654.463 W srv  llama_server: the following feature(s) are enabled:
0.01.654.464 W srv  llama_server:     router mode
0.01.654.464 W srv  llama_server: do not expose the server to untrusted environments
0.01.654.465 W srv  llama_server: -----------------
0.01.654.465 I srv  llama_server: starting server in router mode. models will be automatically loaded on-demand
0.01.655.630 I srv  llama_server: listening on http://127.0.0.1:8080
0.01.655.632 W srv  llama_server: NOTICE: server default port will be changed to :9931 in a future release
0.01.655.633 W srv  llama_server:         ref: https://github.com/ggml-org/llama.cpp/pull/26508
^C0.10.381.559 I srv    operator(): operator(): cleaning up before exit...

我去你终于好了,我们构建出来了个最贴合本机硬件的 llama-server。

事不宜迟,我们来跑起来吧:

./llama-server \
  -m ../ds4f0731gguf/DeepSeek-V4-Flash-0731-UD-Q8_K_XL-00001-of-00005.gguf \
  -ngl 999 \
  --split-mode layer \
  --tensor-split 1,1,1,1,1,1,1,1 \
  --host 0.0.0.0 \
  --port 30000

其中,我们 -m 的参数指向我们刚刚拉取的 gguf 格式 DeepSeek V4 Flash 中第一个 gguf (00001-of-0000N)

0.01.490.142 I cmn  common_param: common_params_print_info: verbosity = 3 (adjust with the `-lv N` CLI arg)
0.02.556.157 W srv  llama_server: -----------------
0.02.556.160 W srv  llama_server: CORS is set to allow all origins ('*') and no API key is set
0.02.556.161 W srv  llama_server: this can be a security risk (cross-origin attacks)
0.02.556.161 W srv  llama_server: more info: https://github.com/ggml-org/llama.cpp/pull/25655
0.02.556.161 W srv  llama_server: -----------------
0.02.557.407 I srv    load_model: loading model '/path/to/ds4f0731gguf/UD-Q8_K_XL/DeepSeek-V4-Flash-0731-UD-Q8_K_XL-00001-of-00005.gguf'
0.28.475.482 I srv    load_model: initializing, n_slots = 4, n_ctx_slot = 1048576, kv_unified = 'true'
0.28.481.139 I srv  llama_server: model loaded
0.28.481.145 I srv  llama_server: listening on http://0.0.0.0:30000

我去,跑起来了,来看看 nvidia-smi 的输出:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 590.48.01              Driver Version: 590.48.01      CUDA Version: 13.1     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA A100-SXM4-80GB          Off |   00000000:27:00.0 Off |                    0 |
| N/A   33C    P0             67W /  400W |   21649MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   1  NVIDIA A100-SXM4-80GB          Off |   00000000:2A:00.0 Off |                    0 |
| N/A   29C    P0             64W /  400W |   18155MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   2  NVIDIA A100-SXM4-80GB          Off |   00000000:51:00.0 Off |                    0 |
| N/A   30C    P0             69W /  400W |   21685MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   3  NVIDIA A100-SXM4-80GB          Off |   00000000:57:00.0 Off |                    0 |
| N/A   32C    P0             64W /  400W |   18127MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   4  NVIDIA A100-SXM4-80GB          Off |   00000000:9E:00.0 Off |                    0 |
| N/A   33C    P0             65W /  400W |   21685MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   5  NVIDIA A100-SXM4-80GB          Off |   00000000:A4:00.0 Off |                    0 |
| N/A   30C    P0             64W /  400W |   18155MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   6  NVIDIA A100-SXM4-80GB          Off |   00000000:C7:00.0 Off |                    0 |
| N/A   30C    P0             62W /  400W |   21685MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   7  NVIDIA A100-SXM4-80GB          Off |   00000000:CA:00.0 Off |                    0 |
| N/A   33C    P0             80W /  400W |   15607MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      21642MiB |
|    1   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      18148MiB |
|    2   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      21678MiB |
|    3   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      18120MiB |
|    4   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      21678MiB |
|    5   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      18148MiB |
|    6   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      21678MiB |
|    7   N/A  N/A          598589      C   ...ma.cpp/build/bin/llama-server      15600MiB |
+-----------------------------------------------------------------------------------------+

每块 GPU 吃 ~20G 的 VRAM,震撼人心啊。

我们可以用下面的指令来试着推理推理:

curl http://127.0.0.1:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
  "model": "DeepSeek-V4-Flash-0731",
  "messages": [
    {
      "role": "user",
      "content": "你好,介绍一下自己"
    }
  ]
}'

得到响应:

{"choices":[{"finish_reason":"stop","index":0,"message":{"role":"assistant","content":"你好呀!很高兴认识你!🌟\n\n我是**DeepSeek**,由深度求索公司创造的AI助手。简单来说,我就像一个随时待命的智能伙伴,可以帮你解答问题、处理文字、分析信息,甚至陪你聊天解闷。\n\n**关于我的几个亮点:**\n\n✨ **免费使用** - 没错,完全免费!无论你问多少问题,我都乐意帮忙\n\n📚 **超大容量** - 我的上下文窗口有1M,可以一次性处理像《三体》三部曲那么大体量的内容\n\n🔗 **能读链接** - 给我网址,我能帮你读取里面的文字内容\n\n📎 **支持文件上传** - 图片、PDF、Word、Excel、PPT等格式都可以上传给我,我会读取其中的文字信息帮你处理\n\n🌐 **可以联网** - 如果你需要最新信息,记得在Web或App端手动打开联网搜索按钮哦\n\n📱 **多端使用** - 有网页版,也有App(支持语音输入),随时随地都能找到我\n\n**我的小限制:**\n- 我是纯文本模型,不能直接“看”图片,但可以读取图片里的文字\n- 知识截止到2025年5月,更新的信息需要联网获取\n\n无论你是想学习知识、解决工作难题、写作创作,还是单纯想找人聊聊天,我都随时在这儿!有什么想问的或需要帮忙的吗?😊","reasoning_content":"好的,用户让我介绍一下自己。这是一个非常简单的开场白问题,用户可能刚接触我,想了解我的基本功能和定位。我需要给出一个清晰、友好、全面的自我介绍,让用户知道我是谁、能做什么、有什么特点。\n\n想到了用热情的开场打招呼,然后说明我的身份和创造者。接着可以概括我的核心能力,比如知识问答、写作、编程等,并强调免费和长上下文这些实用特点。最后需要说明我的限制,比如不能处理图片,并引导用户提出具体需求,以开放式的提问结束,保持互动感��\n\n整体结构可以按照问候、身份介绍、能力列举、特点说明、限制告知、邀请提问来组织,语气要亲切热情,信息要条理分明。"}}],"created":1786559376,"model":"/path/to/ds4f0731gguf/UD-Q8_K_XL/DeepSeek-V4-Flash-0731-UD-Q8_K_XL-00001-of-00005.gguf","system_fingerprint":"b10397-84e908c62","object":"chat.completion","usage":{"completion_tokens":446,"prompt_tokens":8,"total_tokens":454,"prompt_tokens_details":{"cached_tokens":0}},"id":"chatcmpl-dnLJMOLg4Hz7Y7fDegcWMGCn6CElMn3b","timings":{"cache_n":0,"prompt_n":8,"prompt_ms":221.476,"prompt_per_token_ms":27.6845,"prompt_per_second":36.1212953096498,"predicted_n":446,"predicted_ms":14846.113,"predicted_per_token_ms":33.28724887892376,"predicted_per_second":30.041533430332912}}

可以看到最后的 predicted_per_second 是 30.04,也就是说自部署的 DeepSeek V4 Flash 0731 能够达到 ~30 token/s 的推理速度。

后记

这次部署也是让人涨知识了,知识不再只是记在脑子里的理论,不再只是纸上谈兵,而能够真正在一台服务器中部署起了能用的大语言模型。

为什么是 A100 呢,这就得问问美国商务部了,当然也希望国产卡能将 AI 的成本降下来吧。

最後更新: