Ejemplo n.º 1
0
 def choose_trial_to_run(
         self, trial_runner: "trial_runner.TrialRunner") -> Optional[Trial]:
     for trial in trial_runner.get_trials():
         if (trial.status == Trial.PENDING
                 and trial_runner.has_resources(trial.resources)):
             return trial
     for trial in trial_runner.get_trials():
         if (trial.status == Trial.PAUSED
                 and trial_runner.has_resources(trial.resources)):
             return trial
     return None
Ejemplo n.º 2
0
    def choose_trial_to_run(
            self, trial_runner: "trial_runner.TrialRunner") -> Optional[Trial]:
        """Ensures all trials get fair share of time (as defined by time_attr).

        This enables the PBT scheduler to support a greater number of
        concurrent trials than can fit in the cluster at any given time.
        """
        candidates = []
        for trial in trial_runner.get_trials():
            if trial.status in [Trial.PENDING, Trial.PAUSED] and \
                    trial_runner.has_resources(trial.resources):
                if not self._synch:
                    candidates.append(trial)
                elif self._trial_state[trial].last_train_time < \
                        self._next_perturbation_sync:
                    candidates.append(trial)
        candidates.sort(
            key=lambda trial: self._trial_state[trial].last_train_time)
        return candidates[0] if candidates else None
Ejemplo n.º 3
0
    def choose_trial_to_run(
            self, trial_runner: "trial_runner.TrialRunner") -> Optional[Trial]:
        """Fair scheduling within iteration by completion percentage.

        List of trials not used since all trials are tracked as state
        of scheduler. If iteration is occupied (ie, no trials to run),
        then look into next iteration.
        """

        for hyperband in self._hyperbands:
            # band will have None entries if no resources
            # are to be allocated to that bracket.
            scrubbed = [b for b in hyperband if b is not None]
            for bracket in sorted(
                    scrubbed, key=lambda b: b.completion_percentage()):
                for trial in bracket.current_trials():
                    if (trial.status == Trial.PENDING
                            and trial_runner.has_resources(trial.resources)):
                        return trial
        return None
Ejemplo n.º 4
0
    def choose_trial_to_run(self,
                            trial_runner: "trial_runner.TrialRunner",
                            allow_recurse: bool = True) -> Optional[Trial]:
        """Fair scheduling within iteration by completion percentage.

        List of trials not used since all trials are tracked as state
        of scheduler. If iteration is occupied (ie, no trials to run),
        then look into next iteration.
        """

        for hyperband in self._hyperbands:
            # band will have None entries if no resources
            # are to be allocated to that bracket.
            scrubbed = [b for b in hyperband if b is not None]
            for bracket in scrubbed:
                for trial in bracket.current_trials():
                    if (trial.status == Trial.PENDING
                            and trial_runner.has_resources(trial.resources)):
                        return trial
        # MAIN CHANGE HERE!
        if not any(t.status == Trial.RUNNING
                   for t in trial_runner.get_trials()):
            for hyperband in self._hyperbands:
                for bracket in hyperband:
                    if bracket and any(trial.status == Trial.PAUSED
                                       for trial in bracket.current_trials()):
                        # This will change the trial state
                        self._process_bracket(trial_runner, bracket)

                        # If there are pending trials now, suggest one.
                        # This is because there might be both PENDING and
                        # PAUSED trials now, and PAUSED trials will raise
                        # an error before the trial runner tries again.
                        if allow_recurse and any(
                                trial.status == Trial.PENDING
                                for trial in bracket.current_trials()):
                            return self.choose_trial_to_run(
                                trial_runner, allow_recurse=False)
        # MAIN CHANGE HERE!
        return None