Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion datamint/api/endpoints/deploy_model_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import httpx

from datamint.configs import DEFAULT_DEPLOY_MODEL_ALIAS
from datamint.entities.deployjob import DeployJob
from datamint.exceptions import JobTimeoutError, ResourceNotFoundError

Expand Down Expand Up @@ -182,7 +183,7 @@ def remove_image(self, model_name: str, tag: str | None = None) -> dict:
response = self._make_request('DELETE', f'/{self.endpoint_base}/image/{model_name}', params=params)
return response.json()

def image_exists(self, model_name: str, tag: str = "latest") -> bool:
def image_exists(self, model_name: str, tag: str = DEFAULT_DEPLOY_MODEL_ALIAS) -> bool:
"""Check if a model image exists."""
params = {'tag': tag}
response = self._make_request('GET', f'/{self.endpoint_base}/image/{model_name}/exists', params=params)
Expand Down
3 changes: 2 additions & 1 deletion datamint/api/endpoints/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mlflow.entities.model_registry import RegisteredModel as MlflowRegisteredModel

from datamint._repr_utils import render_html_card, render_text_block
from datamint.configs import DEFAULT_DEPLOY_MODEL_ALIAS
from datamint.entities.annotations.annotation_spec import AnnotationSpec
from datamint.mlflow.flavors.datamint_flavor import FLAVOR_NAME
from datamint.mlflow.models.tags import DATAMINT_LOGGED_MODEL_ID_TAG
Expand Down Expand Up @@ -198,7 +199,7 @@ def get_metrics(self, version: ModelVersion | None = None) -> dict[str, float]:
version = version or self.get_latest_version()
return version.get_metrics() if version else {}

def is_deployed(self, tag: str = 'latest') -> bool:
def is_deployed(self, tag: str = DEFAULT_DEPLOY_MODEL_ALIAS) -> bool:
return self._api._deploy_api.image_exists(self.name, tag=tag)

def get_projects(self) -> list['Project']:
Expand Down
9 changes: 3 additions & 6 deletions datamint/client_cmd_tools/datamint_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
api = Api()

# Deploy the model registered during training. This can take a few minutes.
deploy_job = api.deploy.start(model_name=MODEL_NAME, model_alias="latest")
deploy_job = api.deploy.start(model_name=MODEL_NAME)
print(f"Deploying '{MODEL_NAME}'... (this may take a few minutes)")

deploy_job = deploy_job.wait()
Expand All @@ -428,7 +428,6 @@

inf_job = api.inference.submit(
model_name=MODEL_NAME,
model_alias="latest",
resource_id=resource.id,
)
inf_job = inf_job.wait()
Expand Down Expand Up @@ -860,7 +859,7 @@
api = Api()

# Deploy the model registered during training. This can take a few minutes.
deploy_job = api.deploy.start(model_name=MODEL_NAME, model_alias="latest")
deploy_job = api.deploy.start(model_name=MODEL_NAME)
print(f"Deploying '{MODEL_NAME}'... (this may take a few minutes)")

deploy_job = deploy_job.wait()
Expand All @@ -875,7 +874,6 @@

inf_job = api.inference.submit(
model_name=MODEL_NAME,
model_alias="latest",
resource_id=resource.id,
)
inf_job = inf_job.wait()
Expand Down Expand Up @@ -1344,7 +1342,7 @@ def _overlay(ax, img_np, anns):
api = Api()

# Deploy the model registered during training. This can take a few minutes.
deploy_job = api.deploy.start(model_name=MODEL_NAME, model_alias="latest")
deploy_job = api.deploy.start(model_name=MODEL_NAME)
print(f"Deploying '{MODEL_NAME}'... (this may take a few minutes)")

deploy_job = deploy_job.wait()
Expand All @@ -1359,7 +1357,6 @@ def _overlay(ax, img_np, anns):

inf_job = api.inference.submit(
model_name=MODEL_NAME,
model_alias="latest",
resource_id=resource.id,
)
inf_job = inf_job.wait()
Expand Down
2 changes: 2 additions & 0 deletions datamint/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
APIURL_KEY: 'https://api.datamint.io'
}

DEFAULT_DEPLOY_MODEL_ALIAS = 'latest'

_LOGGER = logging.getLogger(__name__)

DIRS = PlatformDirs(appname='datamintapi')
Expand Down
5 changes: 4 additions & 1 deletion datamint/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from datamint.configs import DEFAULT_DEPLOY_MODEL_ALIAS


class DatamintException(Exception):
"""Base class for all Datamint exceptions."""

Expand Down Expand Up @@ -139,7 +142,7 @@ def __str__(self) -> str:
ref = f"{self.model_name}:{self.model_alias}"
deploy_kwarg = f"model_alias='{self.model_alias}'"
else:
ref = f"{self.model_name}:champion"
ref = f"{self.model_name}:{DEFAULT_DEPLOY_MODEL_ALIAS}"
deploy_kwarg = None

deploy_call = f"api.deploy_model.start('{self.model_name}'"
Expand Down
Loading