Example #1
0
def run_scheduled_optimizer_factory_case(config,
                                         iteration,
                                         epoch_truth=None,
                                         step_truth=None,
                                         option_name="defaultLearningRate"):
    """Runs a single case of the schedule optimizer factory tests. Simulates running through
    every step of every epoch required by the config, and updates the optimizer factory as
    defined by the schedule. Then checks the optimizer parameters to ensure they are correct."""
    if epoch_truth is None:
        epoch_truth = {}

    if step_truth is None:
        step_truth = {}

    factory = ScheduledOptimizerFactory(config, iteration)
    for iteration.epoch in range(iteration.epochs):
        for _ in range(iteration.steps_per_epoch):
            if factory.should_update(iteration):
                factory.update(iteration)

            if iteration.count in step_truth:
                lr = factory.option_values[option_name]
                assert lr == step_truth[iteration.count]
            iteration.count += 1

        if iteration.epoch in epoch_truth:
            lr = factory.option_values[option_name]
            assert lr == epoch_truth[iteration.epoch]
Example #2
0
    def test_case(config, iteration, epoch_truth={}, step_truth={}, option_name="defaultLearningRate"):
        factory = ScheduledOptimizerFactory(config, iteration)
        for iteration.epoch in range(iteration.epochs):
            for step in range(iteration.steps_per_epoch):
                if factory.should_update(iteration):
                    factory.update(iteration)

                if iteration.count in step_truth:
                    lr = factory.option_values[option_name]
                    assert(lr == step_truth[iteration.count])
                iteration.count += 1

            if iteration.epoch in epoch_truth:
                lr = factory.option_values[option_name]
                assert(lr == epoch_truth[iteration.epoch])