Skip to content

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

Open
@Aditi2424

Description

@Aditi2424

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()

https://github.com/aws/sagemaker-python-sdk/blob/6fb3b813d487d65b2114d129370ea012e9e37f07/src/sagemaker/session.py#L7512

Metadata

Metadata

Assignees

No one assigned

    Labels

    Amazon Q development agentGenerate new features or iterate code based on issue descriptions and comments.bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions