跳到內容

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,
        # tensor_parallel_size=... # for distributed inference
)

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

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