vLLM部署推理及相关重要参数

部署示例代码

from vllm import LLM, SamplingParams

prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

llm = LLM(model="qwen/Qwen-7B-Chat", revision="v1.1.8", trust_remote_code=True)

outputs = llm.generate(prompts, sampling_params)

for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

SamplingParams()重要传参

  • temperature:Temperature 参数是文本生成模型中用于控制生成文本的随机性和创造性的一个重要的超参数。Temperature参数通常设置为 0.1 到 1.0 之间。
  • top_k:模型预测的前k个最可能的下一个词。
  • max_tokens:模型生成的最大长度。
  • stop:生成模型停止生成的符号。

LLM()中重要传参

  • model:LLM模型路径。
  • tensor_parallel_size:并行处理的大小。
  • gpu_memory_utilization:默认为0.9, cpu_swap_space默认4个G。若gpu_memory_utilization参数过小(分配的内存大小低于模型使用内存)或者过大(接近1.0)时,代码会崩溃。
  • request_rate:请求速率

参考文献

https://github.com/vllm-project/vllm
https://docs.vllm.ai/en/latest/index.html

你可能感兴趣的:(大语言模型,自然语言处理,人工智能,LLM,大模型,NLP,vLLM,部署,加速推理)