Skip to content

Commit

Permalink
Fix Deployment model definition (#271)
Browse files Browse the repository at this point in the history
#258 added fields to the `Deployment` model provided by the new
`deployments.{get,list,update}` endpoints. However, those were
implemented against a version of the OpenAPI specification that
disagreed with the actual API responses. Specifically, the
`min_instances` and `max_instances` properties were listed as
subproperties of a `scaling` object rather than direct fields. The
result — as reported in #270 — was Pydantic validation errors like this:

```
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for Deployment
current_release -> configuration -> scaling
field required (type=value_error.missing)"
```

This PR updates the `Deployment` model to correctly locate
`min_instances` and `max_instances` as properties of
`current_release.configuration`.

Signed-off-by: Mattt Zmuda <mattt@replicate.com>
  • Loading branch information
mattt committed Mar 21, 2024
1 parent e8147b3 commit 111e5c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
24 changes: 7 additions & 17 deletions replicate/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,14 @@ class Configuration(Resource):
The SKU for the hardware used to run the model.
"""

class Scaling(Resource):
"""
A scaling configuration for a deployment.
"""

min_instances: int
"""
The minimum number of instances for scaling.
"""

max_instances: int
"""
The maximum number of instances for scaling.
"""

scaling: Scaling
min_instances: int
"""
The scaling configuration for the deployment.
The minimum number of instances for scaling.
"""

max_instances: int
"""
The maximum number of instances for scaling.
"""

configuration: Configuration
Expand Down
23 changes: 14 additions & 9 deletions tests/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"configuration": {
"hardware": "gpu-t4",
"scaling": {"min_instances": 1, "max_instances": 5},
"min_instances": 1,
"max_instances": 5,
},
},
},
Expand Down Expand Up @@ -86,7 +87,8 @@
},
"configuration": {
"hardware": "gpu-t4",
"scaling": {"min_instances": 1, "max_instances": 5},
"min_instances": 1,
"max_instances": 5,
},
},
},
Expand All @@ -105,7 +107,8 @@
},
"configuration": {
"hardware": "cpu",
"scaling": {"min_instances": 2, "max_instances": 10},
"min_instances": 2,
"max_instances": 10,
},
},
},
Expand Down Expand Up @@ -136,7 +139,8 @@
},
"configuration": {
"hardware": "gpu-t4",
"scaling": {"min_instances": 1, "max_instances": 5},
"min_instances": 1,
"max_instances": 5,
},
},
},
Expand Down Expand Up @@ -166,7 +170,8 @@
},
"configuration": {
"hardware": "gpu-v100",
"scaling": {"min_instances": 2, "max_instances": 10},
"min_instances": 2,
"max_instances": 10,
},
},
},
Expand Down Expand Up @@ -352,8 +357,8 @@ async def test_create_deployment(async_flag):
assert deployment.current_release.created_by.username == "acme"
assert deployment.current_release.created_by.name == "Acme, Inc."
assert deployment.current_release.configuration.hardware == "gpu-t4"
assert deployment.current_release.configuration.scaling.min_instances == 1
assert deployment.current_release.configuration.scaling.max_instances == 5
assert deployment.current_release.configuration.min_instances == 1
assert deployment.current_release.configuration.max_instances == 5


@respx.mock
Expand Down Expand Up @@ -392,5 +397,5 @@ async def test_update_deployment(async_flag):
assert updated_deployment.current_release.model == "acme/esrgan-updated"
assert updated_deployment.current_release.version == "new-version-id"
assert updated_deployment.current_release.configuration.hardware == "gpu-v100"
assert updated_deployment.current_release.configuration.scaling.min_instances == 2
assert updated_deployment.current_release.configuration.scaling.max_instances == 10
assert updated_deployment.current_release.configuration.min_instances == 2
assert updated_deployment.current_release.configuration.max_instances == 10

0 comments on commit 111e5c2

Please sign in to comment.