当我从 sagemaker 端点获得预测时,该端点会做什么?
在 sagemaker 中,文档讨论了需要具有 4 个特定函数的推理脚本。当我们得到预测时,Python SDK 会向端点发送请求。
然后推理脚本运行。但我找不到 SDK 中推理脚本运行的位置。
当我浏览 sdk 代码时,Predictor.predict()
方法调用 sagemaker 会话以向端点发布请求并获取响应。这是sdk中的最后一步。当 Sagemaker 收到该请求时,它显然正在做某事。
它运行的代码是什么?
In sagemaker, the docs talk about inference scripts requiring to have 4 specific functions. When we get a prediction, the python SDK sends a request to the endpoint.
Then the inference script runs. But I cannot find where in the SDK the inference script is run.
When I navigate through the sdk code the Predictor.predict()
method calls the sagemaker session to post a request to the endpoint and get a response. That is the final step in the sdk. Sagemaker is obviously doing something when it receives that request.
What is the code that it runs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
端点本质上是在 Docker 容器中运行的 Flask Web 服务器
如果它是 scikit-learn 图像,当您调用端点时,它会从 S3 加载脚本,然后...
它调用
input_fn(request_body: bytearray, content_type )-> np.ndarray
将request_body
解析为 numpy 数组然后它调用您的
model_fn(model_dir: str) ->; object
函数从model_dir
加载模型并返回模型然后它调用
predict_fn(input_object: np.ndarray, model: object) -> np.array
,它调用您的model.predict()
函数并返回预测然后它调用
output_fn(prediction: np.array, Accept: str)
从predict_fn
获取结果并将其编码为accept
类型您不需要自己实现所有这些函数,因为
您有默认值< /strong> 需要实施
model_fn
如果您有非数字数据,则只需实现
input_fn
如果您的模型使用
以外的其他内容,则只需实现
predict_fn
.predict()您可以看到默认函数实现如何工作此处
The endpoint is essentially a Flask web server running in a Docker container
If it's a scikit-learn image, when you invoke the endpoint, it loads your script from S3, then...
It calls
input_fn(request_body: bytearray, content_type) -> np.ndarray
to parse therequest_body
into a numpy arrayThen it calls your
model_fn(model_dir: str) -> object
function to load the model frommodel_dir
and return the modelThen it calls
predict_fn(input_object: np.ndarray, model: object) -> np.array
, which calls yourmodel.predict()
function and returns the predictionThen it calls
output_fn(prediction: np.array, accept: str)
to take the result frompredict_fn
and encode it to theaccept
typeYou don't need to implement all of these functions yourself, as there are defaults
You do need to implement
model_fn
You only need to implement
input_fn
if you have non numeric dataYou only need to implement
predict_fn
if your model uses something other than.predict()
You can see how the default function implementations work here