All checks were successful
Docker Build and Push / docker (push) Successful in 1m5s
vllm-ascend-fix-tokenizer
基于 harbor.4pd.io/modelhubxc/enginex-ascend/vllm-ascend:v0.11.0rc0 的 tokenizer 自动修复镜像,面向 Ascend 910B3 NPU。
问题背景
部分模型的 tokenizer_config.json 存在以下问题,导致 vLLM 服务启动失败(错误码 TOKENIZER_FAILED):
| 错误 | 原因 |
|---|---|
ValueError: Tokenizer class TokenizersBackend does not exist |
tokenizer_class 不是 transformers 合法类名 |
AttributeError: 'list' object has no attribute 'keys' |
extra_special_tokens 为 list 格式,transformers 要求 dict |
详见 tokenizer_error_classification_summary.md。
修复方式
构建时将镜像内的 vllm 二进制(/usr/local/bin/vllm)替换为同名 wrapper 脚本,原二进制重命名为 vllm_real。
容器启动时 wrapper 自动检测 tokenizer_config.json:
- 存在问题 → 将 tokenizer 文件复制到
/tmp/fixed_tokenizer/并修复,追加--tokenizer /tmp/fixed_tokenizer参数后调用vllm_real - 无问题 → 直接调用
vllm_real,行为与原镜像完全一致
原始模型目录不做任何修改。
使用方式
原始 docker run 命令只需替换镜像名,其他参数不变:
# 原镜像
harbor.4pd.io/modelhubxc/enginex-ascend/vllm-ascend:v0.11.0rc0
# 替换为
<this-image>
示例:
docker run -dit --name <container_name> \
-p 8000:8000 \
--privileged=true \
--ipc=host \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /path/to/model:/model \
-e NPU_VISIBLE_DEVICES=0 \
-e ASCEND_RT_VISIBLE_DEVICES=0 \
--entrypoint vllm <this-image> \
serve /model --served-model-name llm \
--trust-remote-code --max-model-len 2048 --enforce-eager -tp 1
测试
如果发送请求时出现以下报错:
ValueError: default chat template is no longer allowed, so you must provide a chat template if the tokenizer does not define one.
请使用 completion 接口测试,而非 chat completion:
curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llm",
"prompt": "Hello, how are you?",
"max_tokens": 100
}'
docker build -t vllm-ascend-fix-tokenizer:latest .
CI 通过推送 v* tag 自动触发构建并推送镜像。
Description
Languages
Python
78.6%
Shell
12.7%
Dockerfile
8.7%