ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported.

用户在使用 vLLM 启动 API 服务(通过 Docker 命令 vllm/vllm-openai:qwen3_5 镜像)部署通过 LLaMA-Factory 或 SWIFT 微调后的 Qwen3.5 模型时触发此错误。无论微调方式是 LoRA(后合并)还是全参微调,均会复现。服务启动参数中包含

ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported.

ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported.

快速结论:该报错通常出现在使用 vLLM 部署经过 LLaMA-Factory 或 SWIFT 等框架微调后的 Qwen3.5 模型时。优先排查微调后的模型目录中的 tokenizer_config.json 文件是否包含了异常的 tokenizers_backend 配置,尝试使用基座模型的原始 tokenizer_config.json 文件替换。

问题场景

用户在使用 vLLM 启动 API 服务(通过 Docker 命令 vllm/vllm-openai:qwen3_5 镜像)部署通过 LLaMA-Factory 或 SWIFT 微调后的 Qwen3.5 模型时触发此错误。无论微调方式是 LoRA(后合并)还是全参微调,均会复现。服务启动参数中包含 --trust-remote-code

报错原文

ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported.

原因分析

最可能的原因是微调框架(如 LLaMA-Factory 或 SWIFT)在保存模型时,修改了 tokenizer_config.json 文件,在其中添加或修改了一个名为 tokenizers_backend 的字段。vLLM 在加载该配置文件时,尝试根据这个字段的值去实例化一个不存在的 TokenizersBackend 类,从而抛出 ValueError。使用基座模型原始的 tokenizer_config.json 替换可绕过此问题,但可能引发后续的其他错误。

环境排查

  • vLLM 版本:用户反馈中涉及的版本为 0.16.1rc1.dev124+g92f5d0f07,但该问题可能不限于特定版本。
  • 微调框架:LLaMA-Factory 或 SWIFT。
  • 基础模型:Qwen3.5 系列模型(包括 MoE 架构,如 Qwen3_5MoeForConditionalGeneration)。
  • 关键文件:微调后模型目录下的 tokenizer_config.json

解决步骤

  1. 备份微调后的 tokenizer_config.json: 进入微调后的模型目录,将 tokenizer_config.json 文件备份。
  2. 获取基座模型的配置: 从原始 Qwen3.5 基座模型权重目录中,复制一份 tokenizer_config.json 文件。
  3. 替换文件: 将复制的基座模型 tokenizer_config.json 覆盖到微调后的模型目录中。
  4. 重新启动服务: 使用原来的 Docker 命令重新启动 vLLM 服务。

注意:根据用户反馈,这一替换操作可能导致后续出现 KeyError: 'qwen3_5_moe' 错误,该错误表明微调后的 config.json 中的 model_type 字段(如 qwen3_5_moe)可能未被当前版本的 transformers 或 vLLM 识别。这是另一个独立问题,可能需要升级 vLLM 或等待框架兼容。

验证方法

执行上述替换步骤后,重新运行 vLLM 服务启动命令。观察终端日志,若 ValueError: Tokenizer class TokenizersBackend does not exist or is not currently imported. 错误不再出现,且服务能成功加载模型并启动,则说明该问题已解决。

参考来源

vllm-project/vllm #35989

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 14576

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注