Skip to content
Open
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
2 changes: 1 addition & 1 deletion mlflow/tracking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def rename_experiment(self, experiment_id, new_name):
"""
self.store.rename_experiment(experiment_id, new_name)

def log_metric(self, run_id, key, value, timestamp=None):
def log_metric(self, run_id, key, value, timestamp=None, step=0):
"""
Log a metric against the run ID. If timestamp is not provided, uses
the current timestamp.
Expand Down
14 changes: 11 additions & 3 deletions mlflow/tracking/fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ActiveRun(Run): # pylint: disable=W0223

def __init__(self, run):
Run.__init__(self, run.info, run.data)
self.step = 0

def __enter__(self):
return self
Expand Down Expand Up @@ -186,15 +187,22 @@ def set_tag(key, value):
MlflowClient().set_tag(run_id, key, value)


def log_metric(key, value):
def log_metric(key, value, step=None):
"""
Log a metric under the current run, creating a run if necessary.

:param key: Metric name (string).
:param value: Metric value (float).
"""
run_id = _get_or_start_run().info.run_uuid
MlflowClient().log_metric(run_id, key, value, int(time.time()))
run = _get_or_start_run()
if step is None:
step = run.step
MlflowClient().log_metric(run_id=run.info.run_uuid,
key=key,
value=value,
timestamp=int(time.time()),
step=step)
run.step = step + 1 # Or just `step`?


def log_metrics(metrics):
Expand Down