Files
2026-10-30 17:29:26 +08:00

92 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 昆仑芯 DeepSeek INT8 修复镜像
基础镜像:用户已提交的 `xc-llm-kunlun:v0.25.1`。
输出镜像:`xc-llm-kunlun:v0.25.1-int8-fixed`。
## 修改内容
1. `vllm_kunlun/quantization/compressed_tensors/compressed_tensors_moe.py`:
INT8 MoE 从 RoutedExperts 实例读取 scoring_func、num_expert_group、topk_group、e_score_correction_bias 和 routed_scaling_factor,替代旧接口的默认值。避免 DeepSeek sigmoid 分组路由被错误地执行成 softmax;尊重外层 runner 的缩放分工,不硬编码 2.5。
2. `vllm_kunlun/ops/_custom_ops.py`:
两个 sigmoid 路由包装函数向 kunlun_ops 传参时,将 `block_static=block_static` 改为 `block_statistic=block_static`。保留上层 Torch 注册接口的 block_static 名称。
补丁可重复执行。构建时检查版本、语法、路由参数与底层函数签名,不导入 torch/vllm、不使用 XPU。文件原本已修复时只验证,不重复插入。
MLA 接口并未修复,启动脚本使用 `VLLM_MLA_DISABLE=1` 绕过当前 FlashMLAImpl 缺少 forward_mha/forward_mqa 的问题。使用 `VLLM_KUNLUN_ENABLE_INT8_BMM=0`,与已转换权重中的 BF16 kv_b_proj 一致。首测使用 TP=8、不启用 EP、eager、单并发、4096 上下文、每卡 4 GiB KV cache。
模型权重不打入镜像。当前转换结果中,路由专家和部分 MLA 投影为 INT8,kv_b_proj、Dense MLP 与共享专家为 BF16;MTP 已排除。
## 构建
在 172.28.4.201 宿主机执行:
```bash
cd /mnt/disk1/quant_tools/deepseek_r1_image
docker build --pull=false \
--build-arg BASE_IMAGE=xc-llm-kunlun:v0.25.1 \
-t xc-llm-kunlun:v0.25.1-int8-fixed .
```
仅针对内置文件验证补丁,不挂卡、不挂模型:
```bash
docker run --rm xc-llm-kunlun:v0.25.1-int8-fixed \
/opt/vllm_kunlun/bin/python /opt/kunlun-deepseek-fixes/apply_patches.py --check
```
## 启动与验证
切换服务前先停止旧服务,释放设备和端口。若旧服务由 srx_test 承载,可停止旧容器后再启动新容器:
```bash
docker stop srx_test
cd /mnt/disk1/quant_tools/deepseek_r1_image
bash run_container.sh xc-llm-kunlun:v0.25.1-int8-fixed deepseek_int8_fixed
```
run_container.sh 挂入八张 XPU、xpuctrl、32 GiB 共享内存,使用 host 网络,沿用实际宿主机映射:
```text
/mnt/disk0 -> /mnt/data0
/mnt/disk1 -> /mnt/data1
```
执行真实 P800 路由数值检查(小张量,不加载模型):
```bash
docker exec deepseek_int8_fixed \
/opt/vllm_kunlun/bin/python /opt/kunlun-deepseek-fixes/test_route_p800.py
```
启动完整服务(该命令前台运行,测试请求另开终端):
```bash
docker exec -it deepseek_int8_fixed \
bash /opt/kunlun-deepseek-fixes/serve_deepseek.sh
```
确认模型文件存在于宿主机 `/mnt/disk1/deepseek-r1-INT8`。镜像内脚本使用容器路径 `/mnt/data1/deepseek-r1-INT8`。
服务启动后:
```bash
curl -sS http://127.0.0.1:8000/v1/models
curl -sS --max-time 300 http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"/mnt/data1/deepseek-r1-INT8","messages":[{"role":"user","content":"北京是哪个国家的首都?请简短回答。"}],"temperature":0,"max_tokens":2048}'
```
查看 content、reasoning 和 finish_reason。完整输出质量需实际业务问题验证,算子数值检查不能代替该步骤。
## 导出与回滚
```bash
docker save -o /mnt/disk1/xc-llm-kunlun-v0.25.1-int8-fixed.tar \
xc-llm-kunlun:v0.25.1-int8-fixed
# 另一台同架构、驱动兼容的 P800 机器:
docker load -i /path/to/xc-llm-kunlun-v0.25.1-int8-fixed.tar
```
镜像归档不包含挂载模型;迁移时模型目录需要单独准备。
回滚时停止新服务/容器,再使用原镜像或启动原容器;旧镜像标签保持不变。