Skip to content

Commit

Permalink
Initial publishing commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bw27492 committed Feb 22, 2024
1 parent 79283eb commit e997535
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
26 changes: 26 additions & 0 deletions lib/python-beta/src/bailo/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ def filter_none(json: dict[str, Any]) -> dict[str, Any]:
"""
res = {k: v for k, v in json.items() if v is not None}
return res


class NestedDict(dict):
def __getitem__(self,keytuple):
# if key is not a tuple then access as normal
if not isinstance(keytuple, tuple):
return super(NestedDict,self).__getitem__(keytuple)
d = self
for key in keytuple:
d = d[key]
return d
def __setitem__(self, keytuple, item):
# if key is not a tuple then access as normal
if not isinstance(keytuple, tuple):
return super(NestedDict,self).__setitem__(keytuple, item)
d = self
for index, key in enumerate(keytuple):
if index != len(keytuple) - 1:
try:
d = d[key]
except:
d[key] = {}
d = d[key]

else:
d[key] = item
21 changes: 17 additions & 4 deletions lib/python-beta/src/bailo/helper/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bailo.core.enums import ModelVisibility
from bailo.helper.release import Release
from bailo.core.exceptions import BailoException
from bailo.core.utils import NestedDict

from semantic_version import Version

Expand Down Expand Up @@ -316,12 +317,12 @@ def log_params(self, params: dict[str, Any]):
def log_metrics(self, metrics: dict[str, Any]):
self.run_data["metrics"].append(metrics)

def log_artifacts(self, artifacts: str):
def log_artifacts(self, artifacts: dict[str, Any]):
self.run_data["artifiacts"].append(artifacts)

def from_mlflow(self, tracking_uri: str, experiment_id: str):
if ml_flow == 1:
client = mlflow.tracking.MlflowClient(tracking_uri=tracking_uri) #should this be here? or passed in?
client = mlflow.tracking.MlflowClient(tracking_uri=tracking_uri)
runs = client.search_runs(experiment_id)

for run in runs:
Expand All @@ -333,5 +334,17 @@ def from_mlflow(self, tracking_uri: str, experiment_id: str):
raise ImportError("Optional MLFlow dependencies (needed for this method) are not installed.")


def publish(release_version: str, card_version: str):
pass
def publish(self, mc_loc: str, run_id: str):
mc = self.model.model_card
mc = NestedDict(mc)

for run in self.raw:
if run["run"] == run_id:
sel_run = run
else:
continue

sel_run = sel_run['params'] + sel_run['metrics']

mc[tuple(mc_loc.split('.'))] = sel_run
self.model.update_model_card(model_card=mc)

0 comments on commit e997535

Please sign in to comment.