Skip to content

Commit

Permalink
Merge pull request #45 from gizatechxyz/feature/add-ezkl-deployments
Browse files Browse the repository at this point in the history
Add EZKL deployments
  • Loading branch information
Gonmeso authored Feb 19, 2024
2 parents fb01626 + edab4c8 commit 80362b5
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Giza CLI 0.11.0
description: Giza CLI 0.12.0
---

# Giza CLI
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/full_transpilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pip install -r requirements.txt
Or:

```bash
pip install giza-cli==0.11.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0
pip install giza-cli==0.12.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0
```

We will use the libraries for the following purposes:
Expand Down
2 changes: 1 addition & 1 deletion examples/mnist/mnist_pytorch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Or:\n",
"\n",
"```bash\n",
"pip install giza-cli==0.11.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0\n",
"pip install giza-cli==0.12.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0\n",
"```\n",
"\n",
"We will use the libraries for the following purposes:\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/mnist/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
giza-cli==0.11.0
giza-cli==0.12.0
onnx==1.14.1
tf2onnx==1.15.1
torch==2.1.0
Expand Down
2 changes: 1 addition & 1 deletion giza/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

__version__ = "0.11.0"
__version__ = "0.12.0"
# Until DNS is fixed
API_HOST = os.environ.get("GIZA_API_HOST", "https://api.gizatech.xyz")
6 changes: 2 additions & 4 deletions giza/commands/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from giza import API_HOST
from giza.client import DeploymentsClient
from giza.frameworks import cairo
from giza.frameworks import cairo, ezkl
from giza.options import DEBUG_OPTION
from giza.schemas.deployments import DeploymentsList
from giza.schemas.proofs import Proof, ProofList
Expand Down Expand Up @@ -38,9 +38,7 @@ def deploy(
data=data, model_id=model_id, version_id=version_id, size=size, debug=debug
)
elif framework == Framework.EZKL:
raise NotImplementedError(
"EZKL deployment is not yet supported, please use Cairo instead"
)
ezkl.deploy(model_id=model_id, version_id=version_id, size=size, debug=debug)
else:
raise typer.BadParameter(
f"Framework {framework} is not supported, please use one of the following: {Framework.CAIRO}, {Framework.EZKL}"
Expand Down
80 changes: 78 additions & 2 deletions giza/frameworks/ezkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
from requests import HTTPError
from rich import print_json
from rich.live import Live
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.progress import Progress, Spinner, SpinnerColumn, TextColumn

from giza import API_HOST
from giza.client import (
DeploymentsClient,
JobsClient,
ModelsClient,
ProofsClient,
VersionJobsClient,
VersionsClient,
)
from giza.options import DEBUG_OPTION
from giza.schemas.deployments import DeploymentCreate, DeploymentsList
from giza.schemas.jobs import Job, JobCreate
from giza.schemas.models import ModelCreate
from giza.schemas.proofs import Proof
from giza.schemas.versions import VersionCreate, VersionStatus, VersionUpdate
from giza.utils import Echo, get_response_info
from giza.utils.enums import Framework, JobKind, JobSize, JobStatus
from giza.utils.enums import Framework, JobKind, JobSize, JobStatus, ServiceSize


def setup(
Expand Down Expand Up @@ -314,3 +317,76 @@ def verify(
if debug:
raise e
sys.exit(1)


def deploy(
model_id: int,
version_id: int,
size: ServiceSize = ServiceSize.S,
debug: Optional[bool] = DEBUG_OPTION,
) -> str:
"""
Command to deploy a specific version of a model. This will create a deployment for the specified version and check the status, once it finishes if COMPLETED the deployment is ready to be used.
Args:
model_id: model id to deploy
version_id: version id to deploy
size: Size of the service, allowed values are S, M, L and XL. Defaults to S.
debug (Optional[bool], optional): Whether to add debug information, will show requests, extra logs and traceback if there is an Exception. Defaults to DEBUG_OPTION (False).
Raises:
ValidationError: input fields are validated, if these are not suitable the exception is raised
HTTPError: request error to the API, 4XX or 5XX
"""
try:
echo = Echo(debug=debug)
client = DeploymentsClient(API_HOST)

deployments_list: DeploymentsList = client.list(model_id, version_id)
deployments: dict = json.loads(deployments_list.json())

if len(deployments) > 0:
echo.info(
f"Deployment for model id {model_id} and version id {version_id} already exists! ✅"
)
echo.info(f"Deployment id -> {deployments[0]['id']} ✅")
echo.info(f'You can start doing inferences at: {deployments[0]["uri"]} 🚀')
sys.exit(1)

spinner = Spinner(name="aesthetic", text="Creating deployment!")

with Live(renderable=spinner):
deployment = client.create(
model_id,
version_id,
DeploymentCreate(
size=size,
model_id=model_id,
version_id=version_id,
framework=Framework.EZKL,
),
None,
)
except ValidationError as e:
echo.error("Deployment validation error")
echo.error("Review the provided information")
if debug:
raise e
echo.error(str(e))
sys.exit(1)
except HTTPError as e:
info = get_response_info(e.response)
echo.error("⛔️Could not create the deployment")
echo.error(f"⛔️Detail -> {info.get('detail')}⛔️")
echo.error(f"⛔️Status code -> {info.get('status_code')}⛔️")
echo.error(f"⛔️Error message -> {info.get('content')}⛔️")
echo.error(
f"⛔️Request ID: Give this to an administrator to trace the error -> {info.get('request_id')}⛔️"
) if info.get("request_id") else None
if debug:
raise e
sys.exit(1)
echo("Deployment is successful ✅")
echo(f"Deployment created with id -> {deployment.id} ✅")
echo(f"Deployment created with endpoint URL: {deployment.uri} 🎉")
return deployment
3 changes: 2 additions & 1 deletion giza/schemas/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from giza.utils.enums import ServiceSize
from giza.utils.enums import Framework, ServiceSize


class DeploymentCreate(BaseModel):
Expand All @@ -13,6 +13,7 @@ class DeploymentCreate(BaseModel):
status: Optional[str] = None
size: ServiceSize
service_name: Optional[str] = None
framework: Framework


class Deployment(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "giza-cli"
version = "0.11.0"
version = "0.12.0"
description = "CLI for interacting with Giza"
authors = ["Gonzalo Mellizo-Soto <[email protected]>"]
readme = "README.md"
Expand Down
71 changes: 55 additions & 16 deletions tests/commands/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from requests import HTTPError

from giza.commands.deployments import DeploymentsClient, cairo
from giza.frameworks import ezkl
from giza.schemas.deployments import Deployment, DeploymentsList
from tests.conftest import invoke_cli_runner

Expand Down Expand Up @@ -30,23 +31,61 @@ def test_deploy_with_cairo_framework():


def test_deploy_with_ezkl_framework():
result = invoke_cli_runner(
[
"deployments",
"deploy",
"--model-id",
"1",
"--version-id",
"1",
"--framework",
"EZKL",
"--size",
"S",
"data_path",
],
expected_error=True,
with patch.object(ezkl, "deploy") as mock_deploy:
result = invoke_cli_runner(
[
"deployments",
"deploy",
"--model-id",
"1",
"--version-id",
"1",
"--framework",
"EZKL",
"--size",
"S",
"data_path",
],
)
mock_deploy.assert_called_once()
assert result.exit_code == 0


def test_deploy_ezkl_existing_deployment():
deploy_list = DeploymentsList(
__root__=[
Deployment(
id=1,
status="COMPLETED",
uri="https://giza-api.com/deployments/1",
size="S",
service_name="giza-deployment-1",
model_id=1,
version_id=1,
),
]
)
assert "EZKL deployment is not yet supported" in str(result.exception)
with patch.object(
DeploymentsClient, "list", return_value=deploy_list
) as mock_deploy:
result = invoke_cli_runner(
[
"deployments",
"deploy",
"--model-id",
"1",
"--version-id",
"1",
"--framework",
"EZKL",
"--size",
"S",
"data_path",
],
expected_error=True,
)
mock_deploy.assert_called_once()
assert "already exists" in result.stdout


def test_deploy_with_unsupported_framework():
Expand Down

0 comments on commit 80362b5

Please sign in to comment.