-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
component: pipelinesRelates to the SageMaker Pipeline PlatformRelates to the SageMaker Pipeline Platformtype: question
Description
I'm currently encountering an issue when trying to register a SageMaker model in a pipeline using the Python SDK. Here's the relevant code:
model = Model(
image_uri=image_uri,
model_data=step_train.properties.ModelArtifacts.S3ModelArtifacts,
sagemaker_session=sagemaker_session,
role=role,
)
model_register = model.register(
content_types=["text/csv"],
response_types=["text/csv"],
model_metrics=model_metrics,
inference_instances=["ml.t2.medium", "ml.m5.large"],
transform_instances=["ml.m5.large"],
approval_status="PendingManualApproval",
model_package_group_name="ReturnModelPackage",
)
step_model_register = ModelStep(
name="ReturnModelRegister", step_args=model_register
)
When I run this code, I get the following error message:
Traceback (most recent call last):
File "main_pipeline.py", line 288, in <module>
pipeline = get_pipeline()
File "main_pipeline.py", line 240, in get_pipeline
model_register = model.register(
File "/usr/local/lib/python3.8/dist-packages/sagemaker/workflow/pipeline_context.py", line 272, in wrapper
return run_func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/sagemaker/model.py", line 425, in register
model_package = self.sagemaker_session.create_model_package_from_containers(
File "/usr/local/lib/python3.8/dist-packages/sagemaker/session.py", line 3233, in create_model_package_from_containers
return self._intercept_create_request(
File "/usr/local/lib/python3.8/dist-packages/sagemaker/session.py", line 4813, in _intercept_create_request
return create(request)
File "/usr/local/lib/python3.8/dist-packages/sagemaker/session.py", line 3231, in submit
return self.sagemaker_client.create_model_package(**request)
File "/usr/local/lib/python3.8/dist-packages/botocore/client.py", line 530, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.8/dist-packages/botocore/client.py", line 919, in _make_api_call
request_dict = self._convert_to_request_dict(
File "/usr/local/lib/python3.8/dist-packages/botocore/client.py", line 990, in _convert_to_request_dict
request_dict = self._serializer.serialize_to_request(
File "/usr/local/lib/python3.8/dist-packages/botocore/validate.py", line 381, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
File "/usr/local/lib/python3.8/dist-packages/botocore/validate.py", line 102, in generate_report
error_messages.append(self._format_error(error))
File "/usr/local/lib/python3.8/dist-packages/botocore/validate.py", line 125, in _format_error
f'Invalid type for parameter {name}, value: {param}, '
File "/usr/local/lib/python3.8/dist-packages/sagemaker/workflow/entities.py", line 86, in __str__
raise TypeError(
TypeError: Pipeline variables do not support __str__ operation. Please use `.to_string()` to convert it to string type in execution timeor use `.expr` to translate it to Json for display purpose in Python SDK.
Solution tried: Followed the documentation to register the model using the Model.register() method. Also tried using the RegisterModel() method, which worked without any issue. However, we need to register the model using the Model.register() method.
Request: Please provide a solution to successfully register a SageMaker model in a pipeline using SageMaker Python SDK's Model.register() method without encountering the "TypeError: Pipeline variables do not support str operation" error.
Metadata
Metadata
Assignees
Labels
component: pipelinesRelates to the SageMaker Pipeline PlatformRelates to the SageMaker Pipeline Platformtype: question