ts 包¶
子包¶
- ts.metrics 包
- ts.model_service 包
- ts.protocol 包
- ts.torch_handler 包
- 子包
- ts.torch_handler.request_envelope 包
- ts.torch_handler.unit_tests 包
- 子包
- 子模組
- ts.torch_handler.unit_tests.test_base_handler 模組
- ts.torch_handler.unit_tests.test_envelopes 模組
- ts.torch_handler.unit_tests.test_image_classifier 模組
- ts.torch_handler.unit_tests.test_image_segmenter 模組
- ts.torch_handler.unit_tests.test_mnist_kf 模組
- ts.torch_handler.unit_tests.test_object_detector 模組
- 模組內容
- 子模組
- ts.torch_handler.base_handler 模組
- ts.torch_handler.contractions 模組
- ts.torch_handler.densenet_handler 模組
- ts.torch_handler.image_classifier 模組
- ts.torch_handler.image_segmenter 模組
- ts.torch_handler.object_detector 模組
- ts.torch_handler.text_classifier 模組
- ts.torch_handler.text_handler 模組
- ts.torch_handler.vision_handler 模組
- 模組內容
- 子包
- ts.utils 包
子模組¶
ts.arg_parser 模組¶
此模組解析透過 torchserve 命令列提供的引數。這在執行時由模型伺服器使用。
ts.context 模組¶
傳入請求的上下文物件
- 類 ts.context.Context(model_name, model_dir, manifest, batch_size, gpu, mms_version, limit_max_image_pixels=True, metrics=None, model_yaml_config=None)[原始碼]¶
基類:
objectContext 儲存與模型相關的 worker 資訊。有些在載入時固定,有些由服務設定
- 屬性 metrics¶
- 屬性 request_processor¶
- set_all_response_status(code: int = 200, phrase: str = '') None[原始碼]¶
設定單個請求的狀態碼 :引數 phrase: :引數 code: :返回
- set_response_status(code: int = 200, phrase: str = '', idx: int = 0)[原始碼]¶
設定單個請求的狀態碼 :引數 phrase: :引數 idx: 傳送到 handle() 方法的列表 (data) 中的資料索引 :引數 code: :返回
- 屬性 system_properties¶
ts.model_loader 模組¶
模型載入器。
- 類 ts.model_loader.ModelLoader[原始碼]¶
基類:
object基本模型載入器類。
- 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]¶
從檔案載入模型。
- 引數:
model_name –
model_dir –
handler –
gpu_id –
batch_size –
envelope –
limit_max_image_pixels –
- 返回值:
模型
- class ts.model_loader.TsModelLoader[source]¶
繼承自:
ModelLoaderTorchServe 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[source]¶
從檔案載入 TorchServe 1.0 模型。
- 引數:
model_name –
model_dir –
handler –
gpu_id –
batch_size –
envelope –
limit_max_image_pixels –
metrics_cache – MetricsCacheYamlImpl 物件
- 返回值:
ts.model_server 模組¶
定義模型伺服器入口點的檔案
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後端 worker,用於處理模型伺服器的 python 服務程式碼
- 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 影像的最大畫素數,布林值
}
- 引數:
load_model_request –
- 返回值:
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¶
-
“command”: “predict”, “batch”: [ REQUEST_INPUT ] } :param batch: 請求列表 :return
ts.version 模組¶
這是 TorchServe 的當前版本。
模組內容¶
此模組執行以下操作: a. 啟動模型伺服器。 b. 基於配置的模型建立端點。 c. 暴露標準的“ping”和“api-description”端點。 d. 等待處理推理請求。