首页 > 解决方案 > aws sagemaker 端点的输入 json 字符串是否有限制?

问题描述

我有大约 5MB 的 json 字符串要发送到我的端点。我正在使用 boto3.client 从我的 python 客户端调用端点。它抛出 ConnectionResetError。

    File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\awsrequest.py", line 92, in _send_request
    method, url, body, headers, *args, **kwargs)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\awsrequest.py", line 119, in _send_output
    self.send(msg)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\awsrequest.py", line 203, in send
    return super(AWSConnection, self).send(str)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 977, in send
    self.sock.sendall(data)
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1012, in sendall
    v = self.send(byte_view[count:])
  File "C:\Users\corona\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 981, in send
    return self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

查看跟踪,我猜这是由于 json 字符串大小。有人可以帮我解决这个问题吗?

标签: jsonpython-3.xhttp-postamazon-sagemakerurllib3

解决方案


超过负载大小限制会导致 SageMaker Runtime 服务重置连接。

从 SageMaker文档

端点调用的最大有效负载大小 | 5 MB

您可以使用比 JSON 更节省空间的数据格式来传输有效负载,但可用选项将取决于数据类型和您使用的模型图像(即亚马逊提供的还是自定义实现)。


推荐阅读