跳到内容

将模型注册到 vLLM

vLLM 依赖于模型注册表来确定如何运行每个模型。预注册的架构列表可以在这里找到。

如果您的模型不在列表中,则必须将其注册到 vLLM。本页提供了详细的操作说明。

内置模型

要直接将模型添加到 vLLM 库中,请先 Fork 我们的 GitHub 仓库,然后从源代码构建。这将使您能够修改代码库并测试您的模型。

实现模型后(参见教程),将其放入 vllm/model_executor/models 目录。然后,将您的模型类添加到 vllm/model_executor/models/registry.py 中的 _VLLM_MODELS,以便在导入 vLLM 时自动注册。最后,更新我们的支持模型列表来宣传您的模型!

警告

各部分中的模型列表应按字母顺序维护。

外部模型

您可以使用插件加载外部模型,而无需修改 vLLM 代码库。

要注册模型,请使用以下代码

# The entrypoint of your plugin
def register():
    from vllm import ModelRegistry
    from your_code import YourModelForCausalLM

    ModelRegistry.register_model("YourModelForCausalLM", YourModelForCausalLM)

如果您的模型导入了初始化 CUDA 的模块,请考虑延迟导入,以避免出现诸如 RuntimeError: Cannot re-initialize CUDA in forked subprocess 的错误

# The entrypoint of your plugin
def register():
    from vllm import ModelRegistry

    ModelRegistry.register_model(
        "YourModelForCausalLM",
        "your_code:YourModelForCausalLM"
    )

警告

如果您的模型是多模态模型,请确保模型类实现了 SupportsMultiModal 接口。在此处阅读更多相关信息:这里