记一次 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 部署

vLLMGitHub) 是一个开源的项目,旨在高效地进行大模型推理、服务,但在 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 部署

SGLangGitHub) 同样是一个高性能的模型推理、服务框架,等我环境搭建完了我才知道它也不支持 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 科技,小子!


TODO...

最後更新: