Skip to content

Sagemaker ModelLifeCycle bug: TypeError: Object of type ModelLifeCycle is not JSON serializable #5186

Open
@TunikiCharitha

Description

@TunikiCharitha

Describe the bug
When calling a model.register() method with model_life_cycle param, a TypeError: Object of type ModelLifeCycle is not JSON serializable is encountered.

To reproduce

Create a new model

model = Model(
        image_uri="account.dkr.ecr.region.amazonaws.com/repo:tag",
        role="arn:aws:iam::account:role/name",
        sagemaker_session=PipelineSession
    )

Call model.register()

model.register(
        content_types="application/json",
        response_types="application/json",
        model_package_group_name="somePackageGroupName",
        model_life_cycle=ModelLifeCycle(
            stage="someStage",
            stage_status="someStatus",
            stage_description="someDescription"
        )
    )

Expected behavior
model.register() should not throw TypeError when called with model_life_cycle params.

Screenshots or logs

Image Image

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: 2.244.2
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): N/A
  • Framework version: N/A
  • Python version: 3.11
  • CPU or GPU: N/A
  • Custom Docker image (Y/N): N

Suggested fix
Issue could be due to not converting the ModelLifeCycle class object into dict first since json.dumps() accepts a dict.
Replace model_package_args["model_life_cycle"] = model_life_cycle with model_package_args["model_life_cycle"] = model_life_cycle._to_request_dict()

model_package_args["model_life_cycle"] = model_life_cycle

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions