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

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-12pip3 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_STRINGdims: [-1, -1]}
]
output [{name: "generated_image"data_type: TYPE_FP32dims: [-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 npclass 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 httpclientfrom 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 + filenamequery_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_pathif __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.mzph.cn/news/801447.shtml

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

相关文章

ARM的CI-700和Arteris的NoC对比

ARM的CI-700和Arteris的NoC是两种不同的片上网络互连技术&#xff0c;它们都旨在提高SoC&#xff08;System on Chip&#xff09;的性能和效率&#xff0c;但具有不同的设计理念和应用场景。以下是对两者的详细对比&#xff1a; ARM的CI-700 AMBA 5 CHI互连&#xff1a;CI-70…

如何客观评价5G的现状?

前几天&#xff0c;在知乎上看到一个帖子&#xff0c;热度挺高&#xff1a; 看了一下帖子的回答&#xff0c;基本上都在骂5G。 作为通信行业从业者&#xff0c;我说说我自己的看法。大家姑且听听&#xff0c;一起交流一下。 我们目前所处的这个时代&#xff0c;有一个很大的特点…

【嵌入式Linux】第二部分 - 玩转驱动

本部分是嵌入式Linux教程的第二部分&#xff0c;驱动开发基础 这个部分的主要目的是带大家熟悉基础的驱动开发入门。 ARM嵌入式Linux学习路线 C语言部分&#xff08;核心&#xff09; C语言open()函数&#xff1a;打开文件函数 POSIX标准是什么&#xff1f; LinuxC语言使用…

VSCode 快捷键的使用

快捷键大全 通用 CtrlShiftP, F1 显示命令面板 CtrlP 快速打开&#xff0c;转到文件… CtrlShiftN 新窗口/实例 CtrlShiftW 关闭窗口/实例 Ctrl, 用户设置 CtrlK CtrlS 键盘快捷方式 基本编辑 CtrlX 剪切行&#xff08;空选择&#xff09; CtrlC 复制行&#xff08;空选择&…

Leetcode面试经典150_Q13罗马数字转整数

题目&#xff1a; 罗马数字包含以下七种字符: I&#xff0c; V&#xff0c; X&#xff0c; L&#xff0c;C&#xff0c;D 和 M。 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M …

使用Node.js模拟执行JavaScript

使用Node.js模拟执行JavaScript 模拟执行的是JavaScript&#xff0c;而且依赖的是Node.js&#xff0c;为什么不直接用Node.js来尝试JavaScript的执行呢&#xff1f;其实是完全可行的。 准备工作 确保已经正确安装好了Node.js。安装流程可以在小蜜蜂AI网站获取。 模拟执行 …

CV2不同图像插值方式的区别

最近邻插值&#xff08;Nearest-neighbor interpolation&#xff0c;cv2.INTER_NEAREST&#xff09;&#xff1a; 基于最近的像素值进行插值。简单快速&#xff0c;但可能会产生锯齿状的边缘。通常用于图像放大时速度要求较高的情况。 双线性插值&#xff08;Bilinear interpol…

Day17_学点JavaEE_转发、重定向、Get、POST、乱码问题总结

1 转发 转发&#xff1a;一般查询了数据之后&#xff0c;转发到一个jsp页面进行展示 req.setAttribute("list", list); req.getRequestDispatcher("student_list.jsp").forward(req, resp);2 重定向 重定向&#xff1a;一般添加、删除、修改之后重定向到…

新能源汽车动力电池散热技术

为了进一步解决能源危机问题&#xff0c;我国大力提倡新能源的开发&#xff0c;其中以电力驱动的新型能源汽车&#xff0c;是我国大规模进入新能源应用的关键领域。新能源汽车是指使用非化石能源&#xff08;如电力、太阳能等&#xff09;作为动力源的汽车&#xff0c;其具有低…

Flutter如何集成到已有iOS工程上

大家好&#xff0c;我是咕噜铁蛋&#xff0c;今天我将和大家分享一个实用的技术教程——如何将Flutter集成到已有的iOS工程中。Flutter是Google推出的一款开源的移动UI框架&#xff0c;它允许开发者使用Dart语言来开发高性能、美观的原生应用&#xff0c;并支持iOS和Android两大…

Walmart.com DSV XML对接需求

此前的文章Walmart.com DSV EDI对接需求中&#xff0c;为大家介绍了如果选择传输EDI文件需要做的准备与需求。本文将为大家介绍Walmart.com 与DSV&#xff08;Drop Ship Vender&#xff09;之间传输XML文件的需求。与EDI相比&#xff0c;XML文件的处理难度相对低一些。无论企业…

Linux文件和目录管理及文本搜索命令find grep

在Linux操作系统中&#xff0c;“find” 和 “grep” 是两个非常常用的命令&#xff0c;它们在文件和目录管理以及文本搜索方面提供了强大的功能。 首先&#xff0c;让我们来看一下"find"命令。“find"命令用于在文件系统中搜索文件和目录。它可以根据指定的条…

Kafka生产者在Java中的应用

加油&#xff0c;新时代打工人&#xff01; 1、导入Maven Kafka POM依赖 <repositories><repository><id>central</id><url>http://maven.aliyun.com/nexus/content/groups/public//</url><releases><enabled>true</enabl…

stm32GPO的相关操作

GPIO的使用 1.GPIO八种工作模式1.1 上拉输入1.2 下拉输入1.3 浮空输入1.4 模拟输入1.5 推挽输出1.6 开漏输出1.7 复用推挽输出1.8 复用开漏输出 2.相关寄存器2.1 寄存器配置IO 3.相关库函数 1.GPIO八种工作模式 保护二极管的作用&#xff1a;用来保护IO&#xff0c;一般情况IO的…

【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…

【python读取含有url图片链接的txt文档-3】

如果你需要一个更复杂的解决方案来进行图像数据增强&#xff0c;那么你可以考虑使用imgaug&#xff08;Image Augmentation&#xff09;库。imgaug是一个强大且灵活的图像增强库&#xff0c;它提供了大量的预定义增强方法&#xff0c;并且允许你自定义自己的增强策略。 以下是…

设计模式之命令模式讲解

概念&#xff1a;命令模式&#xff08;Command Pattern&#xff09;又称行动&#xff08;Action&#xff09;模式或交易&#xff08;Transaction&#xff09;模式。将一个请求封装成一个对象&#xff0c;从而让你使用不同的请求把客户端参数化&#xff0c;对请求排队或者记录请…

数据结构:冒泡排序,快速排序,插入排序

冒泡排序&#xff0c;每次只排一个&#xff0c;像鱼吐泡泡一样&#xff0c;从数组最后开始两两交换&#xff0c;一次只找到一个当前最小的&#xff0c;放到第一个,第二个...位置. T(n)O(n的平方&#xff09;,有序O(n) S&#xff08;n&#xff09;O&#xff08;1&#xff09; #i…

使用 Spring Boot 和 Maven 引入本地 Jar 包

背景 在 Java 开发中&#xff0c;有时候我们需要引入本地的 Jar 包到项目中&#xff0c;以满足特定的功能需求。本文将以引入 id 生成器为例&#xff0c;介绍如何在 Spring Boot 项目中使用 Maven 管理本地 Jar 包。 准备工作 创建 libs 目录&#xff1a; 在项目根目录下创建…

Flink KafkaSource 启用动态分区检查

Flink KafkaSource 启用动态分区检查 在不同版本的Flink中&#xff0c;动态分区检查&#xff08;Dynamic Partitions Check&#xff09;启用方式可能会有一些变化。以下是不同版本变化的情况总结&#xff1a; 1. Flink版本< 1.11 分区发现 Flink Kafka Consumer 支持发现动…