Skip to content

Commit

Permalink
[release/0.5] Fix fasttrackml python client (#907)
Browse files Browse the repository at this point in the history
Backport of #897
  • Loading branch information
fabiovincenzi authored Feb 14, 2024
1 parent 0bda8b4 commit 7cea4dc
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 309 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Binaries
dist/
fml
fasttrackml
*.exe
__debug_bin*

Expand All @@ -29,5 +28,4 @@ python/*.egg-info/
wheelhouse/

# Python package
!python/fasttrackml/
__pycache__/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ python-env: ## create python virtual environment.
.PHONY: python-dist
python-dist: go-build python-env ## build python wheels.
@echo '>>> Building Python Wheels.'
@VERSION=$(VERSION) pipenv run python3 -m pip wheel ./python/fasttrackml --wheel-dir=wheelhouse --no-deps
@VERSION=$(VERSION) pipenv run python3 -m pip wheel ./python --wheel-dir=wheelhouse --no-deps

.PHONY: python-format
python-format: python-env ## format python code.
Expand Down
1 change: 1 addition & 0 deletions python/LICENSE
1 change: 1 addition & 0 deletions python/README.md
109 changes: 0 additions & 109 deletions python/batch.py

This file was deleted.

1 change: 0 additions & 1 deletion python/fasttrackml/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion python/fasttrackml/README.md

This file was deleted.

8 changes: 5 additions & 3 deletions python/fasttrackml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import contextlib

import mlflow
from fasttrackml.client import FasttrackmlClient
from mlflow import *

from .client import FasttrackmlClient

del log_metric, log_metrics
from fasttrackml.fluent import log_metric, log_metrics
from .fluent import log_metric, log_metrics

__all__ = [name for name in dir() if name in dir(mlflow)]
__all__.append("FasttrackmlClient")

with contextlib.suppress(Exception):
from mlflow import gateway
from mlflow import gateway

__all__.append("gateway")
Empty file.
25 changes: 18 additions & 7 deletions python/fasttrackml/_tracking_service/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Dict, Optional, Sequence

from fasttrackml.entities.metric import Metric
from fasttrackml.store.custom_rest_store import CustomRestStore
from mlflow.entities import Param, RunTag
from mlflow.store.tracking import GET_METRIC_HISTORY_MAX_RESULTS
from mlflow.tracking._tracking_service.client import TrackingServiceClient
Expand All @@ -13,22 +11,35 @@
from mlflow.utils.time import get_current_time_millis
from mlflow.utils.validation import MAX_METRICS_PER_BATCH

from ..entities.metric import Metric
from ..store.custom_rest_store import CustomRestStore


class FasttrackmlTrackingServiceClient(TrackingServiceClient):

def __init__(self, tracking_uri):
super().__init__(tracking_uri)
self.custom_store = CustomRestStore(lambda: MlflowHostCreds(self.tracking_uri))

def log_metric(self, run_id: str, key:str, value:float, timestamp: Optional[int] = None, step:Optional[int] = None, context: Optional[dict] = None):
def log_metric(
self,
run_id: str,
key: str,
value: float,
timestamp: Optional[int] = None,
step: Optional[int] = None,
context: Optional[dict] = None,
):
timestamp = timestamp if timestamp is not None else get_current_time_millis()
step = step if step is not None else 0
context = context if context else {}
metric_value = convert_metric_value_to_float_if_possible(value)
metric = Metric(key, metric_value, timestamp, step, context)
self.custom_store.log_metric(run_id, metric)

def log_batch(self, run_id: str, metrics: Sequence[Metric]=(), params: Sequence[Param]=(), tags: Sequence[RunTag]=()):

def log_batch(
self, run_id: str, metrics: Sequence[Metric] = (), params: Sequence[Param] = (), tags: Sequence[RunTag] = ()
):
for metrics_batch in chunk_list(metrics, chunk_size=MAX_METRICS_PER_BATCH):
self.custom_store.log_batch(run_id=run_id, metrics=metrics_batch)

Expand Down Expand Up @@ -56,7 +67,7 @@ def get_metric_history(self, run_id, key):
history.extend(paged_history)
token = paged_history.token
return history

def get_metric_histories(
self,
experiment_ids: Optional[Sequence[str]] = None,
Expand All @@ -66,7 +77,7 @@ def get_metric_histories(
run_view_type: int = None,
max_results: int = 10000000,
search_all_experiments: bool = False,
experiment_names: Optional[Sequence[str]] = None,
experiment_names: Optional[Sequence[str]] = None,
context: Optional[Dict[str, object]] = None,
):
return self.custom_store.get_metric_histories(
Expand Down
Loading

0 comments on commit 7cea4dc

Please sign in to comment.