Files
vLLM-Nvidia-A100-opt/README.md
4paradigm 43a9d6fe07
All checks were successful
Docker Build and Push / docker (push) Successful in 1m4s
fix tokenizer
2026-07-23 15:20:18 +08:00

53 lines
1.8 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.

# Nvidia-A100 Tokenizer 配置修复补丁
基于 Nvidia-A100 vLLM v0.11.0 镜像,修复以下两类 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 nvidia-a100-vllm-tokenizer-fix:v0.11.0 .
```
使用时仅替换原 Nvidia-A100 镜像名,`vllm serve` 参数保持不变。以下命令中的 `<this-image>` 表示打好补丁的镜像。
## 启动
```bash
docker run -dit \
--name nvidia_sut_submit_<task_id> \
-p <host_port>:8000 \
--gpus all \
-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
```