GGUF#
警告
请注意,vLLM 中的 GGUF 支持目前仍处于高度实验性和欠优化的状态,可能与其他功能不兼容。目前,您可以使用 GGUF 作为减少内存占用的一种方式。如果您遇到任何问题,请向 vLLM 团队报告。
警告
目前,vllm 仅支持加载单文件 GGUF 模型。如果您有多文件 GGUF 模型,您可以使用 gguf-split 工具将它们合并为单文件模型。
要使用 vLLM 运行 GGUF 模型,您可以从 TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF 下载并使用本地 GGUF 模型,并使用以下命令
wget https://hugging-face.cn/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf
# We recommend using the tokenizer from base model to avoid long-time and buggy tokenizer conversion.
vllm serve ./tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf --tokenizer TinyLlama/TinyLlama-1.1B-Chat-v1.0
您还可以添加 --tensor-parallel-size 2
以启用使用 2 个 GPU 的张量并行推理
# We recommend using the tokenizer from base model to avoid long-time and buggy tokenizer conversion.
vllm serve ./tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf --tokenizer TinyLlama/TinyLlama-1.1B-Chat-v1.0 --tensor-parallel-size 2
警告
我们建议使用来自基础模型的 tokenizer,而不是 GGUF 模型。因为从 GGUF 转换 tokenizer 非常耗时且不稳定,特别是对于某些具有大词汇量的模型。
您也可以通过 LLM 入口点直接使用 GGUF 模型
from vllm import LLM, SamplingParams
# In this script, we demonstrate how to pass input to the chat method:
conversation = [
{
"role": "system",
"content": "You are a helpful assistant"
},
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
{
"role": "user",
"content": "Write an essay about the importance of higher education.",
},
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
# Create an LLM.
llm = LLM(model="./tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf",
tokenizer="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.chat(conversation, sampling_params)
# Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")