Skip to content

Commit

Permalink
[tune] Fix current best trial progress string for metric=0 (ray-proje…
Browse files Browse the repository at this point in the history
…ct#26943)

Signed-off-by: Kai Fricke <[email protected]>
Signed-off-by: Stefan van der Kleij <[email protected]>
  • Loading branch information
krfricke authored and Stefan van der Kleij committed Aug 18, 2022
1 parent 1c9279e commit 562634b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/ray/tune/progress_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _current_best_trial(self, trials: List[Trial]):
continue
if metric not in t.last_result:
continue
if not best_metric or t.last_result[metric] * metric_op > best_metric:
if not best_trial or t.last_result[metric] * metric_op > best_metric:
best_metric = t.last_result[metric] * metric_op
best_trial = t
return best_trial, metric
Expand Down
15 changes: 15 additions & 0 deletions python/ray/tune/tests/test_progress_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
detect_reporter,
time_passed_str,
trial_progress_str,
TuneReporterBase,
)
from ray.tune.result import AUTO_RESULT_KEYS
from ray.tune.trial import Trial
Expand Down Expand Up @@ -471,6 +472,20 @@ def testBestTrialStr(self):
result = best_trial_str(trial, "metric", parameter_columns=["nested/conf"])
self.assertIn("nested_value", result)

def testBestTrialZero(self):
trial1 = Trial("", config={}, stub=True)
trial1.last_result = {"metric": 7, "config": {}}

trial2 = Trial("", config={}, stub=True)
trial2.last_result = {"metric": 0, "config": {}}

trial3 = Trial("", config={}, stub=True)
trial3.last_result = {"metric": 2, "config": {}}

reporter = TuneReporterBase(metric="metric", mode="min")
best_trial, metric = reporter._current_best_trial([trial1, trial2, trial3])
assert best_trial == trial2

def testTimeElapsed(self):
# Sun Feb 7 14:18:40 2016 -0800
# (time of the first Ray commit)
Expand Down

0 comments on commit 562634b

Please sign in to comment.