如何处理 Sagemaker 批量转换丢弃模型请求失败的文件
How to handle Sagemaker Batch Transform discarding a file with a failed model request
我有大量 JSON 请求将模型拆分为 S3 存储桶中的多个文件。我想使用 Sagemaker 的批量转换功能来处理所有这些请求(我使用少量数据进行了几次测试,转换作业成功)。我的主要问题在这里 (https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform.html#batch-transform-errors),特别是:
If a batch transform job fails to process an input file because of a problem with the dataset, SageMaker marks the job as failed. If an input file contains a bad record, the transform job doesn't create an output file for that input file because doing so prevents it from maintaining the same order in the transformed data as in the input file. When your dataset has multiple input files, a transform job continues to process input files even if it fails to process one. The processed files still generate useable results.
这不是可取的,主要是因为如果在包含大量请求的文件中有 1 个请求失败(无论是暂时性错误、格式错误的请求还是模型容器有问题),所有这些请求都将得到丢弃(即使所有的都成功而最后一个失败)。理想情况下,我更希望 Sagemaker 将失败响应的输出写入文件并继续,而不是丢弃整个文件。
我的问题是,是否有任何缓解此问题的建议?我正在考虑在 S3 中为每个文件存储 1 个请求,但这似乎有些荒谬?即使我这样做了,是否有一种好方法可以在转换作业完成后查看具体失败的请求?
您的想法是正确的:每个文件中的数据点越少,给定文件失败的可能性就越小。问题是虽然您可以将包含许多文件的前缀传递给 CreateTransformJob, partitioning one datapoint per file at least requires an S3 read per datapoint, plus a model invocation per datapoint, which is probably not great. Be aware also that apparently there are hidden rate limits.
这里有几个选项:
分区成small-ish个文件,并计划故障很少见。希望您的数据点实际上不会失败。如果您将数据集划分为例如100 个文件,那么一次故障只需要重新处理 1% 的数据。请注意,Sagemaker 也有 built-in 次重试,因此大多数时候失败应该是由您 data/logic 造成的,而不是 Sagemaker 方面的随机性。
直接在您的模型中处理故障。您在问题中引用的同一文档还说:
If you are using your own algorithms, you can use placeholder text, such as ERROR, when the algorithm finds a bad record in an input file. For example, if the last record in a dataset is bad, the algorithm places the placeholder text for that record in the output file.
请注意,批处理转换 whole-file 失败的原因是要在输入和输出行之间保持 1-1 映射。如果您可以用模型内部的错误消息替换失败数据点的输出,而不会实际导致模型本身处理失败,那么批量转换会很高兴。
我有大量 JSON 请求将模型拆分为 S3 存储桶中的多个文件。我想使用 Sagemaker 的批量转换功能来处理所有这些请求(我使用少量数据进行了几次测试,转换作业成功)。我的主要问题在这里 (https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform.html#batch-transform-errors),特别是:
If a batch transform job fails to process an input file because of a problem with the dataset, SageMaker marks the job as failed. If an input file contains a bad record, the transform job doesn't create an output file for that input file because doing so prevents it from maintaining the same order in the transformed data as in the input file. When your dataset has multiple input files, a transform job continues to process input files even if it fails to process one. The processed files still generate useable results.
这不是可取的,主要是因为如果在包含大量请求的文件中有 1 个请求失败(无论是暂时性错误、格式错误的请求还是模型容器有问题),所有这些请求都将得到丢弃(即使所有的都成功而最后一个失败)。理想情况下,我更希望 Sagemaker 将失败响应的输出写入文件并继续,而不是丢弃整个文件。
我的问题是,是否有任何缓解此问题的建议?我正在考虑在 S3 中为每个文件存储 1 个请求,但这似乎有些荒谬?即使我这样做了,是否有一种好方法可以在转换作业完成后查看具体失败的请求?
您的想法是正确的:每个文件中的数据点越少,给定文件失败的可能性就越小。问题是虽然您可以将包含许多文件的前缀传递给 CreateTransformJob, partitioning one datapoint per file at least requires an S3 read per datapoint, plus a model invocation per datapoint, which is probably not great. Be aware also that apparently there are hidden rate limits.
这里有几个选项:
分区成small-ish个文件,并计划故障很少见。希望您的数据点实际上不会失败。如果您将数据集划分为例如100 个文件,那么一次故障只需要重新处理 1% 的数据。请注意,Sagemaker 也有 built-in 次重试,因此大多数时候失败应该是由您 data/logic 造成的,而不是 Sagemaker 方面的随机性。
直接在您的模型中处理故障。您在问题中引用的同一文档还说:
If you are using your own algorithms, you can use placeholder text, such as ERROR, when the algorithm finds a bad record in an input file. For example, if the last record in a dataset is bad, the algorithm places the placeholder text for that record in the output file.
请注意,批处理转换 whole-file 失败的原因是要在输入和输出行之间保持 1-1 映射。如果您可以用模型内部的错误消息替换失败数据点的输出,而不会实际导致模型本身处理失败,那么批量转换会很高兴。