Skip to content

Sagemaker pipeline model registration issue

0

Below is my Code Snippet from Pipeline.

Step 3: Model Evaluation

evaluation_processor = SKLearnProcessor(
    framework_version="0.23-1",
    instance_type="ml.m5.xlarge", 
    instance_count=1,
    base_job_name="fraud-evaluation",
    role=role,
)

evaluation_report = PropertyFile(
    name="EvaluationReport",
    output_name="evaluation",
    path="evaluation.json"
)

evaluation_step = ProcessingStep(
    name="EvaluateFraudModel",
    processor=evaluation_processor,
    inputs=[
        ProcessingInput(
            source=training_step.properties.ModelArtifacts.S3ModelArtifacts,
            destination="/opt/ml/processing/model"
        ),
        ProcessingInput(
            source=processing_step.properties.ProcessingOutputConfig.Outputs["test"].S3Output.S3Uri,
            destination="/opt/ml/processing/test"
        )
    ],
    outputs=[
        ProcessingOutput(
            output_name="evaluation",
            source="/opt/ml/processing/evaluation",
            destination=f"s3://{bucket}/evaluation-results"
        )
    ],
    code="../src/evaluation_pipeline.py",
    property_files=[evaluation_report]
)

# Step 4: Model Registration
model_metrics = ModelMetrics(
    model_statistics=MetricsSource(
        s3_uri="s3://{}/evaluation-results/evaluation.json".format(bucket),
        content_type="application/json"
    )
)

register_step = RegisterModel(
    name="RegisterFraudModel",
    estimator=xgb_estimator,
    model_data=training_step.properties.ModelArtifacts.S3ModelArtifacts,
    content_types=["text/csv"],
    response_types=["text/csv"],
    inference_instances=["ml.m5.large", "ml.m5.xlarge"],
    transform_instances=["ml.m5.large"],
    model_package_group_name="fraud-detection-models",
    approval_status=model_approval_status,
    model_metrics=model_metrics
)

This step is failing with the following error:Enter image description here model_metrics = ModelMetrics( model_statistics=MetricsSource( s3_uri="s3://{}/evaluation-results/evaluation.json".format(bucket), content_type="application/json" ) ) ClientError: Failed to invoke sagemaker:CreateModelPackage. Error Details: 1 validation error detected: Value '<sagemaker.workflow.properties.Properties object at 0x1182d83d0>/evaluation.json' at 'modelMetrics.modelQuality.statistics.s3Uri' failed to satisfy constraint: Member must satisfy regular expression pattern: (https|s3)://([^/]+)/?(.*)

1 Answer
0

The error you're encountering is related to the model registration step in your SageMaker pipeline. The issue is with the S3 URI format in your ModelMetrics configuration.

When using RegisterModel in a SageMaker pipeline with SDK version 2.90.0 or later, there are specific requirements for how you reference S3 URIs. The error indicates that the S3 URI format you're using for model metrics doesn't match the expected pattern.

Instead of directly specifying the S3 URI as a string with formatting, you should reference the output from your evaluation step. Here's how you can fix your code:

model_metrics = ModelMetrics(
model_statistics=MetricsSource(
s3_uri=evaluation_step.properties.ProcessingOutputConfig.Outputs["evaluation"].S3Output.S3Uri + "/evaluation.json",
content_type="application/json"
)
)

This approach uses the properties from your evaluation step to dynamically reference the S3 location where your evaluation results are stored.

If you continue to face issues with RegisterModel in your pipeline, you might consider using ModelStep instead, as it's the recommended approach for model registration in newer versions of the SageMaker SDK. Alternatively, you could use Boto3 or SageMaker Studio to register your model.
Sources
Troubleshoot model registry issues in SageMaker AI | AWS re:Post
Add a step - Amazon SageMaker AI

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.