LiteLLM + vLLM模型调用引擎架构

二、Docker 安装 vLLM

docker-compose.yml

复制代码
version: '3.7'

services:

  vllm-qwen:
    image: vllm/vllm-openai:latest
    container_name: vllm-qwen
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
    volumes:
      - ./models:/models
    command: >
      --model /models/qwen/Qwen2.5-0.5B-Instruct
      --host 0.0.0.0
      --port 8000
      --gpu-memory-utilization 0.5
      --max-model-len 1024
    ports:
      - "8000:8000"

  litellm:
    image: ghcr.io/berriai/litellm:main-latest
    container_name: litellm
    volumes:
      - ./config.yaml:/app/config.yaml
    command: --config /app/config.yaml
    ports:
      - "4000:4000"
    depends_on:
      - vllm-qwen

把模型放到models

LiteLLM 配置config.yaml

复制代码
model_list:
  - model_name: qwen
    litellm_params:
      model: openai//models/qwen/Qwen2.5-0.5B-Instruct  # 使用 vLLM 返回的完整模型 ID
      api_base: http://vllm-qwen:8000/v1
      api_key: none

启动服务

docker compose up -d

此过程比较慢,因为下载的比较大。

测试 vLLM

curl http://localhost:8000/v1/models

测试 LiteLLM

curl http://localhost:4000/v1/models

整体测试:

curl http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d "{\"model\":\"qwen\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}"

python代码测试:

复制代码
from openai import OpenAI

client = OpenAI(
    api_key="anything",
    base_url="http://10.61.104.181:4000/v1"
)

response = client.chat.completions.create(
    model="qwen",
    messages=[
        {"role": "user", "content": "你好,讲个笑话"}
    ]
)
 
print(response.choices[0].message.content)

增加多个模型(暂未尝试)

相关推荐
x²+(y-√³x²)²=11 天前
Linux 或者 Ubuntu 离线使用 vllm启动大模型
linux·ubuntu·vllm
HyperAI超神经2 天前
【TVM教程】理解 Relax 抽象层
人工智能·深度学习·学习·机器学习·gpu·tvm·vllm
晨欣2 天前
单卡 48GB 实测:Gemma 4 26B A4B、Gemma 4 31B、gpt-oss-20b 三模型部署与并发对比
google·openai·nvidia·vllm·llama.cpp·gpt-oss-20b·gemma4
weixin_6682 天前
在DGX-Spark上多模态模型gemma-4-31B-it vLLM部署
vllm
认真的薛薛3 天前
GPU运维:vllm启动大模型参数解析
运维·数据库·vllm
handsomestWei3 天前
KV Cache与vLLM、SGLang推理框架
vllm·推理框架·kv cache·sglang
lin_dec+4 天前
KV Cache:大模型推理加速的关键技术
nlp·transformer·vllm·大模型推理·kv cache
deephub5 天前
从零构建 Mini-vLLM:KV-Cache、动态批处理与分布式推理全流程
人工智能·python·深度学习·大语言模型·vllm
西西弗Sisyphus6 天前
大模型运行的 enforce_eager 参数
langchain·prompt·transformer·vllm·enforce_eager
诸神缄默不语6 天前
本地LLM部署工具(写给小白的LLM工具选型系列:第一篇)
llm·大规模预训练语言模型·vllm·ollama