当前位置: 首页 > news >正文

vLLM 部署 InternVL2_5

vllm 中文文档
OpenAI 兼容服务器部署参数

模型下载

模型下载的渠道很多,这里使用 modelscope 进行下载,InternVL2_5-1B首页,

  • 安装 modelscope
pip install modelscope
  • 下载模型
from modelscope import snapshot_download
model_dir = snapshot_download('OpenGVLab/InternVL2_5-1B', local_dir="xxx/OpenGVLab/InternVL2_5-1B")

服务部署与请求

OpenGVLab/InternVL2_5-1B/config.json 中给定了初始化的超参数,例如temperaturetop_ptop_k等,简单部署命令如下,默认使用 8000 端口

vllm serve OpenGVLab/InternVL2_5-1B
or
python -m vllm.entrypoints.openai.api_server --model=OpenGVLab/InternVL2_5-1B

http://127.0.0.1:8000/docs 可以看到各种路由信息

请求脚本如下

import base64
import requests
from openai import OpenAI

# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key=openai_api_key,
    base_url=openai_api_base,
)

models = client.models.list()
model = models.data[0].id


def encode_image_base64_from_url(image_url: str) -> str:
    """Encode an image retrieved from a remote url to base64 format."""

    with requests.get(image_url) as response:
        response.raise_for_status()
        result = base64.b64encode(response.content).decode('utf-8')

    return result


def image_to_base64(image_path):
    with open(image_path, "rb") as image_file:
        image_data = image_file.read()
        base64_str = base64.b64encode(image_data).decode('utf-8')
        return base64_str  # 添加MIME类型前缀[7](@ref)


def single_image_call(image_path):
    image_base64 = image_to_base64(image_path=image_path)
    chat_completion_from_base64 = client.chat.completions.create(
        messages=[{
            "role":
                "user",
            "content": [
                {
                    "type": "text",
                    "text": "What’s in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{image_base64}"
                    },
                },
            ],
        }],
        model=model,
        max_tokens=8192,
        top_p=0.9,
        temperature=0.0,
    )
    return chat_completion_from_base64.choices[0].message.content


total_result = []
for i in range(20):
    result = single_image_call("demo.jpg")
    total_result.append(result)

# 验证多次推理结果是否相同
if len(set(total_result)) == 1:
    print(True)
else:
    print(False)
  • 请求脚本使用 temperature=0.0 保证每次推理结果相同
  • vllm 服务刚启动了,前几个请求始终会出现差异,可能是 bug
  • –trust-remote-code 加载用户自己训练的模型,需要该参数
  • –port 8765 指定端口号
  • –tensor-parallel-size 张量并行数,部署服务需要的显卡数量
  • –seed 42 指定随机种子,使用 temperature=0.0,无需该参数也能保证每次推理结果相同

vLLM 示例命令

vllm serve xxx/checkpoint-yyy --port 8567 --trust-remote-code --max-num-batched-tokens 8192 --seed 42 --tensor-parallel-size 8
http://www.dtcms.com/a/99743.html

相关文章:

  • Gogs 精简备份与恢复方案(仅SQLite数据库和配置)
  • 逻辑回归(Logistic Regression)模型的概率预测函数
  • Gateway实战(一)、网关基本了解、配置路由案例实操
  • YOLOv8环境配置及依赖安装过程记录
  • 爬虫工程师分享自动批量化获取商品评论数据的方法有哪些?
  • Linux中CP到一半不小心kill了能恢复吗?
  • SAP SD学习笔记36 - BackOrder(延期交货订单处理)
  • Stable Diffusion太慢?国内Midjourney平替方案—商用合规部署
  • AI Agent开发大全第十四课-零售智能导购智能体的RAG开发理论部分
  • 从分布式系统架构看LPL饭圈生态:开发者视角下的博弈平衡与演化逻辑
  • 【vue】聊一聊拖拽改变DOM大小的实现
  • Redis场景问题2:缓存击穿
  • VMware笔记之windows的vmware17pro中的ubuntu22.04调整系统空间大小
  • C#里实现C#脚本单步执行的信息提示
  • 算法 之 求解有向图和无向图的环的长度
  • CSS学习笔记4——盒子模型
  • IO模型之于并发编程模型、并发模型之于架构模式
  • 破界·共生:生成式人工智能(GAI)认证重构普通人的AI进化图谱
  • SpringCould微服务架构之Docker(6)
  • 【C#】C#字符串拼接的6种方式及其性能分析对比
  • Axure项目实战:智慧运输平台后台管理端-货主管理(中继器)
  • 21 python __name__ 与 __main__
  • Java中的String类
  • 智能巡检机器人:2025年企业安全运维的“数字哨兵“
  • Vue 3 中 slot插槽的使用方法
  • 最大子序和 买股票的最佳时机|| 跳跃游戏
  • 【计算机网络】深入解析TCP/IP参考模型:从四层架构到数据封装,全面对比OSI
  • 面经-项目
  • 革新测试管理 2.0丨Storm UTP统一测试管理平台智能化升级与全流程优化
  • HCIP之VRRP