amazon-s3amazon-sagemakeramz-sagemaker-distributed-training

How can I save a model from a Sagemaker Pipelines TrainingStep in a specific location i.e. without the unique parent folder?


I know that the TrainingStep saves the model as output by default, but I want to save it in a specific place in my S3 bucket. I need a way to programmatically find where a model is stored, so I want to get rid of the unique parent directory (pipelines-1913hs62gbn9-pipeline-scripts-tra-SAPd32cbD1z/).

I am aware of the output path parameter, but this alters the path after the unique folder name, not the whole one.

I am also aware of this question which was previously answered, but is not helpful for my case. (Been burned before, so now I am doing a diligent search before asking)

For example Path where it is saved now: s3://{my_bucket}/model/pipelines-1913hs62gbn9-pipeline-scripts-tra-SAPd32cbD1z/model.tar.gz

Where I want it: s3://{my_bucket}/model/model.tar.gz

Any ideas on API calls to make or ways to save it in a specific place?

*edited to fix spelling mistakes


Solution

  • SageMaker training/ pipeline step always adds a unique suffix to the output path provided for the files stored in the model dir. There are 2 ways you can avoid this

    1. Rather than storing to /opt/ml/model you can define checkpoint_local_path and checkpoint_s3_uri where the files are copied as is to s3.
    2. Write your own s3 uploader which will upload to a known path.