GGUF

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 假设 huggingface 可以将元数据转换为配置文件。如果 huggingface 不支持您的模型,您可以手动创建配置并将其作为 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}")