生成日期:2026-04-28 | 环境:Linux / Docker / vLLM v0.19.1 / NVIDIA RTX 4090 ×4
本文档记录了在单机 4×RTX 4090 环境下,通过 vLLM v0.19.1 部署两个大语言模型的完整过程,涵盖模型下载、Docker 容器配置、量化策略、推测解码及 KV cache 量化等关键技术细节。
部署模型:
| 模型 | 规模 | 精度 | 服务端口 | 状态 |
|---|---|---|---|---|
| Qwen3.6-35B-A3B-GPTQ-Int4 | 35B 总参数 / 3B 激活 | GPTQ Int4 | 18004 |
运行中 |
| Gemma-4-26B-A4B-it | 26B 总参数 / 4B 激活 | BF16 | 18005 |
待启动 |
| 项目 | 配置 |
|---|---|
| GPU | NVIDIA RTX 4090 × 4(GPU 4、5、6、7),Compute Capability 8.9 |
| GPU 显存 | 每卡 24 GiB,合计 96 GiB |
| 互联方式 | PCIe(非 NVLink,已禁用 custom_allreduce) |
| 推理框架 | vLLM v0.19.1(DaoCloud 镜像:docker.m.daocloud.io/vllm/vllm-openai:v0.19.1) |
| 容器运行时 | NVIDIA Container Runtime(--runtime nvidia) |
| 通信库 | NCCL 2.27.5 |
| Attention 后端 | FlashAttention v2 |
| 模型存储目录 | /data/models/int4/ |
使用 huggingface_hub 通过国内镜像站加速下载:
# 安装依赖(uv 虚拟环境) uv venv .venv --python python3.10 uv pip install huggingface_hub --python .venv/bin/python # 下载 Qwen3.6-35B-A3B-GPTQ-Int4 HF_ENDPOINT=https://hf-mirror.com .venv/bin/python -c " from huggingface_hub import snapshot_download snapshot_download( repo_id='palmfuture/Qwen3.6-35B-A3B-GPTQ-Int4', local_dir='/data/models/int4/Qwen3.6-35B-A3B-GPTQ-Int4', ) " # 下载 Gemma-4-26B-A4B-it HF_ENDPOINT=https://hf-mirror.com .venv/bin/python -c " from huggingface_hub import snapshot_download snapshot_download( repo_id='google/gemma-4-26B-A4B-it', local_dir='/data/models/int4/gemma-4-26B-A4B-it', ) "
| 模型 | 文件数 | 总大小 | 耗时 |
|---|---|---|---|
| Qwen3.6-35B-A3B-GPTQ-Int4 | 22 | 23 GiB | 约 1h 40min |
| Gemma-4-26B-A4B-it | 10 | 49 GiB | 约 5h |
https://hf-mirror.com 代理了模型元数据和小文件,但大权重文件(safetensors)经由 xet/CAS 存储系统下载,部分仍走境外线路,速度受限。模型采用 GPTQ Int4 量化(由 GPTQModel 6.0.3 生成),关键配置:
| 参数 | 值 | 说明 |
|---|---|---|
bits | 4 | 权重量化位宽 |
group_size | 128 | 分组量化粒度 |
desc_act | false | 不使用激活重排序 |
sym | true | 对称量化 |
| 排除层 | attn、shared_expert、mtp、visual、mlp.gate、lm_head、embed_tokens | 这些层保持原始精度 |
#!/bin/bash
# /data/models/int4/start_qwen3.6_int4.sh
docker rm qwen3.6-int4 -f 2>/dev/null
docker run -d --restart unless-stopped \
--name qwen3.6-int4 -p 18004:8000 \
--runtime nvidia --ipc=host \
-e NVIDIA_VISIBLE_DEVICES=4,5,6,7 \
-e PYTORCH_ALLOC_CONF=expandable_segments:True \
-v /data/models/int4/Qwen3.6-35B-A3B-GPTQ-Int4:/model \
docker.m.daocloud.io/vllm/vllm-openai:v0.19.1 \
--tensor-parallel-size 4 \
--reasoning-parser qwen3 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder \
--default-chat-template-kwargs '{"enable_thinking": false}' \
--speculative-config '{"method":"qwen3_next_mtp","num_speculative_tokens":2}' \
--additional-config '{"turboquant": true, "k_quant": "q4_0", "v_quant": "q3_0"}' \
--max-model-len 253440 \
--enable-prefix-caching \
--served-model-name Qwen3.6-35B-A3B-GPTQ-Int4 \
--enforce-eager \
--model /model
docker logs -f qwen3.6-int4
| 参数 | 值 | 说明 |
|---|---|---|
--tensor-parallel-size | 4 | 4 卡张量并行 |
--reasoning-parser qwen3 | — | 解析 <think> 推理链 |
--tool-call-parser qwen3_coder | — | 函数调用格式解析 |
--speculative-config | method=mtp, num_speculative_tokens=2 | MTP 推测解码,每步草稿 2 token |
--additional-config turboquant | k_quant=q4_0, v_quant=q3_0 | KV cache 量化(DaoCloud 扩展) |
--max-model-len | 253440 | 最大上下文长度(约 247K tokens) |
--enable-prefix-caching | — | 前缀缓存加速重复前缀场景 |
--enforce-eager | — | 禁用 CUDAGraph / torch.compile |
MTP 推测解码各位置接受率:position-0 ≈ 55~83%,position-1 ≈ 25~50%。
| 项目 | 值 |
|---|---|
| 架构 | Gemma4ForConditionalGeneration(多模态) |
| 精度 | BF16(无权重量化) |
| 参数量 | 26B 总参数 / 4B 激活(MoE) |
| 文��大小 | 49 GiB(2 个 safetensors 分片) |
| 上下文长度 | 131,072 tokens(128K) |
#!/bin/bash
# /data/models/int4/start_gemma4_26b.sh
docker rm gemma4-26b -f 2>/dev/null
docker run -d --restart unless-stopped \
--name gemma4-26b -p 18005:8000 \
--runtime nvidia --ipc=host \
-e NVIDIA_VISIBLE_DEVICES=4,5,6,7 \
-e PYTORCH_ALLOC_CONF=expandable_segments:True \
-v /data/models/int4/gemma-4-26B-A4B-it:/model \
docker.m.daocloud.io/vllm/vllm-openai:v0.19.1 \
--tensor-parallel-size 4 \
--enable-auto-tool-choice \
--tool-call-parser pythonic \
--max-model-len 131072 \
--enable-prefix-caching \
--served-model-name gemma-4-26B-A4B-it \
--enforce-eager \
--model /model
docker logs -f gemma4-26b
pythonic、不使用 turboquant(BF16 权重)。turboquant 是 DaoCloud 定制 vLLM 镜像中的 KV cache 量化扩展,与模型权重量化相互独立,可叠加使用。
| 参数 | 说明 |
|---|---|
turboquant: true | 启用 KV cache 量化 |
k_quant: "q4_0" | Key cache 量化为 4-bit |
v_quant: "q3_0" | Value cache 量化为 3-bit |
生效验证:日志中参数被正确解析(无报错),初始化阶段出现两次如下提示,说明有耗时的 KV cache 量化操作执行:
No available shared memory broadcast block found in 60 seconds. This typically happens when some processes are doing time-consuming work (e.g. compilation, weight/kv cache quantization).
curl http://localhost:18004/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen3.6-35B-A3B-GPTQ-Int4",
"messages": [{"role": "user", "content": "你好"}],
"max_tokens": 512
}'
curl http://localhost:18005/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemma-4-26B-A4B-it",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 512
}'
curl http://localhost:18004/v1/models curl http://localhost:18005/v1/models
| 问题 | 说明 |
|---|---|
| MTP 方法名弃用 | qwen3_next_mtp 已被标记为 deprecated,vLLM 自动映射到 mtp,功能正常。 |
| PCIe 互联限制 | 4×RTX 4090 为 PCIe 连接,不支持 NVLink SymmMem 和 custom_allreduce,all-reduce 走标准 NCCL,带宽有限。 |
| MoE config 缺失 | vLLM 未找到 RTX 4090 的 MoE 内核配置文件,使用默认配置,性能可能非最优。 |
| Prefix caching + Mamba | Qwen3.6 含 Mamba 层,prefix caching 处于实验性支持阶段,已自动设置为 align 模式。 |
| max_num_seqs | 未显式设置,使用 vLLM 默认值(256 并发序列)。高并发场景可按需调低以控制显存。 |
| Gemma 4 模型权重 | 49 GiB BF16,4 卡各承载约 12.25 GiB 权重,加上 KV cache 开销,显存较为紧张,建议降低 max-model-len 或减少 max-num-seqs。 |