Untitled

LLM推理有很多框架,各有其特点,下面分别介绍一下表中七个框架的关键点:

  1. vLLM[1]:适用于大批量Prompt输入,并对推理速度要求高的场景;
  2. Text generation inference[2]:依赖HuggingFace模型,并且不需要为核心模型增加多个adapter的场景;
  3. CTranslate2[3]:可在CPU上进行推理;
  4. OpenLLM[4]:为核心模型添加adapter并使用HuggingFace Agents,尤其是不完全依赖PyTorch;
  5. Ray Serve[5]:稳定的Pipeline和灵活的部署,它最适合更成熟的项目;
  6. MLC LLM[6]:可在客户端(边缘计算)(例如,在Android或iPhone平台上)本地部署LLM;
  7. DeepSpeed-MII[7]:使用DeepSpeed库来部署LLM;

下面我们在内存容量为40GB的A100 GPU上,并且使用LLaMA-1 13b模型(因为列表中的所有库都支持它)进行七个部署框架的对比。

一、vLLM

Untitled

vLLM的吞吐量比HuggingFace Transformers(HF)高14x-24倍,比HuggingFace Text Generation Inference(TGI)高2.2x-2.5倍。

离线批量推理


# pip install vllm
from vllm import LLM, SamplingParams

prompts = [
    "Funniest joke ever:",
    "The capital of France is",
    "The future of AI is",
]
sampling_params = SamplingParams(temperature=0.95, top_p=0.95, max_tokens=200)
llm = LLM(model="huggyllama/llama-13b")
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}")

API Server


# Start the server:
python -m vllm.entrypoints.api_server --env MODEL_NAME=huggyllama/llama-13b

# Query the model in shell:
curl <http://localhost:8000/generate> \
    -d '{
        "prompt": "Funniest joke ever:",
        "n": 1,
        "temperature": 0.95,
        "max_tokens": 200
    }'

功能: