Пример #1
0
    def testAlternateMetrics(self):
        def result2(t, rew):
            return TrainingResult(training_iteration=t, neg_mean_loss=rew)

        scheduler = AsyncHyperBandScheduler(
            grace_period=1, time_attr='training_iteration',
            reward_attr='neg_mean_loss', brackets=1)
        t1 = Trial("PPO")  # mean is 450, max 900, t_max=10
        t2 = Trial("PPO")  # mean is 450, max 450, t_max=5
        scheduler.on_trial_add(None, t1)
        scheduler.on_trial_add(None, t2)
        for i in range(10):
            self.assertEqual(
                scheduler.on_trial_result(None, t1, result2(i, i * 100)),
                TrialScheduler.CONTINUE)
        for i in range(5):
            self.assertEqual(
                scheduler.on_trial_result(None, t2, result2(i, 450)),
                TrialScheduler.CONTINUE)
        scheduler.on_trial_complete(None, t1, result2(10, 1000))
        self.assertEqual(
            scheduler.on_trial_result(None, t2, result2(5, 450)),
            TrialScheduler.CONTINUE)
        self.assertEqual(
            scheduler.on_trial_result(None, t2, result2(6, 0)),
            TrialScheduler.CONTINUE)
Пример #2
0
    def testAsyncHBAllCompletes(self):
        scheduler = AsyncHyperBandScheduler(max_t=10, brackets=10)
        trials = [Trial("PPO") for i in range(10)]
        for t in trials:
            scheduler.on_trial_add(None, t)

        for t in trials:
            self.assertEqual(
                scheduler.on_trial_result(None, t, result(10, -2)),
                TrialScheduler.STOP)
Пример #3
0
    def testAsyncHBAllCompletes(self):
        scheduler = AsyncHyperBandScheduler(
            max_t=10, brackets=10)
        trials = [Trial("PPO") for i in range(10)]
        for t in trials:
            scheduler.on_trial_add(None, t)

        for t in trials:
            self.assertEqual(
                scheduler.on_trial_result(None, t, result(10, -2)),
                TrialScheduler.STOP)
Пример #4
0
 def testAsyncHBOnComplete(self):
     scheduler = AsyncHyperBandScheduler(max_t=10, brackets=1)
     t1, t2 = self.basicSetup(scheduler)
     t3 = Trial("PPO")
     scheduler.on_trial_add(None, t3)
     scheduler.on_trial_complete(None, t3, result(10, 1000))
     self.assertEqual(scheduler.on_trial_result(None, t2, result(101, 0)),
                      TrialScheduler.STOP)
Пример #5
0
 def testAsyncHBGracePeriod(self):
     scheduler = AsyncHyperBandScheduler(grace_period=2.5,
                                         reduction_factor=3,
                                         brackets=1)
     t1, t2 = self.basicSetup(scheduler)
     scheduler.on_trial_complete(None, t1, result(10, 1000))
     scheduler.on_trial_complete(None, t2, result(10, 1000))
     t3 = Trial("PPO")
     scheduler.on_trial_add(None, t3)
     self.assertEqual(scheduler.on_trial_result(None, t3, result(1, 10)),
                      TrialScheduler.CONTINUE)
     self.assertEqual(scheduler.on_trial_result(None, t3, result(2, 10)),
                      TrialScheduler.CONTINUE)
     self.assertEqual(scheduler.on_trial_result(None, t3, result(3, 10)),
                      TrialScheduler.STOP)
Пример #6
0
 def testAsyncHBUsesPercentile(self):
     scheduler = AsyncHyperBandScheduler(
         grace_period=1, max_t=10, reduction_factor=2, brackets=1)
     t1, t2 = self.basicSetup(scheduler)
     scheduler.on_trial_complete(None, t1, result(10, 1000))
     scheduler.on_trial_complete(None, t2, result(10, 1000))
     t3 = Trial("PPO")
     scheduler.on_trial_add(None, t3)
     self.assertEqual(
         scheduler.on_trial_result(None, t3, result(1, 260)),
         TrialScheduler.STOP)
     self.assertEqual(
         scheduler.on_trial_result(None, t3, result(2, 260)),
         TrialScheduler.STOP)
Пример #7
0
 def testAsyncHBGracePeriod(self):
     scheduler = AsyncHyperBandScheduler(
         grace_period=2.5, reduction_factor=3, brackets=1)
     t1, t2 = self.basicSetup(scheduler)
     scheduler.on_trial_complete(None, t1, result(10, 1000))
     scheduler.on_trial_complete(None, t2, result(10, 1000))
     t3 = Trial("PPO")
     scheduler.on_trial_add(None, t3)
     self.assertEqual(
         scheduler.on_trial_result(None, t3, result(1, 10)),
         TrialScheduler.CONTINUE)
     self.assertEqual(
         scheduler.on_trial_result(None, t3, result(2, 10)),
         TrialScheduler.CONTINUE)
     self.assertEqual(
         scheduler.on_trial_result(None, t3, result(3, 10)),
         TrialScheduler.STOP)
Пример #8
0
 def testAsyncHBOnComplete(self):
     scheduler = AsyncHyperBandScheduler(
         max_t=10, brackets=1)
     t1, t2 = self.basicSetup(scheduler)
     t3 = Trial("PPO")
     scheduler.on_trial_add(None, t3)
     scheduler.on_trial_complete(None, t3, result(10, 1000))
     self.assertEqual(
         scheduler.on_trial_result(None, t2, result(101, 0)),
         TrialScheduler.STOP)
register_trainable("my_class", MyTrainableClass)

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--smoke-test",
                        action="store_true",
                        help="Finish quickly for testing")
    args, _ = parser.parse_known_args()
    ray.init()

    # asynchronous hyperband early stopping, configured with
    # `episode_reward_mean` as the
    # objective and `timesteps_total` as the time unit.
    ahb = AsyncHyperBandScheduler(time_attr="timesteps_total",
                                  reward_attr="episode_reward_mean",
                                  grace_period=5,
                                  max_t=100)

    run_experiments(
        {
            "asynchyperband_test": {
                "run": "my_class",
                "stop": {
                    "training_iteration": 1 if args.smoke_test else 99999
                },
                "repeat": 20,
                "resources": {
                    "cpu": 1,
                    "gpu": 0
                },
                "config": {
Пример #10
0
    parser = argparse.ArgumentParser()
    parser.add_argument("--smoke-test",
                        action="store_true",
                        help="Finish quickly for testing")
    args, _ = parser.parse_known_args()
    ray.init(redirect_output=True)

    register_trainable("exp", easy_objective)

    space = {
        'width': hp.uniform('width', 0, 20),
        'height': hp.uniform('height', -100, 100),
        'activation': hp.choice("activation", ["relu", "tanh"])
    }

    config = {
        "my_exp": {
            "run": "exp",
            "repeat": 10 if args.smoke_test else 1000,
            "stop": {
                "training_iteration": 100
            },
        }
    }
    algo = HyperOptSearch(config,
                          space,
                          max_concurrent=4,
                          reward_attr="neg_mean_loss")
    scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
    run_experiments(search_alg=algo, scheduler=scheduler)
Пример #11
0
                        help='Size of Hidden Layer (default: 128)')
    parser.add_argument('--dropout2',
                        type=float,
                        default=0.5,
                        help='Size of first kernel (default: 0.5)')
    return parser


if __name__ == '__main__':
    parser = create_parser()
    args = parser.parse_args()
    mnist.load_data()  # we do this because it's not threadsafe

    ray.init()
    sched = AsyncHyperBandScheduler(time_attr="timesteps_total",
                                    reward_attr="mean_accuracy",
                                    max_t=400,
                                    grace_period=20)
    tune.register_trainable("train_mnist",
                            lambda cfg, rprtr: train_mnist(args, cfg, rprtr))
    tune.run_experiments(
        {
            "exp": {
                "stop": {
                    "mean_accuracy": 0.99,
                    "timesteps_total": 10 if args.smoke_test else 300
                },
                "run": "train_mnist",
                "repeat": 1 if args.smoke_test else 10,
                "config": {
                    "lr": lambda spec: np.random.uniform(0.001, 0.1),
                    "momentum": lambda spec: np.random.uniform(0.1, 0.9),
Пример #12
0
register_trainable("my_class", MyTrainableClass)

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--smoke-test", action="store_true", help="Finish quickly for testing")
    args, _ = parser.parse_known_args()
    ray.init()

    # asynchronous hyperband early stopping, configured with
    # `episode_reward_mean` as the
    # objective and `training_iteration` as the time unit,
    # which is automatically filled by Tune.
    ahb = AsyncHyperBandScheduler(
        time_attr="training_iteration",
        reward_attr="episode_reward_mean",
        grace_period=5,
        max_t=100)

    run_experiments(
        {
            "asynchyperband_test": {
                "run": "my_class",
                "stop": {
                    "training_iteration": 1 if args.smoke_test else 99999
                },
                "repeat": 20,
                "trial_resources": {
                    "cpu": 1,
                    "gpu": 0
                },
Пример #13
0
                        action='store_true',
                        help='Finish quickly for testing')
    args, _ = parser.parse_known_args()

    register_trainable('train_mnist', train)
    mnist_spec = {
        'run': 'train_mnist',
        'repeat': 10,
        'stop': {
            'mean_accuracy': 0.99,
            'timesteps_total': 600,
        },
        'config': {
            'activation': grid_search(['relu', 'elu', 'tanh']),
        },
    }

    if args.smoke_test:
        mnist_spec['stop']['training_iteration'] = 2
        mnist_spec['repeat'] = 1

    ray.init()

    from ray.tune.async_hyperband import AsyncHyperBandScheduler
    run_experiments({'tune_mnist_test': mnist_spec},
                    scheduler=AsyncHyperBandScheduler(
                        time_attr="timesteps_total",
                        reward_attr="mean_accuracy",
                        max_t=600,
                    ))