Files
vLLM-Kunlunxin_p-800-tokeni…/README.md
2026-06-29 17:04:41 +08:00

51 lines
2.0 KiB
Markdown
Raw 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.

# xc-llm-kunlun-fix-tokenizer
基于 `harbor-contest.4pd.io/sunjichen/xc-llm-kunlun:latest` 的 tokenizer 自动修复镜像,解决部分模型 `tokenizer_config.json``tokenizer_class``TokenizersBackend` 等非标准类名导致 vLLM 启动失败的问题。
## 问题背景
某些经过训练/合并的模型,其 `tokenizer_config.json` 中存在以下问题:
- `tokenizer_class` 被设置为 `TokenizersBackend``TiktokenTokenizer` 等 transformers 不识别的类名
- `extra_special_tokens` 字段为 list 格式,而 transformers 期望 dict 格式
这会导致 `AutoTokenizer.from_pretrained` 抛出 `ValueError`vLLM 服务无法启动。
## 修复方式
容器启动时自动检测 `tokenizer_config.json`,若存在问题则将 tokenizer 文件复制到 `/tmp/fixed_tokenizer/` 并修复配置,再以 `--tokenizer /tmp/fixed_tokenizer` 参数启动 vLLM。原始模型目录不做任何修改。
## 使用方式
将原 docker run 命令中的镜像名替换为本镜像,并去掉 `--entrypoint vllm`,改为直接传参:
```bash
docker run -dit --name <container_name> \
-p 44825:8000 \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
--tmpfs /dev/shm:rw,nosuid,nodev,exec,size=64g \
--ulimit memlock=-1 \
--device=/dev/xpu0:/dev/xpu0 \
--device=/dev/xpuctrl:/dev/xpuctrl \
-v /path/to/model:/model \
<this-image> \
/model --port 8000 --served-model-name llm \
--max-model-len 2048 --gpu-memory-utilization 0.9 \
--enforce-eager --trust-remote-code -tp 1
```
## 环境变量
| 变量 | 默认值 | 说明 |
|---|---|---|
| `AUTO_FIX_TOKENIZER` | `auto` | `auto`:自动检测;`1`/`true`:强制修复;其他值:跳过修复 |
| `MODEL_DIR` | `/model` | 模型路径(通常通过命令行第一个参数传入) |
| `FIX_TOKENIZER_DIR` | `/tmp/fixed_tokenizer` | 修复后 tokenizer 文件的临时目录 |
## 构建
```bash
docker build -t xc-llm-kunlun-fix-tokenizer:latest .
```
CI 通过推送 `v*` tag 自动触发构建并推送镜像。