get_best_result#

ResultGrid.get_best_result(metric: str | None = None, mode: str | None = None, scope: str = 'last', filter_nan_and_inf: bool = True) Result[source]#

Get the best result from all the trials run.

For metrics that are reported in a nested dict, use a slash-separated flat key to refer to the nested entry. For example, if a trial reports {"eval": {"metrics": {"loss": 0.1}}}, pass metric="eval/metrics/loss":

>>> best_result = result_grid.get_best_result(
...     metric="eval/metrics/loss", mode="min")

This works because Tune flattens reported result dicts with / as the default delimiter before tracking metrics.

Parameters:
  • metric – Key for trial info to order on. Defaults to the metric specified in your Tuner’s TuneConfig. For nested metrics, use a slash-separated flat key (e.g. "eval/metrics/loss").

  • mode – One of [min, max]. Defaults to the mode specified in your Tuner’s TuneConfig.

  • scope – One of [all, last, avg, last-5-avg, last-10-avg]. If scope=last, only look at each trial’s final step for metric, and compare across trials based on mode=[min,max]. If scope=avg, consider the simple average over all steps for metric and compare across trials based on mode=[min,max]. If scope=last-5-avg or scope=last-10-avg, consider the simple average over the last 5 or 10 steps for metric and compare across trials based on mode=[min,max]. If scope=all, find each trial’s min/max score for metric based on mode, and compare trials based on mode=[min,max].

  • filter_nan_and_inf – If True (default), NaN or infinite values are disregarded and these trials are never selected as the best trial.

Returns:

The Result corresponding to the best trial under the given metric, mode, and scope.