-
Notifications
You must be signed in to change notification settings - Fork 66
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: add artifact id and token endpoint #485
Changes from 6 commits
79b2ddd
3354305
e139141
4095648
08ab93b
33a710d
616cc44
006c201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,15 @@ def __init__( | |
|
||
def __str__(self): | ||
return f'{self.message} ({self.code}): {self.details}' | ||
|
||
|
||
class RunInProgressError(Exception): | ||
... | ||
|
||
|
||
class RunFailedError(Exception): | ||
... | ||
|
||
|
||
class UserNotLoginError(Exception): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserNotLoggedIn |
||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
from finetuner.client import FinetunerV1Client | ||
from finetuner.constants import ARTIFACTS_DIR, FINISHED, STATUS | ||
from finetuner.constants import ( | ||
ARTIFACT_ID, | ||
ARTIFACTS_DIR, | ||
CREATED, | ||
FAILED, | ||
STARTED, | ||
STATUS, | ||
) | ||
from finetuner.exception import RunFailedError, RunInProgressError | ||
from finetuner.hubble import download_artifact | ||
|
||
|
||
|
@@ -29,6 +37,7 @@ def __init__( | |
self._config = config | ||
self._created_at = created_at | ||
self._description = description | ||
self._run = self._get_run() | ||
|
||
@property | ||
def name(self) -> str: | ||
|
@@ -38,6 +47,12 @@ def name(self) -> str: | |
def config(self) -> dict: | ||
return self._config | ||
|
||
def _get_run(self) -> dict: | ||
"""Get Run object as dict.""" | ||
return self._client.get_run( | ||
experiment_name=self._experiment_name, run_name=self._name | ||
) | ||
|
||
def status(self) -> dict: | ||
"""Run status. | ||
|
||
|
@@ -56,18 +71,40 @@ def logs(self) -> str: | |
experiment_name=self._experiment_name, run_name=self._name | ||
) | ||
|
||
def _check_run_status(self): | ||
status = self.status()[STATUS] | ||
if status in [CREATED, STARTED]: | ||
raise RunInProgressError( | ||
'The run needs to be finished in order to save the model.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save the artifact |
||
) | ||
if status == FAILED: | ||
raise RunFailedError( | ||
'The run failed, please check the `logs` for detailed information.' | ||
) | ||
|
||
def save_artifact(self, directory: str = ARTIFACTS_DIR) -> str: | ||
"""Save artifact if the run is finished. | ||
|
||
:param directory: Directory where the artifact will be stored. | ||
:returns: A string object that indicates the download path. | ||
""" | ||
if self.status()[STATUS] != FINISHED: | ||
raise Exception('The run needs to be finished in order to save the model.') | ||
|
||
self._check_run_status() | ||
return download_artifact( | ||
client=self._client, | ||
experiment_name=self._experiment_name, | ||
artifact_id=self._run[ARTIFACT_ID], | ||
run_name=self._name, | ||
directory=directory, | ||
) | ||
|
||
def artifact_id(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a property. Otherwise rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well I think all should be properties 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having static ones as properties and non-statics with |
||
"""Get artifact id from the run. | ||
|
||
An artifact in finetuner contains fine-tuned model and its metadata. | ||
Such as preprocessing function, collate function. This id could be useful | ||
if you want to directly pull the artifact from the cloud storage, such as | ||
using `FinetunerExecutor`. | ||
|
||
:return: Artifact id as string object. | ||
""" | ||
self._check_run_status() | ||
return self._run[ARTIFACT_ID] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the docstring is confusing. This function does not download the artifact