快捷方式

ts.torch_handler.request_envelope 包

子模块

ts.torch_handler.request_envelope.base 模块

所有 RequestEnvelope 的基类。

请求信封重新格式化对处理程序的调用的输入/输出。它将特定于模型编排器(如 Seldon 或 KServe)的格式转换为一组扁平的 Python 项目,反之亦然。

class ts.torch_handler.request_envelope.base.BaseEnvelope(handle_fn)[source]

基类: ABC

所有信封的接口。从此类派生,替换抽象方法

abstract format_output(data)[source]
handle(data, context)[source]

输入请求和响应在此处处理。

abstract parse_input(data)[source]

ts.torch_handler.request_envelope.body 模块

所有处理程序的默认类。从请求正文中获取数据。

class ts.torch_handler.request_envelope.body.BodyEnvelope(handle_fn)[source]

基类: BaseEnvelope

从输入数据中获取键 “body”,返回原始列表

format_output(data)[source]
parse_input(data)[source]

ts.torch_handler.request_envelope.json 模块

使用 JSON 格式化的输入/输出,遵循 https://tensorflowcn.cn/tfx/serving/api_rest 中概述的结构

class ts.torch_handler.request_envelope.json.JSONEnvelope(handle_fn)[source]

基类: BaseEnvelope

实现。以 JSON 格式捕获批次,也以 JSON 格式返回。

format_output(data)[source]
parse_input(data)[source]

ts.torch_handler.request_envelope.kserve 模块

KServe 信封用于处理 Torchserve 内部的 KServe 输入请求。

class ts.torch_handler.request_envelope.kserve.KServeEnvelope(handle_fn)[source]

基类: BaseEnvelope

此函数用于处理 KServe 格式中指定的输入请求,并将其转换为 Torchserve 可读格式。

参数:

Format (data - KServe 中的输入请求列表) –

返回:

返回 Torchserve 格式的输入请求列表

返回类型:

[list]

format_output(data)[source]

返回输入请求的预测响应和 Captum 解释响应。

参数:

outputs (List) – outputs 参数的形式为字典列表。

返回:

响应作为预测和解释列表返回

返回类型:

(list)

parse_input(data)[source]

ts.torch_handler.request_envelope.kservev2 模块

KServe 信封用于处理 Torchserve 内部的 KServe 输入请求。

class ts.torch_handler.request_envelope.kservev2.KServev2Envelope(handle_fn)[source]

基类: BaseEnvelope

实现。以 KServe v2 协议格式捕获批次,也以 FServing v2 协议格式返回。

format_output(data)[source]

转换 Torchserve 输出 KServe v2 响应格式。

参数: data (list): 处理程序的 Torchserve 响应。

返回: KServe v2 响应 json。 {

“id”: “f0222600-353f-47df-8d9d-c96d96fa894e”, “model_name”: “bert”, “model_version”: “1”, “outputs”: [{

“name”: “input-0”, “shape”: [1], “datatype”: “INT64”, “data”: [2]

}]

}

parse_input(data)[source]

将 KServe 请求输入转换为 Torchserve 期望的数据列表。

参数: data (json): KServe v2 请求输入 json。 {

“inputs”: [{

“name”: “input-0”, “shape”: [37], “datatype”: “INT64”, “data”: [66, 108, 111, 111, 109]

}]

}

返回: 数据对象列表。 [{ ‘name’: ‘input-0’, ‘shape’: [5], ‘datatype’: ‘INT64’, ‘data’: [66, 108, 111, 111, 109] }]

模块内容

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得问题解答

查看资源