TensorRT triton003 launch Triton SERVER (乱记)

文章介绍了如何在TritonInferenceServer中配置和使用ensemble_model,包括模型目录结构、config.pbtxt的设置以及多个模型间的输入输出映射。同时,展示了如何创建状态模型(StatefulModel)并提供了PythonHTTP客户端进行推理请求的示例代码。

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

example1

https://www.bilibili.com/video/BV1tt4y1h75i/?

Ensemble folder: https://forums.developer.nvidia.com/t/triton-ensemble-model-version/182635

├─ path/to/models
  ├── ensemble_name
  |  ├── config.pbtxt
  |  ├── 1             (empty)
  ├── MODEL1
  |  ├── config.pbtxt
  |  ├── 1
  ├── MODEL2
  |  ├── config.pbtxt
  |  ├── 1

在这里插入图片描述
在这里插入图片描述

name:"ensemble_model"
platform:"ensemble"  // 平台指定为ensemble
max_batch_size:1
input[
	{
		name:"IMAGE"
		data_type:TYPE_STRING
		dims:[1]
	}
]
output[
	{
		name:"CLASSIFICATION"
		data_type:TYPE_FP32
		dims:[1000]
	},
	{
		name:"SEGMENTATION"
		data_type:TYPE_FP32
		dims:[3,224,224]
	}
]
ensemble_scheduling{
	step[
		{
			model_name :"image_preprocess_model"
			model_version:-1
			input_map { //*_map定义从模型到ensemble_model中的名称映射
				key:"RAW_IMAGE" //key is real input/output name of "image_preprocess_model"
				value:"IMAGE" //第一个步骤的输入名称和上边name:"ensemble_model"的一致
			}
			output_map {
				key:"PREPROCESSED_OUTPUT"  //key is real input/output name of "image_preprocess_model"
				value:"preprocessed_image" // 第一步的输出在ensemble_model的新名称
			}
		},

		{
			model_name :"classification_model"
			model_version:-1
			input_map {
				key:"FORMATTED_IMAGE"
				value:"preprocessed_image"  //名称用于step之间的链接
			}
			output_map {
				key:"CLASSIFICATION_OUTPUT"
				value:"CLASSIFICATION" // 与output名称一致
			}
		},

		{
			model_name :"segmentation_model"
			model_version:-1
			input_map {
				key:"FORMATTED_IMAGE"
				value:"preprocessed_image"
			}
			output_map {
				key:"SEGMENTATION_OUTPUT"
				value:"SEGMENTATION" // 与output名称一致
			}
		}
			
	]

}

注意事项

在这里插入图片描述

example2

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
https://www.bilibili.com/video/BV1tt4y1h75i/?

request

  • https://zhuanlan.zhihu.com/p/482170985
# 安装依赖包
pip install tritonclient[all]


import gevent.ssl
import numpy as np
import tritonclient.http as httpclient


def client_init(url="localhost:8000",
                ssl=False, key_file=None, cert_file=None, ca_certs=None, insecure=False,
                verbose=False):
    """

    :param url:
    :param ssl: Enable encrypted link to the server using HTTPS
    :param key_file: File holding client private key
    :param cert_file: File holding client certificate
    :param ca_certs: File holding ca certificate
    :param insecure: Use no peer verification in SSL communications. Use with caution
    :param verbose: Enable verbose output
    :return:
    """
    if ssl:
        ssl_options = {}
        if key_file is not None:
            ssl_options['keyfile'] = key_file
        if cert_file is not None:
            ssl_options['certfile'] = cert_file
        if ca_certs is not None:
            ssl_options['ca_certs'] = ca_certs
        ssl_context_factory = None
        if insecure:
            ssl_context_factory = gevent.ssl._create_unverified_context
        triton_client = httpclient.InferenceServerClient(
            url=url,
            verbose=verbose,
            ssl=True,
            ssl_options=ssl_options,
            insecure=insecure,
            ssl_context_factory=ssl_context_factory)
    else:
        triton_client = httpclient.InferenceServerClient(
            url=url, verbose=verbose)

    return triton_client


def infer(triton_client, model_name,
          input0='INPUT0', input1='INPUT1',
          output0='OUTPUT0', output1='OUTPUT1',
          request_compression_algorithm=None,
          response_compression_algorithm=None):
    """

    :param triton_client:
    :param model_name:
    :param input0:
    :param input1:
    :param output0:
    :param output1:
    :param request_compression_algorithm: Optional HTTP compression algorithm to use for the request body on client side.
            Currently supports "deflate", "gzip" and None. By default, no compression is used.
    :param response_compression_algorithm:
    :return:
    """
    inputs = []
    outputs = []
    # batch_size=8
    # 如果batch_size超过配置文件的max_batch_size,infer则会报错
    # INPUT0、INPUT1为配置文件中的输入节点名称
    inputs.append(httpclient.InferInput(input0, [8, 2], "FP32"))
    inputs.append(httpclient.InferInput(input1, [8, 2], "INT32"))

    # Initialize the data
    # np.random.seed(2022)
    inputs[0].set_data_from_numpy(np.random.random([8, 2]).astype(np.float32), binary_data=False)
    # np.random.seed(2022)
    inputs[1].set_data_from_numpy(np.random.randint(0, 20, [8, 2]).astype(np.int32), binary_data=False)

    # OUTPUT0、OUTPUT1为配置文件中的输出节点名称
    outputs.append(httpclient.InferRequestedOutput(output0, binary_data=False))
    outputs.append(httpclient.InferRequestedOutput(output1,
                                                   binary_data=False))
    query_params = {'test_1': 1, 'test_2': 2}
    results = triton_client.infer(
        model_name=model_name,
        inputs=inputs,
        outputs=outputs,
        request_compression_algorithm=request_compression_algorithm,
        response_compression_algorithm=response_compression_algorithm)
    print(results)
    # 转化为numpy格式
    print(results.as_numpy(output0))
    print(results.as_numpy(output1))
Triton版本与Python版本对应关系的确定主要基于以下几个方面: ### 兼容性测试 开发团队会对不同版本的TritonPython进行全面的兼容性测试。在测试过程中,会运行一系列的功能测试和性能测试,以确保Triton在特定Python版本上能够正常工作,并且性能表现符合预期。例如,测试Triton的核函数、并行计算等核心功能在不同Python环境下是否能稳定运行。像Triton 2.1.0支持Python 3.10和3.11,Triton 3.0.0支持Python 3.10、3.11和3.12,这些支持的Python版本都是经过兼容性测试确定的[^1]。 ### 依赖库的兼容性 Triton依赖于许多其他的Python库,而这些库可能对Python版本有特定的要求。因此,Triton版本与Python版本的对应关系需要考虑这些依赖库的兼容性。如果某个依赖库不支持较新的Python版本,那么Triton在该Python版本上可能无法正常使用。 ### 语言特性的支持 不同版本的Python会引入新的语言特性或对现有特性进行改进。Triton的开发团队需要评估这些新特性对Triton的影响,并决定是否支持相应的Python版本。例如,如果某个Python版本的新特性可以提升Triton的性能或开发效率,开发团队可能会考虑支持该版本。 ### 社区反馈和市场需求 社区的反馈和市场需求也是确定对应关系的重要因素。如果用户在社区中频繁请求支持某个Python版本,开发团队可能会进行评估并考虑添加对该版本的支持。同时,市场上主流Python版本的使用情况也会影响Triton版本与Python版本的对应关系。 ```python # 示例代码,展示Triton核函数的基本结构 import triton import triton.language as tl @triton.jit def add_kernel( x_ptr, # *Pointer* to first input vector y_ptr, # *Pointer* to second input vector output_ptr, # *Pointer* to output vector n_elements, # Size of the vector BLOCK_SIZE: tl.constexpr, # Number of elements each program should process ): # There are multiple 'programs' processing different data. We identify which program # we are here pid = tl.program_id(axis=0) # We use a 1D launch grid so axis is 0 # This program will process inputs that are offset from the initial data. # for instance, if you had a vector of length 256 and block_size of 64, the programs # would each access the elements [0:64, 64:128, 128:192, 192:256]. # Note that offsets is a list of pointers block_start = pid * BLOCK_SIZE offsets = block_start + tl.arange(0, BLOCK_SIZE) # Create a mask to guard memory operations against out-of-bounds accesses mask = offsets < n_elements # Load x and y from DRAM, masking out any extra elements in case the input is not a # multiple of the block size x = tl.load(x_ptr + offsets, mask=mask) y = tl.load(y_ptr + offsets, mask=mask) output = x + y # Write x + y back to DRAM tl.store(output_ptr + offsets, output, mask=mask) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值