不使用 Docker 构建 Triton 服务器并在 Google Colab 平台上部署 HuggingFace 模型

news2024/10/6 12:19:27

Build Triton server without docker and deploy HuggingFace models on Google Colab platform

  • Environment
  • Building Triton server
  • Deploying HuggingFace models
  • 客户端
  • 推荐阅读
  • 参考

Environment

根据Triton 环境对应表 ,Colab 环境缺少 tensorrt-8.6.1,cudnn9-cuda-12,triton-server 版本应该选择 r23.10。
在这里插入图片描述

apt update && apt install -y --no-install-recommends \
    ca-certificates autoconf automake build-essential docker.io git libre2-dev libssl-dev libtool libboost-dev \
    libcurl4-openssl-dev libb64-dev patchelf python3-dev python3-pip python3-setuptools rapidjson-dev scons \
    software-properties-common unzip wget zlib1g-dev libarchive-dev pkg-config uuid-dev libnuma-dev curl \
    libboost-all-dev datacenter-gpu-manager cudnn9-cuda-12

pip3 install --upgrade pip && pip3 install --upgrade wheel setuptools tritonclient[all] diffusers>=0.27.0 transformers accelerate safetensors optimum["onnxruntime"]

upgrade boost

wget https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0.tar.gz
tar -zxvf boost_1_84_0.tar.gz 
cd boost_1_84_0
chmod -R 777 .
./bootstrap.sh --with-libraries=all --with-toolset=gcc
./b2 -j20 toolset=gcc
./b2 install 

install libarchive

wget https://github.com/libarchive/libarchive/releases/download/v3.6.2/libarchive-3.6.2.tar.gz
tar -zxvf libarchive-3.6.2.tar.gz 
cd libarchive-3.6.2
./configure
make
sudo make install

install tensorrt-8.6.1

# 方法一
wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/tars/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz
tar -xvf TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz 
sudo mv TensorRT-8.6.1.6/ /usr/local/
vim ~/.bashrc 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/TensorRT-8.6.1.6/lib
source ~/.bashrc 

# 方法二
wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/local_repos/nv-tensorrt-local-repo-ubuntu2204-8.6.1-cuda-12.0_1.0-1_amd64.deb
sudo cp /var/nv-tensorrt-local-repo-ubuntu2204-8.6.1-cuda-12.0/nv-tensorrt-local-42B2FC56-keyring.gpg /usr/share/keyrings/
sudo dpkg -i nv-tensorrt-local-repo-ubuntu2204-8.6.1-cuda-12.0_1.0-1_amd64.deb

Building Triton server

编译 Triton

git clone -b r23.10 https://github.com/triton-inference-server/server.git

# enable-all 编译失败了,原因可能为编译某个 backend 导致的,解决方法未知
./build.py -v --no-container-build --build-dir=`pwd`/build --enable-all

# 自定义参数且只编译 python 后端,成功
./build.py -v --no-container-build --build-dir=$(pwd)/build --enable-logging --enable-stats --enable-tracing --enable-gpu --endpoint http --endpoint grpc  --backend python --extra-core-cmake-arg j=0

设置软链接

ln -s /content/server/build/opt/tritonserver /opt/tritonserver

Deploying HuggingFace models

克隆 python_backend,因为我们要使用 python_backend 中的 triton_python_backend_utils

git clone https://github.com/triton-inference-server/python_backend.git -b r23.02
cd python_backend

配置模型库
部署非常能打的文生图大模型 playground-v2.5

mkdir -p models/playground-v2.5/1/
# 配置文件
touch models/playground-v2.5/config.pbtxt
# 模型文件
touch models/playground-v2.5/1/model.py
# 客户端文件
touch models/playground-v2.5/client.py

config.pbtxt

name: "playground-v2.5"
backend: "python"
max_batch_size: 0
input [
  {
    name: "prompt"
    data_type: TYPE_STRING
    dims: [-1, -1]
  }
]
output [
  {
    name: "generated_image"
    data_type: TYPE_FP32
    dims: [-1, -1, -1]
  }
]
instance_group [
  {
    kind: KIND_GPU
  }
]

model.py

import numpy as np
import triton_python_backend_utils as pb_utils
from transformers import ViTImageProcessor, ViTModel
from diffusers import DiffusionPipeline
import torch
import time
import os
import shutil
import json
import numpy as np

class TritonPythonModel:
    def initialize(self, args):
        self.model = DiffusionPipeline.from_pretrained(
            "playgroundai/playground-v2.5-1024px-aesthetic",
            torch_dtype=torch.float16,
            variant="fp16"
        ).to("cuda")

    def execute(self, requests):
        responses = []
        for request in requests:
            inp = pb_utils.get_input_tensor_by_name(request, "prompt")
            prompt = inp.as_numpy()[0][0].decode()
            print(prompt)
            # prompt = "sailing ship in storm by Leonardo da Vinci, detailed, 8k"
            image = self.model(prompt=prompt, num_inference_steps=50, guidance_scale=3).images[0]
            pixel_values = np.asarray(image)
            inference_response = pb_utils.InferenceResponse(
                output_tensors=[
                    pb_utils.Tensor(
                        "generated_image",
                        pixel_values,
                    )
                ]
            )
            responses.append(inference_response)
        return responses

启动 Triton 服务

/opt/tritonserver/bin/tritonserver --model-repository /content/python_backend/models

在这里插入图片描述

client.py

import time
import os
import numpy as np
import tritonclient.http as httpclient

from PIL import Image
from tritonclient.utils import *

IMAGES_SAVE_DIR = "/content/images/"

def text2image(prompt):
	if not os.path.exists(IMAGES_SAVE_DIR):
	    os.makedirs(IMAGES_SAVE_DIR)
	    
	client = httpclient.InferenceServerClient(url="localhost:8000")
	text_obj = np.array([prompt], dtype="object").reshape((-1, 1))
	
	input_text = httpclient.InferInput(
	    "prompt", text_obj.shape, np_to_triton_dtype(text_obj.dtype)
	)
	input_text.set_data_from_numpy(text_obj)
	
	output_img = httpclient.InferRequestedOutput("generated_image")
	timestamp = str(int(time.time()))
	filename = timestamp + ".png"
	output_path = IMAGES_SAVE_DIR + filename
	
	query_response = client.infer(
	    model_name="playground-v2.5", inputs=[input_text], outputs=[output_img]
	)
	image = query_response.as_numpy("generated_image")
	im = Image.fromarray(np.squeeze(image.astype(np.uint8)))
	im.save(output_path)
	return output_path

if __name__ == '__main__':
	start = time.time()
	prompt = "A beautiful Asian girl is sitting in a rocking chair in a beautiful garden, holding a cute kitten, admiring the beautiful scenery, with willow trees and a river."
    image_path = text2image(prompt)
    end = time.time()
	print("Time taken:", end - start)

客户端

python client.py
在这里插入图片描述
更多示例
Space ship.
在这里插入图片描述
The West Lake
在这里插入图片描述

推荐阅读

  • 一. Triton Server Python 后端性能优化

参考

  • Triton Server - Conceptual Guides

  • Building Triton Without Docker

  • Deploying HuggingFace models

  • Triton 支持的数据类型汇总

  • Deploy Stable Diffusion 不支持高并发

  • Optimize and deploy model on Nvidia Triton server

  • 深度学习怎么模型部署? - 李稀敏的回答 - 知乎

  • How to Run a Stable Diffusion Server on Google Cloud Platform (GCP)

  • 深度学习模型如何部署?部署可以试试triton~

  • TensorRT 官网

  • Tensorrt的安装、模型转换、推理demo编写

  • datacenter-gpu-manager

  • Export huggingface SDXL model to ONNX

  • Replicate.com 公开部署的模型

  • Replicate Playgroundv2.5 推理接口源代码

  • stable-diffusion-webui

  • Error: install include <NvCaffeParser.h>

  • ubuntu22.04 cuda cudnn tensorRT安装

  • NVIDIA Deep Learning TensorRT Documentation

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1579355.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2024/4/5—力扣—搜索旋转排序数组

代码实现&#xff1a; 思路&#xff1a;二分法 int search(int *nums, int numsSize, int target) {int l 0, r numsSize - 1;while (l < r) { // 左闭右闭int mid (l r) >> 1;if (nums[mid] target) {return mid;}if (nums[l] < nums[mid]) { // 说明l - mid…

ClickHouse 介绍

前言 一个通用系统意味着更广泛的适用性&#xff0c;但通用的另一种解释是平庸&#xff0c;因为它无法在所有场景内都做到极致。 ClickHouse 在没有像三驾马车这样的指导性论文的背景下&#xff0c;通过针对特定场景的极致优化&#xff0c;获得闪电般的查询性能。 ClickHous…

为说阿拉伯语的国家进行游戏本地化

阿拉伯语是由超过4亿人使用的语言&#xff0c;并且是二十多个国家的官方语言。进入这些国家的市场并非易事——虽然他们共享一种通用语言&#xff0c;但每个国家都有自己独特的文化&#xff0c;有自己的禁忌和对审查的处理方式。这就是为什么视频游戏公司长期以来都远离阿拉伯语…

C语言学习初级阶段(数据)——scanf读取标准输入

文章目录 一、scanf函数的原理1.1、自己理解1.2、王道解释1.3、注意 一、scanf函数的原理 输入和输出是通过标准函数库实现的&#xff0c;C语言通过scanf函数读取键盘输入&#xff0c;键盘输入又称标准输入。当scanf函数读取标准输入时&#xff0c;如果还没有输入任何内容&…

如何提升产品用户体验?4个工具+6张案例,让你快速吃透!

在数字时代的浪潮中&#xff0c;产品用户体验早已不再是简单的“好用”或“不好用”的评判标准&#xff0c;它不仅仅是功能的堆砌&#xff0c;更是情感的连接、智慧的体现。在这个竞争激烈的市场中&#xff0c;只有那些能够深入理解用户需求、精准把握用户心理的产品&#xff0…

ES6中 Promise的详细讲解

文章目录 一、介绍状态特点流程 二、用法实例方法then()catchfinally() 构造函数方法all()race()allSettled()resolve()reject() 三、使用场景# 参考文献 一、介绍 Promise&#xff0c;译为承诺&#xff0c;是异步编程的一种解决方案&#xff0c;比传统的解决方案&#xff08;…

(学习日记)2024.04.09:UCOSIII第三十七节:事件函数接口

写在前面&#xff1a; 由于时间的不足与学习的碎片化&#xff0c;写博客变得有些奢侈。 但是对于记录学习&#xff08;忘了以后能快速复习&#xff09;的渴望一天天变得强烈。 既然如此 不如以天为单位&#xff0c;以时间为顺序&#xff0c;仅仅将博客当做一个知识学习的目录&a…

uniapp请求后端接口

新建文件夹utils const request (config) > {// 拼接完整的接口路径config.url http://mm.test.cn config.url;//这里拼接的是访问后端接口的地址&#xff0c;http://mm.test.cn/prod-api/testconsole.log(config.url)//判断是都携带参数if(!config.data){config.data …

比派科技(BananaPI) 和 Qbee 达成战略合作伙伴关系,共同推动物联网技术发展

比派科技&#xff08;Banana PI&#xff09;&#xff08;https://banana-pi.org/&#xff09;和Qbee&#xff08;https://qbee.io/&#xff09;很高兴地宣布建立战略合作伙伴关系&#xff0c;旨在推动物联网&#xff08;IoT&#xff09;技术领域的创新和发展。 作为在物联网领…

[官方推荐]通义灵码做活动,送礼品,快来薅羊毛!!!

你的编辑器装上智能ai编辑了吗&#xff0c;的确挺好用的。 最近阿里云AI编码搞活动&#xff0c;可以免费体验并且还可以抽盲盒。有日历、马克杯、代金券、等等其他数码产品。 大多数都是日历。 点击链接参与「通义灵码 体验 AI 编码&#xff0c;开 AI 盲盒」 https://develope…

代码随想录阅读笔记-二叉树【总结】

二叉树的理论基础 代码随想录 (programmercarl.com)&#xff1a;二叉树的种类、存储方式、遍历方式、定义方式 二叉树的遍历方式 深度优先遍历 代码随想录阅读笔记-二叉树【递归遍历】-CSDN博客&#xff1a;递归三部曲初次亮相代码随想录阅读笔记-二叉树【迭代遍历】-CSDN博…

护眼灯值不值得买?入手不亏护眼灯十大品牌推荐

如今&#xff0c;我们不难发现越来越多的人早早地戴上了眼镜。这背后&#xff0c;或许是频繁接触电子产品&#xff0c;或许是长时间的学习&#xff0c;又或许是长时间处于不健康的光线环境。无论原因如何&#xff0c;我们都深知营造良好的光线环境对于保护视力至关重要。市面上…

Maven POM元素解析

这是对Maven中使用的Maven项目描述符的引用。 <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/…

SQL语法 之 数据库多表查询

对这篇文章的延申 Mysql-全外连接-Union和Union ALL的辨析及练习-CSDN博客 其他SQL系列文章&#xff1a; MySQL《一》-数据库基础_宋红康主要课程-CSDN博客 MySQL《二》-基本查询语句&#xff08;Select)-CSDN博客 Mysql - 定点型(DECIMAL)的使用详解及练习-CSDN博客 MySQ…

RuleEngine规则引擎底层改造AviatorScript 之公式规则

前情提要&#xff0c;看上一个文章&#xff0c;具体要实现的效果就是 当然上来的问题就是前端的问题&#xff0c;这个框首先他们用的是富文本&#xff0c;富文本传到后台的结果是前端脚本&#xff0c;带着h5的标签&#xff0c;后面改成了这个&#xff0c;当时这个东西其实和后…

【Linux】TCP编程{socket/listen/accept/telnet/connect/send}

文章目录 1.TCP接口1.1socket文档 1.2listen拓&#xff1a;端口号8080 1.3accept拓&#xff1a;今天全局函数 1.4读写接口1.5telnet1.一个客户端2.两个客户端 1.6ulimit -a1.7常识回顾1.8connect1.9拓&#xff1a;客户端的ip和地址什么时候被分配&#xff1f;1.10拓&#xff1a…

【接口自动化】参数化替换

在做接口测试时&#xff0c;除了测单个接口&#xff0c;还需要进行业务链路间的接口测试 比如[注册-登陆]需要token鉴权的业务流 当我们用使用postman/jmeter等工具时&#xff0c;将注册接口的一些响应信息提取出来&#xff0c;放到登陆接口的请求中&#xff0c;来完成某个业务…

【Redis】Redis群集的三种模式(主从、哨兵、群集)

redis群集有三种模式&#xff0c;分别是主从同步/复制、哨兵模式、Cluster&#xff0c;下面会讲解一下三种模式的工作方式&#xff0c;以及如何搭建cluster群集 ●主从复制&#xff1a;主从复制是高可用Redis的基础&#xff0c;哨兵和集群都是在主从复制基础上实现高可用的。主…

Qt案例 通过调用Setupapi.h库实现对设备管理器中设备默认驱动的备份

参考腾讯电脑管家-软件市场中的驱动备份专家写的一个驱动备份软件案例&#xff0c;学习Setupapi.h库中的函数使用.通过Setupapi.h库读取设备管理器中安装的设备获取安装的驱动列表&#xff0c;通过bit7z库备份驱动目录下的所有文件. 目录导读 实现效果相关内容示例获取SP_DRVIN…

DevOps已死?2024年的DevOps将如何发展

随着我们进入2024年&#xff0c;DevOps也发生了变化。新兴的技术、变化的需求和发展的方法正在重新定义有效实施DevOps实践。 IDC预测显示&#xff0c;未来五年&#xff0c;支持DevOps实践的产品市场继续保持健康且快速增长&#xff0c;2022年-2027年的复合年增长率&#xff0…