Files
4paradigm 694fed044e
All checks were successful
Docker Build and Push / docker (push) Successful in 6m4s
fix tokenizer
2026-07-21 11:02:18 +08:00

56 lines
1.9 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.

# BI-150 Tokenizer 配置修复补丁
基于 BI-150 vLLM 0.8.3 镜像,修复以下两类 tokenizer 配置问题:
1. `tokenizer_class` 指向当前 `transformers` 中不存在的类,例如:
```text
ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported.
```
2. `extra_special_tokens` 使用 list而当前 `transformers` 要求该字段为 dict。
## 工作方式
镜像构建时用 wrapper 接管 `vllm` 命令。执行 `vllm serve <model_dir>` 时:
1. 读取模型的 `tokenizer_config.json`。
2. 检查 `tokenizer_class` 是否存在于当前 `transformers`,并检查 `extra_special_tokens` 是否为 list。
3. 发现任一问题时,将 tokenizer 文件复制到 `/tmp/fixed_tokenizer`。
4. 对不存在的 `tokenizer_class`,根据已有文件选择替代类:`tokenizer.json` 使用 `PreTrainedTokenizerFast``tokenizer.model` 使用 `LlamaTokenizer``vocab.json` 与 `merges.txt` 使用 `GPT2TokenizerFast`;无法判断时回退到 `PreTrainedTokenizerFast`。
5. 将 list 格式的 `extra_special_tokens` 转换为 `{token: token}` 形式的 dict。
6. 向原始 vLLM 命令追加 `--tokenizer /tmp/fixed_tokenizer`。
原模型目录不会被修改,仅处理以上两类 tokenizer 配置问题。
## 构建
```bash
docker build -t iluvatar-bi150-vllm-tokenizer-fix:0.8.3 .
```
使用时仅替换原 BI-150 镜像名,`vllm serve` 参数保持不变。以下命令中的 `<this-image>` 表示打好补丁的镜像。
## 启动
```bash
docker run -dit \
--name iluvatar_sut_submit_325811 \
-p 38047:8000 \
--privileged \
-v /lib/modules:/lib/modules \
-v /dev:/dev \
-v /usr/src:/usr/src \
-v /path/to/model:/model \
-e CUDA_VISIBLE_DEVICES=0 \
--entrypoint vllm \
<this-image> \
serve /model \
--port 8000 \
--served-model-name llm \
--max-model-len 2048 \
--enforce-eager \
--trust-remote-code \
-tp 1
```