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 耗时且不稳定,特别是对于一些词汇量很大的模型。
GGUF 假定 Hugging Face 可以将元数据转换为配置文件。如果 Hugging Face 不支持您的模型,您可以手动创建一个配置并将其作为 hf-config-path 传入
# If you model is not supported by huggingface you can manually provide a huggingface compatible config path
vllm serve ./tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf \
--tokenizer TinyLlama/TinyLlama-1.1B-Chat-v1.0 \
--hf-config-path Tinyllama/TInyLlama-1.1B-Chat-v1.0
您还可以直接通过 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}")