Skip to content

_repack_model.py does not work with S3 URI from processing job #3324

@isunli

Description

@isunli

Describe the bug
I noticed that in this change, the model_path logic in the _repack_model.py has changed from
model_path = os.path.join(data_directory, model_archive)
to
model_path = os.path.join(data_directory, model_archive.split("/")[-1]) . This change break the model artifacts reference from a processing job in the sagemaker pipeline. For example when I reference model data in the create model step in the sagemaker pipeline, it use:

model_data=step_processing.properties.ProcessingOutputConfig.Outputs[
            "model"
        ].S3Output.S3Uri

And model_archive.split("/")[-1] will take whatever in the last after string split to the model_path, this result in a path not exists error. For example:

data_directory = "/opt/ml/input/data/training"
model_archive = "s3://a/b"
model_path -> "/opt/ml/input/data/training/b" (not exist)

To reproduce
Code I use

model_path_param = ParameterString(
    name="model_path", default_value=f"{s3_prefix}/models/sklearn/processing")

step_processing = ProcessingStep(
    name="ProcessInputData",
    processor=sklearn_processor,
    outputs=[
        ProcessingOutput(
            output_name="model", source="/opt/ml/processing/model", destination=model_path_param
           ),
        ],
    )

preprocessing_model = SKLearnModel(
    name="CreatePreprocessingModel",
    model_data=step_processing.properties.ProcessingOutputConfig.Outputs[
        "model"
    ].S3Output.S3Uri,
    entry_point="preprocessing.py",
    source_dir=script_dir,
    code_location=f"{s3_prefix}/inference/sklearn/processing",
    role=role,
   )

When execute pipeline following error will be thrown:

ClientError: Failed to invoke sagemaker:CreateTrainingJob. Error Details: No S3 objects found under S3 URL "s3://.../models/sklearn/processing/model.tar.gz" given in input data source. Please ensure that the bucket exists in the selected region (us-east-1), that objects exist under that S3 prefix, and that the role...

Expected behavior
Model passed by s3 path can be correctly referred in the sagemaker pipeline

Screenshots or logs
See above

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: 1.102.0
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): SKLearnProcessor
  • Framework version: 1.0-1
  • Python version: 3.8
  • CPU or GPU: CPU
  • Custom Docker image (Y/N): N

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: pipelinesRelates to the SageMaker Pipeline Platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions