Deployments Client

Importing

1
from gradient import gradient_deployments
2
api_key='YOUR_API_KEY'
Copied!

Create the deployment spec

You can either create a deployment spec within your script, or import one from a YAML file on disk. For example,
1
deployment_spec = {
2
'image': 'tensorflow/serving:latest-gpu',
3
'port': 8501,
4
'resources': {
5
'replicas': 2,
6
'instanceType': 'P4000'
7
},
8
'models': [{
9
'id': model.id,
10
'path': '/opt/models/'
11
}],
12
'env': [
13
{
14
'name': 'MODEL_BASE_PATH',
15
'value': '/opt/models'
16
}, {
17
'name': 'MODEL_NAME',
18
'value': 'my-tf-model'
19
}
20
]
21
}
22
23
# or, to load from a YAML file on disk
24
import yaml
25
26
27
deployment_spec = yaml.safe_load('my_spec.yaml')
Copied!

Create the deployment

We'll use the create_deployment method to create our new deployment. Optionally, we can also pass cluster_id=<cluster> if you want to deploy onto a specific private cluster. You can safely omit this field if you are not using private clusters.
1
deployment = gradient_deployments.create_deployment(
2
name='TensorFlow Serving Model',
3
project_id='asdf1234',
4
cluster_id='cluster1234',
5
spec=deployment_spec,
6
api_key=api_key
7
)
Copied!

Check the deployment status

We can monitor the status of our newly created deployment with the get_deployment function:
1
import json
2
3
4
deployment_info = gradient_deployments.get_deployment(
5
id=deployment['id'],
6
api_key=api_key
7
)
8
9
print(json.dumps(deployment_info, indent=4))
Copied!

Update the deployment

You can also modify an existing deployment at any time, and can change any of the attributes that you have specified in its deployment spec. For instance, here we are scaling the number of replicas in our deployment down to 0, and changing the instance type to a CPU-only option:
1
deployment_spec['resources']['replicas'] = 0
2
deployment_spec['resources']['instanceType'] = 'C4'
3
4
gradient_deployments.update_deployment(
5
id=deployment['id'],
6
project_id='asdf1234',
7
spec=deployment_spec,
8
api_key=api_key
9
)
Copied!

Delete a deployment

At any point, you can delete a deployment and remove it from the web console and from all CLI output:
1
gradient_deployments.delete_deployment(
2
id=deployment['id'],
3
api_key=api_key
4
)
Copied!

View and search existing deployments

We also provide a list_deployments method which allows you to view all active deployments. You can also optionally filter by any or all of cluster ID, project ID, and deployment name:
1
deployments = gradient_deployments.list_deployments(
2
cluster_id='cluster-id-1234',
3
project_id='asdf1234',
4
name='TensorFlow Serving Model',
5
api_key=api_key
6
)
Copied!
Last modified 1mo ago