gpt4 book ai didi

python - 如何在 aws sagemaker 中提供每日预先计算的预测?

转载 作者:行者123 更新时间:2023-12-04 04:11:59 24 4
gpt4 key购买 nike

我正在尝试使用 Sagemaker 来提供预先计算的预测。预测在 python 字典中采用以下格式。

customer_group prediction
1 50
2 60
3 25
4 30
...

目前 docker serve API code转到 s3 并每天下载数据。

问题是下载数据会阻止 api 响应 Sagemaker health endpoint calls .

这是 how zappos did it 的案例研究使用 Amazon DynamoDB。但是,有没有办法在 Sagemaker 中做到这一点?

在哪里以及如何添加s3下载功能以避免中断健康检查?

这能行吗? -> https://github.com/seomoz/s3po
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-x-email-support
app = flask.Flask(__name__)

@app.route('/ping', methods=['GET'])
def ping():
"""Determine if the container is working and healthy. In this sample container, we declare
it healthy if we can load the model successfully."""
health = ScoringService.get_model() is not None # You can insert a health check here

status = 200 if health else 404
return flask.Response(response='\n', status=status, mimetype='application/json')

@app.route('/invocations', methods=['POST'])
def transformation():
"""Do an inference on a single batch of data. In this sample server, we take data as CSV, convert
it to a pandas data frame for internal use and then convert the predictions back to CSV (which really
just means one prediction per line, since there's a single column.
"""
data = None

# Convert from CSV to pandas
if flask.request.content_type == 'text/csv':
data = flask.request.data.decode('utf-8')
s = StringIO.StringIO(data)
data = pd.read_csv(s, header=None)
else:
return flask.Response(response='This predictor only supports CSV data', status=415, mimetype='text/plain')

print('Invoked with {} records'.format(data.shape[0]))

# Do the prediction
predictions = ScoringService.predict(data)

# Convert from numpy back to CSV
out = StringIO.StringIO()
pd.DataFrame({'results':predictions}).to_csv(out, header=False, index=False)
result = out.getvalue()

return flask.Response(response=result, status=200, mimetype='text/csv')

最佳答案

为什么不打电话batch transform而是让 AWS 完成繁重的工作。

您可以安排每天完成,也可以手动触发。

在此之后,使用带有 Lambda 函数的 API 网关或 CloudFront 来显示来自 S3 的结果。

关于python - 如何在 aws sagemaker 中提供每日预先计算的预测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61566816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com