Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cogstack_model_gateway/gateway/core/auto_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def deploy_on_demand_model(
model_type=model_type,
deployment_type=ModelDeploymentType.AUTO,
ttl=model_config.idle_ttl,
resources=model_config.deploy.resources if model_config.deploy else None,
resources=model_config.deploy.__dict__ if model_config.deploy else None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not using pydantic's built-in model_dump here?

We generally tend to avoid calling internal/magic/dunder methods like that directly. __dict__ is used to fetch an object's writable attributes, not convert it to a dictionary. Consider the following example:

deploy = DeploySpec(resources=DeployResources(limits=ResourceLimits(memory="4g")))

Calling deploy.__dict__ will return the following, which isn't really what you want (notice how it doesn't work recursively):

{'resources': DeployResources(limits=ResourceLimits(memory='4g', cpus=None), reservations=None)}

Instead, you should be calling model_dump which is build for this exact purpose, replacing the now deprecated dict method of pydantic's BaseModel.

Suggested change
resources=model_config.deploy.__dict__ if model_config.deploy else None,
resources=model_config.deploy.model_dump() if model_config.deploy else None,

The above will give you the intended result:

{'resources': {'limits': {'memory': '4g', 'cpus': None}, 'reservations': None}}

)

log.info("Successfully deployed container for model: %s", model_name)
Expand Down
Loading