跳到内容

LangChain

vLLM 也可通过 LangChain 使用。

要安装 LangChain,请运行

pip install langchain langchain_community -q

要在单卡或多卡 GPU 上运行推理,请使用 langchain 中的 VLLM 类。

代码
from langchain_community.llms import VLLM

llm = VLLM(
    model="Qwen/Qwen3-4B",
    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 ?"))

有关更多详细信息,请参阅此 教程