From 49bea8dd82f8064fed2f1e886970646db814a6c6 Mon Sep 17 00:00:00 2001 From: Bangtian Liu Date: Sat, 11 Jan 2025 11:12:40 -0800 Subject: [PATCH] [tuner] add the output file Signed-off-by: Bangtian Liu --- tuner/examples/simple/simple_tuner.py | 11 +++++++++++ tuner/tuner/libtuner.py | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tuner/examples/simple/simple_tuner.py b/tuner/examples/simple/simple_tuner.py index 3b8af79f9..9cc962427 100644 --- a/tuner/examples/simple/simple_tuner.py +++ b/tuner/examples/simple/simple_tuner.py @@ -75,6 +75,7 @@ def main(): path_config = libtuner.PathConfig() path_config.base_dir.mkdir(parents=True, exist_ok=True) + path_config._set_tune_output(Path("autotune_output.txt")) # TODO(Max191): Make candidate_trackers internal to TuningClient. candidate_trackers: list[libtuner.CandidateTracker] = [] stop_after_phase: str = args.stop_after @@ -156,3 +157,13 @@ def main(): print("Check the detailed execution logs in:") print(path_config.run_log.resolve()) + + print("Check the tuning results in:") + print(path_config.tune_output.resolve()) + with open(path_config.tune_output, "w") as file: + file.write(f"Top dispatch candidates: {top_candidates}\n") + for id in top_candidates: + file.write(f"{candidate_trackers[id].spec_path.resolve()}\n") + file.write(f"Top model candidates: {top_model_candidates}\n") + for id in top_model_candidates: + file.write(f"{candidate_trackers[id].spec_path.resolve()}\n") diff --git a/tuner/tuner/libtuner.py b/tuner/tuner/libtuner.py index cdd589022..4aae8b63f 100644 --- a/tuner/tuner/libtuner.py +++ b/tuner/tuner/libtuner.py @@ -79,6 +79,7 @@ class PathConfig: # To be set outside of class run_log: Optional[Path] = field(init=False, default=None) + tune_output: Optional[Path] = field(init=False, default=None) def __post_init__(self): object.__setattr__(self, "base_dir", self._name_base_dir()) @@ -95,6 +96,9 @@ def _name_base_dir(self) -> Path: def _set_run_log(self, run_log: Path): object.__setattr__(self, "run_log", run_log) + def _set_tune_output(self, tune_output: Path): + object.__setattr__(self, "tune_output", self.base_dir / tune_output) + def get_candidate_spec_filename(self, candidate_id: int) -> str: return f"{candidate_id}_spec.mlir" @@ -801,7 +805,7 @@ def compile( num_worker=num_worker, task_list=task_list, function=run_iree_compile_command ) compiled_candidates = [c for c in compiled_candidates if c is not None] - success_rate = float(len(compiled_candidates)) / float(len(candidates)) + success_rate = float(len(compiled_candidates)) / float(len(task_list)) logging.info( f"Successfully compiled [{len(compiled_candidates)}] candidates. Success rate: {success_rate:.2f}" )