跳到內容

註冊模型

vLLM 依賴模型登錄檔來確定如何執行每個模型。預註冊架構的列表可以在此處找到。

如果您的模型不在此列表中,則必須將其註冊到 vLLM。本頁面提供了詳細的操作說明。

內建模型

要將模型直接新增到 vLLM 庫,請首先分叉我們的 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 介面。欲瞭解更多資訊,請點選此處