Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(models): add method to show model usage #381

Merged

Conversation

cwetherill-ps
Copy link
Contributor

This inmplements a function in the Gradient Python package to access
current and historic deployments of one or more models. A user can
optionally filter on the basis of:

  • Model name;
  • Model project; and
  • Deployment cluster
    and can specify the max number of models (generally if no model name is
    specified) and number of recent deployments of each model to return in
    the result set.

By way of example:

>>> import json
>>> from gradient import models
>>>
>>>
>>> deployed_models = models.get_model_usage(
...     model_name='some-model',
...     projectId='asdf1234',
...     clusterId='4321fdsa',
...     num_models=10,
...     num_deployments=100,
...     api_key=os.getenv('PS_API_KEY')
... )
>>> print(
...     json.dumps(deployed_models, indent=4)
>>> )
[
    {
        "id": 1,
        "name": "sample-model",
        "dtCreated": "2022-01-14T15:12:48.092Z",
        "deploymentSpecs": {
            "nodes": [
                {
                    "id": "697dd23c-51d2-476e-8638-543e3c8a7cb9",
                    "dtCreated": "2022-01-14T15:13:54.087Z",
                    "externalApplied": "2022-01-20T00:07:45.848Z",
                    "actor": {
                        "fullName": null,
                        "email": "admin@paperspace.com"
                    },
                    "deployment": {
                        "name": "test-model",
                        "id": "c195321d-0e7d-4ba9-b747-933764bc9347"
                    },
                    "cluster": {
                        "fqdn": "local.paperspacegradient.com",
                        "name": "dev-cluster"
                    },
                    "endpointUrl": "dc195321d0e7d4ba9b747933764bc9347.local.paperspacegradient.com"
                },
                {
                    "id": "eb23e623-a6d3-44a8-a6bd-1820e2670d29",
                    "dtCreated": "2022-01-19T19:29:52.829Z",
                    "externalApplied": "2022-01-20T00:07:45.848Z",
                    "actor": {
                        "fullName": null,
                        "email": "admin@paperspace.com"
                    },
                    "deployment": {
                        "name": "test-model",
                        "id": "c195321d-0e7d-4ba9-b747-933764bc9347"
                    },
                    "cluster": {
                        "fqdn": "local.paperspacegradient.com",
                        "name": "dev-cluster"
                    },
                    "endpointUrl": "dc195321d0e7d4ba9b747933764bc9347.local.paperspacegradient.com"
                }
            ]
        }
    }
]

This inmplements a function in the Gradient Python package to access
current and historic deployments of one or more models. A user can
optionally filter on the basis of:
  - Model name;
  - Model project; and
  - Deployment cluster
and can specify the max number of models (generally if no model name is
specified) and number of recent deployments of each model to return in
the result set.

By way of example:
```
>>> import json
>>> from gradient import models
>>>
>>>
>>> deployed_models = models.get_model_usage(
...     model_name='some-model',
...     projectId='asdf1234',
...     clusterId='4321fdsa',
...     num_models=10,
...     num_deployments=100,
...     api_key=os.getenv('PS_API_KEY')
... )
>>> print(
...     json.dumps(deployed_models, indent=4)
>>> )
[
    {
        "id": 1,
        "name": "sample-model",
        "dtCreated": "2022-01-14T15:12:48.092Z",
        "deploymentSpecs": {
            "nodes": [
                {
                    "id": "697dd23c-51d2-476e-8638-543e3c8a7cb9",
                    "dtCreated": "2022-01-14T15:13:54.087Z",
                    "externalApplied": "2022-01-20T00:07:45.848Z",
                    "actor": {
                        "fullName": null,
                        "email": "admin@paperspace.com"
                    },
                    "deployment": {
                        "name": "test-model",
                        "id": "c195321d-0e7d-4ba9-b747-933764bc9347"
                    },
                    "cluster": {
                        "fqdn": "local.paperspacegradient.com",
                        "name": "dev-cluster"
                    },
                    "endpointUrl": "dc195321d0e7d4ba9b747933764bc9347.local.paperspacegradient.com"
                },
                {
                    "id": "eb23e623-a6d3-44a8-a6bd-1820e2670d29",
                    "dtCreated": "2022-01-19T19:29:52.829Z",
                    "externalApplied": "2022-01-20T00:07:45.848Z",
                    "actor": {
                        "fullName": null,
                        "email": "admin@paperspace.com"
                    },
                    "deployment": {
                        "name": "test-model",
                        "id": "c195321d-0e7d-4ba9-b747-933764bc9347"
                    },
                    "cluster": {
                        "fqdn": "local.paperspacegradient.com",
                        "name": "dev-cluster"
                    },
                    "endpointUrl": "dc195321d0e7d4ba9b747933764bc9347.local.paperspacegradient.com"
                }
            ]
        }
    }
]
```
@cwetherill-ps
Copy link
Contributor Author

as an aside, it looks like we're returning the actual id from the models table instead of its handle. Not a huge issue since it'll migrate to uuid w/the mlobject transition either way, but will need to circle back to API Next and fix up at some point

@cwetherill-ps cwetherill-ps merged commit 0daa2c7 into master Jan 21, 2022
@cwetherill-ps cwetherill-ps deleted the cwetherill/nb-384-access-the-model-associated-with-a branch January 21, 2022 20:06
@PSBOT
Copy link

PSBOT commented Jan 21, 2022

🎉 This PR is included in version 1.10.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@PSBOT PSBOT added the released label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants