Ejemplo n.º 1
0
 def __init__(self, trial, searcher_config, training_history: dict,
              config_history: dict):
     self.trial = trial
     self.training_history = training_history
     self.training_history[trial] = []
     self.searcher_config = EasyDict(deepcopy(searcher_config))
     self.config_history = config_history
     self.trial_started = time.time()
     self.last_reported_time = self.trial_started
     self.last_result = None
def get_efficientnet_blockargs():
    """ Creates a predefined efficientnet model, which searched by original paper. """
    blocks_args = [
        EasyDict(kernel=3,
                 num_repeat=1,
                 channels=16,
                 expand_ratio=1,
                 stride=1,
                 se_ratio=0.25,
                 in_channels=32),
        EasyDict(kernel=3,
                 num_repeat=2,
                 channels=24,
                 expand_ratio=6,
                 stride=2,
                 se_ratio=0.25,
                 in_channels=16),
        EasyDict(kernel=5,
                 num_repeat=2,
                 channels=40,
                 expand_ratio=6,
                 stride=2,
                 se_ratio=0.25,
                 in_channels=24),
        EasyDict(kernel=3,
                 num_repeat=3,
                 channels=80,
                 expand_ratio=6,
                 stride=2,
                 se_ratio=0.25,
                 in_channels=40),
        EasyDict(kernel=5,
                 num_repeat=3,
                 channels=112,
                 expand_ratio=6,
                 stride=1,
                 se_ratio=0.25,
                 in_channels=80),
        EasyDict(kernel=5,
                 num_repeat=4,
                 channels=192,
                 expand_ratio=6,
                 stride=2,
                 se_ratio=0.25,
                 in_channels=112),
        EasyDict(kernel=3,
                 num_repeat=1,
                 channels=320,
                 expand_ratio=6,
                 stride=1,
                 se_ratio=0.25,
                 in_channels=192),
    ]
    return blocks_args
Ejemplo n.º 3
0
class LocalReporter:
    """
    Reporter implementation for LocalSequentialScheduler
    """
    def __init__(self, trial, searcher_config, training_history: dict,
                 config_history: dict):
        self.trial = trial
        self.training_history = training_history
        self.training_history[trial] = []
        self.searcher_config = EasyDict(deepcopy(searcher_config))
        self.config_history = config_history
        self.trial_started = time.time()
        self.last_reported_time = self.trial_started
        self.last_result = None

    def __call__(self, *args, **kwargs):
        result = deepcopy(kwargs)
        if 'done' not in result:
            result['trial'] = self.trial

            now = time.time()
            result['time_this_iter'] = now - self.last_reported_time
            result['time_since_start'] = now - self.trial_started
            self.last_reported_time = now

            self.training_history[self.trial].append(result)

            if self.trial not in self.config_history:
                self.config_history[self.trial] = self.searcher_config
                if 'util_args' in self.searcher_config:
                    self.searcher_config.pop('util_args')

            self.last_result = result

    def terminate(self):
        pass  # compatibility
Ejemplo n.º 4
0
 def run_job_(self, task_id, searcher_config, reporter):
     args = deepcopy(EasyDict(self.train_fn.kwvars))
     args['task_id'] = task_id
     self.searcher.register_pending(searcher_config)
     is_failed = False
     try:
         result = self.train_fn(args,
                                config=searcher_config,
                                reporter=reporter)
         if type(reporter) is not FakeReporter and reporter.last_result:
             self.searcher.update(config=searcher_config,
                                  **reporter.last_result)
     except Exception as e:
         logger.error(f'Exception during a trial: {e}')
         self.searcher.evaluation_failed(config=searcher_config)
         reporter(traceback=e)
         is_failed = True
         result = {'traceback': str(e)}
     return is_failed, result
Ejemplo n.º 5
0
    def run_trial(self, task_id=0) -> Tuple[bool, float, float]:
        """
        Start a trial with a given task_id

        Parameters
        ----------
        task_id
            task

        Returns
        -------
        is_failed: bool
            True if task completed successfully
        trial_start_time
            Trial start time
        trial_end_time
            Trial end time

        """
        searcher_config = self.searcher.get_config()
        reporter = LocalReporter(task_id, searcher_config,
                                 self.training_history, self.config_history)
        args = deepcopy(EasyDict(self.train_fn.kwvars))
        args['task_id'] = task_id
        self.searcher.register_pending(searcher_config)
        is_failed = False
        try:
            self.train_fn(args, config=searcher_config, reporter=reporter)
            if reporter.last_result:
                self.searcher.update(config=searcher_config,
                                     **reporter.last_result)
        except Exception as e:
            logger.error(f'Exception during a trial: {e}')
            self.searcher.evaluation_failed(config=searcher_config)
            reporter(traceback=e)
            is_failed = True
        return is_failed