跳至内容

注册模型

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接口。了解更多信息请点击here

优云智算