Skip to content

Commit

Permalink
[tuner] add the output file
Browse files Browse the repository at this point in the history
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
  • Loading branch information
bangtianliu committed Jan 11, 2025
1 parent d02d6e0 commit 49bea8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tuner/examples/simple/simple_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
6 changes: 5 additions & 1 deletion tuner/tuner/libtuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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"

Expand Down Expand Up @@ -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}"
)
Expand Down

0 comments on commit 49bea8d

Please sign in to comment.