类型¶
BentoML API 的其他类型
- class bentoml.types.ModelSignature(batchable: bool = False, batch_dim: Tuple[int, int] = (0, 0), input_spec: Any = None, output_spec: Any = None)[source]¶
模型签名表示模型对象上可以调用的方法。
此信息用于为此模型创建 BentoML Runner。
请注意,在使用
ModelSignature
的任何地方,都可以使用一个键对应字段的dict
代替。例如,可以使用{"predict": {"batchable": True}}
而不是{"predict": ModelSignature(batchable=True)}
。- 字段
- batchable
BentoML Runner 是否应对此预测方法的多个 API 调用进行批处理。
- batch_dim
传递给此预测方法时包含多个数据的维度。
例如,如果您有两个要运行预测的输入:
[1, 2]
和[3, 4]
。如果传递给预测方法的数组是[[1, 2], [3, 4]]
,则批处理维度为0
。如果传递给预测方法的数组是[[1, 3], [2, 4]]
,则批处理维度为1
。如果预测方法有多个参数且只提供一个批处理维度,则所有参数将使用该批处理维度。
- 示例: .. code-block:: python
# Save two models with predict method that supports taking input batches on the dimension 0 and the other on dimension 1: bentoml.pytorch.save_model(“demo0”, model_0, signatures={“predict”: {“batchable”: True, “batch_dim”: 0}}) bentoml.pytorch.save_model(“demo1”, model_1, signatures={“predict”: {“batchable”: True, “batch_dim”: 1}}) # if the following calls are batched, the input to the actual predict method on the # model.predict method would be [[1, 2], [3, 4], [5, 6]] runner0 = bentoml.pytorch.get(“demo0:latest”).to_runner() runner0.init_local() runner0.predict.run(np.array([[1, 2], [3, 4]])) runner0.predict.run(np.array([[5, 6]])) # if the following calls are batched, the input to the actual predict method on the # model.predict would be [[1, 2, 5], [3, 4, 6]] runner1 = bentoml.pytorch.get(“demo1:latest”).to_runner() runner1.init_local() runner1.predict.run(np.array([[1, 2], [3, 4]])) runner1.predict.run(np.array([[5], [6]]))
高级 API
批处理维度也可以是 (输入批处理维度, 输出批处理维度) 的元组。例如,如果预测方法应该沿第一个轴对输入进行批处理,并沿零轴对输出进行批处理,则可以将
batch_dim
设置为(1, 0)
。
input_spec: 保留供将来使用。
output_spec: 保留供将来使用。