捷徑

ts 封裝

子封裝

子模組

ts.arg_parser 模組

此模組解析透過 torchserve 命令列給定的引數。模型伺服器在執行階段使用此模組。

class ts.arg_parser.ArgParser[source]

基於: object

用於 torchserve 和 torchserve-export 命令的引數解析器 TODO:新增 readme 網址

static extract_args(args=None)[source]
static model_service_worker_args()[source]

用於後端工作者的 ArgParser。採用 socket 名稱和 socket 類型。:return

static ts_parser()[source]

用於 torchserve 啟動服務的引數解析器

ts.context 模組

傳入請求的內容物件

class ts.context.Context(model_name, model_dir, manifest, batch_size, gpu, mms_version, limit_max_image_pixels=True, metrics=None, model_yaml_config=None)[source]

基於: object

Context 儲存模型相關的 worker 資訊,某些資訊在載入時是固定的,而某些資訊則由服務設定。

get_all_request_header(idx: int) Dict[str, str][source]
get_request_header(idx: int, key: str) Optional[str][source]
get_request_id(idx: int = 0) Optional[str][source]
get_response_content_type(idx: int) Optional[str][source]
get_response_headers(idx: int) Dict[str, str][source]
get_response_status(idx: int) Tuple[int, str][source]
get_sequence_id(idx: int) str[原始碼]
property metrics
property request_processor
set_all_response_status(code: int = 200, phrase: str = '') None[原始碼]

設定個別請求的狀態碼 :param phrase: :param code: :return

set_response_content_type(idx: int, value: str) None[原始碼]
set_response_header(idx, key, value)[原始碼]
set_response_status(code: int = 200, phrase: str = '', idx: int = 0)[原始碼]

設定個別請求的狀態碼 :param phrase: :param idx: 傳送到 handle() 方法的 list(data) 中的索引資料 :param code: :return

property system_properties
class ts.context.RequestProcessor(request_header: dict)[原始碼]

基於: object

請求處理器

add_response_property(key: str, value: str) None[原始碼]
get_request_properties() dict[原始碼]
get_request_property(key: str) Optional[str][原始碼]
get_response_header(key: str) Optional[str][source]
取得回應標頭。
get_response_headers() dict[source]
取得所有回應標頭的字典。
get_response_status_code() int[source]

取得回應狀態碼。

get_response_status_phrase() Optional[str][source]

取得回應狀態短語。

基於: object

report_status(code, reason_phrase=None) None[source]

報告狀態碼與原因短語。

ts.model_loader module

模型載入器模組。
Load model from file.

Parameters:

參數:

基於: object

static get_model_loader()[原始碼]
class ts.model_loader.TsModelLoader[原始碼]

基於: ModelLoader

TorchServe 1.0 模型載入器

load(model_name: str, model_dir: str, handler: Optional[str] = None, gpu_id: Optional[int] = None, batch_size: Optional[int] = None, envelope: Optional[str] = None, limit_max_image_pixels: Optional[bool] = True, metrics_cache: Optional[MetricsCacheYamlImpl] = None) Service[原始碼]

從檔案載入 TorchServe 1.0 模型。

模型載入器模組。
  • Model loader.

  • 模型載入器。

  • class ts.model_loader.ModelLoader[source]

  • 基礎模型載入器類別。

  • Base Model Loader class.

  • abstract load(model_name: str, model_dir: str, handler: Optional[str] = None, gpu_id: Optional[int] = None, batch_size: Optional[int] = None, envelope: Optional[str] = None, limit_max_image_pixels: Optional[bool] = True)[source]

  • 從檔案載入模型。

  • metrics_cache – MetricsCacheYamlImpl 物件

Load model from file.

ts.model_server 模組

定義 Model Server 進入點的檔案

ts.model_server.load_properties(file_path: str) Dict[str, str][原始碼]

將屬性檔案讀取到 map 中。

ts.model_server.start() None[原始碼]

這是模型伺服器的進入點 :return

ts.model_service_worker 模組

ModelServiceWorker 是由 MMS 前端啟動的 worker。 通訊訊息格式:二進位編碼

class ts.model_service_worker.TorchModelServiceWorker(s_type: Optional[str] = None, s_name: Optional[str] = None, host_addr: Optional[str] = None, port_num: Optional[int] = None, metrics_config: Optional[str] = None, async_comm: Optional[bool] = False)[source]

基於: object

後端工作單元,用於處理模型伺服器的 Python 服務代碼

handle_connection(cl_socket)[source]

處理 socket 連線。

模型載入器模組。

cl_socket

Load model from file.

handle_connection_async(cl_socket)[source]

處理 socket 連線。

模型載入器模組。

cl_socket

Load model from file.

load_model(load_model_request)[source]

預期的指令 {

“command” : “load”, 字串 “modelPath” : “/path/to/model/file”, 字串 “modelName” : “name”, 字串 “gpu” : 若為 CPU 則為 None,否則為 gpu_id, 整數 “handler” : 若有提供,則為服務處理常式進入點, 字串 “envelope” : 若有提供,則為請求資料的封裝/解封裝名稱, 整數 “batchSize” : 批次大小, 整數 “limitMaxImagePixels”: 限制 pillow 影像 max_image_pixels, 布林值

}

模型載入器模組。

load_model_request

Load model from file.

run_server()[source]

執行後端工作程序並監聽 socket :return

ts.service 模組

CustomService 類別定義

class ts.service.Service(model_name, model_dir, manifest, entry_point, gpu, batch_size, limit_max_image_pixels=True, metrics_cache=None)[source]

基於: object

自訂 entry_point 的封裝器

property context
predict(batch)[source]
PREDICT 命令 = {

“command”: “predict”, “batch”: [ REQUEST_INPUT ]

} :param batch: 請求列表 :return

static retrieve_data_for_inference(batch)[原始碼]
REQUEST_INPUT = {

“requestId” : “111-222-3333”, “parameters” : [ PARAMETER ]

}

PARAMETER = {

“name” : 參數名稱 “contentType”: “http-content-types”, “value”: “val1”

}

模型載入器模組。

batch

Load model from file.

set_cl_socket(cl_socket)[原始碼]
ts.service.emit_metrics(metrics)[原始碼]

發布在提供的字典中的指標

模型載入器模組。
  • metrics (所有指標的字典) –

  • metrics

  • metric_name (當鍵為) –

  • object (值為指標) –

ts.version 模組

這是 TorchServe 的目前版本

模組內容

此模組執行以下操作:a. 啟動模型伺服器。b. 根據已配置的模型建立端點。c. 公開標準的 “ping” 和 “api-description” 端點。d. 等待提供推論請求。

文件

存取 PyTorch 的完整開發人員文件

檢視文件

教學課程

取得初學者和進階開發人員的深入教學課程

檢視教學課程

資源

尋找開發資源並取得您問題的解答

檢視資源