python/ray/tune/tests/test_experiment_analysis.py
def testGetBestCheckpointNan(self):
        """Tests if nan values are excluded from best checkpoint."""
        metric = "loss"

        def train(config):
            for i in range(config["steps"]):
                if i == 0:
                    value = float("nan")
                else:
                    value = i
                result = {metric: value}
                with tune.checkpoint_dir(step=i):
                    pass
                tune.report(**result)

        ea = tune.run(train, local_dir=self.test_dir, config={"steps": 3})
        best_trial = ea.get_best_trial(metric, mode="min")
        best_checkpoint = ea.get_best_checkpoint(best_trial, metric, mode="min")
        checkpoints_metrics = ea.get_trial_checkpoints_paths(best_trial, metric=metric)
        expected_checkpoint_no_nan = min(
            [
                checkpoint_metric
                for checkpoint_metric in checkpoints_metrics
                if not is_nan(checkpoint_metric[1])
            ],
            key=lambda x: x[1],
        )[0]
        assert best_checkpoint == expected_checkpoint_no_nan
Tests if nan values are excluded from best checkpoint.
Tests if nan values are excluded from best checkpoint.
Tests if nan values are excluded from best checkpoint .
def testGetBestCheckpointNan(self):
        metric = "loss"
        def train(config):
            for i in range(config["steps"]):
                if i == 0:
                    value = float("nan")
                else:
                    value = i
                result = {metric: value}
                with tune.checkpoint_dir(step=i):
                    pass
                tune.report(**result)
        ea = tune.run(train, local_dir=self.test_dir, config={"steps": 3})
        best_trial = ea.get_best_trial(metric, mode="min")
        best_checkpoint = ea.get_best_checkpoint(best_trial, metric, mode="min")
        checkpoints_metrics = ea.get_trial_checkpoints_paths(best_trial, metric=metric)
        expected_checkpoint_no_nan = min(
            [
                checkpoint_metric
                for checkpoint_metric in checkpoints_metrics
                if not is_nan(checkpoint_metric[1])
            ],
            key=lambda x: x[1],
        )[0]
        assert best_checkpoint == expected_checkpoint_no_nan
def testGetBestCheckpointNan ( self ) : metric = "loss" def train ( config ) : for i in range ( config [ "steps" ] ) : if i == 0 : value = float ( "nan" ) else : value = i result = { metric : value } with tune . checkpoint_dir ( step = i ) : pass tune . report ( ** result ) ea = tune . run ( train , local_dir = self . test_dir , config = { "steps" : 3 } ) best_trial = ea . get_best_trial ( metric , mode = "min" ) best_checkpoint = ea . get_best_checkpoint ( best_trial , metric , mode = "min" ) checkpoints_metrics = ea . get_trial_checkpoints_paths ( best_trial , metric = metric ) expected_checkpoint_no_nan = min ( [ checkpoint_metric for checkpoint_metric in checkpoints_metrics if not is_nan ( checkpoint_metric [ 1 ] ) ] , key = lambda x : x [ 1 ] , ) [ 0 ] assert best_checkpoint == expected_checkpoint_no_nan
Tests if nan values are excluded from best checkpoint.
Tests if nan values are excluded from best checkpoint .
"""Tests if nan values are excluded from best checkpoint."""
self