0
votes

I am working on a AWS SageMaker (SKlearn) batch transform job, in which the prediction data is big and therefore I'm required to use mini-batches (where the input .csv is split up into smaller .csv files).

I have this working and outputting a .csv file with the ids and the predictions. However I am attempting to implement a way in which I can have a total of three output files from the batch transform job - which are different .csv files each aggregated in a slightly different way.

My issue is I am not sure how to instruct SageMaker to output multiple files. I have tried the following code as the prediction method submitted in the entry_point file:

def output_fn(prediction, accept):
    output_one = prepare_one(prediction)
    output_two, output_three = prepare_others(output_one)
    return output_one, output_two, output_three

Couple ideas/issues I am currently working with:

  • I think the batching strategy will cause issue. As the additional outputs are aggregations on the total predictions but SageMaker will treat each mini-batch separately (I assume?)
  • Can I simply use boto3 and save extra files using that and treat the SageMaker output as only output_one

Any help would be much appreciated

1

1 Answers

1
votes
  1. In SageMaker Batch, the output file is a one to one mapping to your input file, which means you cannot have multiple output files for a single input.

"If the batch transform job successfully processes all of the records in an input file, it creates an output file with the same name and an .out file extension. For multiple input files, such as input1.csv and input2.csv, the output files are named input1.csv.out, and input2.csv.out." (https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform.html#batch-transform-large-datasets)

  1. In this case, you probably don't need to split the input manually into batches. As your input is CSV, you can simply set the "SplitType" to "Line" and Batch will automatically split your input by newlines and takes each line as a record. Then you can set the "BatchStrategy" to "MultiRecord" and tune the "MaxPayloadInMB" to control the size of the mini batches. As a result, your model will see N records where "N * size_of_each_record <= MaxPayloadInMB" in each HTTP inference request.

Hope this helps!