예제 #1
0
    def run(self):
        if self.num_trials >= self.total_trials:
            self._exit()

        has_told_study = []

        for trial_idx in range(self.num_trials):
            work_name = f"objective_work_{trial_idx}"
            if work_name not in self.ws:
                objective_work = ObjectiveWork(
                    script_path=self.script_path,
                    data_dir=self.data_dir,
                    cloud_compute=L.CloudCompute("cpu"),
                )
                self.ws[work_name] = objective_work
            if not self.ws[work_name].has_started:
                trial = self._study.ask(ObjectiveWork.distributions())
                self.ws[work_name].run(trial_id=trial._trial_id,
                                       **trial.params)

            if self.ws[work_name].metric and not self.ws[
                    work_name].has_told_study:
                self._study.tell(self.ws[work_name].trial_id,
                                 self.ws[work_name].metric)
                self.ws[work_name].has_told_study = True

            has_told_study.append(self.ws[work_name].has_told_study)

        if all(has_told_study):
            self.num_trials += self.simultaneous_trials
예제 #2
0
 def __init__(self):
     super().__init__()
     self.source_work = SourceFileWork()
     self.dest_work = DestinationFileAndServeWork(
         script_path=os.path.join(os.path.dirname(__file__), "scripts/serve.py"),
         port=1111,
         parallel=False,  # runs until killed.
         cloud_compute=L.CloudCompute(),
         raise_exception=True,
     )
예제 #3
0
    def run(self):
        # create dynamically the source_work at runtime
        if "src_w" not in self.dict:
            self.dict["src_w"] = SourceFileWork()

        self.dict["src_w"].run()

        if self.dict["src_w"].has_succeeded:

            # create dynamically the dst_w at runtime
            if "dst_w" not in self.dict:
                self.dict["dst_w"] = DestinationFileAndServeWork(
                    script_path=os.path.join(os.path.dirname(__file__),
                                             "scripts/serve.py"),
                    port=1111,
                    parallel=False,  # runs until killed.
                    cloud_compute=L.CloudCompute(),
                    raise_exception=True,
                )

            # the flow passes the file from one work to another.
            self.dict["dst_w"].run(self.dict["src_w"].boring_path)
            self._exit("Boring App End")
예제 #4
0
import argparse

import lightning as L


class Work(L.LightningWork):
    def __init__(self, cloud_compute):
        super().__init__(cloud_compute=cloud_compute)

    def run(self):
        pass


class Flow(L.LightningFlow):
    def __init__(self, cloud_compute):
        super().__init__()
        self.work = Work(cloud_compute)

    def run(self):
        assert self.work.cloud_compute.name == "gpu", self.work.cloud_compute.name
        self._exit()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--use_gpu", action="store_true", default=False, help="Whether to use GPU in the cloud")
    hparams = parser.parse_args()
    app = L.LightningApp(Flow(L.CloudCompute("gpu" if hparams.use_gpu else "cpu")))
예제 #5
0
 def __init__(self,
              cloud_compute: L.CloudCompute = L.CloudCompute(),
              **kwargs):
     super().__init__(parallel=True, **kwargs, cloud_compute=cloud_compute)
     self.boring_path = None
예제 #6
0
 def __init__(self):
     super().__init__()
     self.runner = TracerPythonScript(
         "train.py",
         cloud_compute=L.CloudCompute("gpu"),
     )