跳到內容

LangChain

vLLM 也可透過 LangChain 使用。

安裝 LangChain,請執行

pip install langchain langchain_community -q

要在單個或多個 GPU 上執行推理,請使用 `langchain` 中的 `VLLM` 類。

程式碼
from langchain_community.llms import VLLM

llm = VLLM(
    model="mosaicml/mpt-7b",
    trust_remote_code=True,  # mandatory for hf models
    max_new_tokens=128,
    top_k=10,
    top_p=0.95,
    temperature=0.8,
    # for distributed inference
    # tensor_parallel_size=...,
)

print(llm("What is the capital of France ?"))

有關更多詳細資訊,請參閱此 教程