Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions helion/autotuner/pattern_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
initial_population: int = 100,
copies: int = 5,
max_generations: int = 20,
min_improvement_delta: float = 0.001,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked 0.001 based on @v0i0 's logs

ci benchmark run: https://github.com/pytorch/helion/actions/runs/18361564232

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no perf hit from this chance

) -> None:
"""
Create a PatternSearch autotuner.
Expand All @@ -38,11 +39,13 @@ def __init__(
initial_population: The number of random configurations to generate for the initial population.
copies: Count of top Configs to run pattern search on.
max_generations: The maximum number of generations to run.
min_improvement_delta: Relative stop threshold; stop if abs(best/current - 1) < this.
"""
super().__init__(kernel, args)
self.initial_population = initial_population
self.copies = copies
self.max_generations = max_generations
self.min_improvement_delta = min_improvement_delta

def _autotune(self) -> Config:
self.log(
Expand Down Expand Up @@ -131,6 +134,15 @@ def _pattern_search_from(
best = min(candidates, key=performance)
if best is current:
return # no improvement, stop searching
# Stop if the relative improvement is smaller than a user-specified delta
if (
self.min_improvement_delta > 0.0
and math.isfinite(best.perf)
and math.isfinite(current.perf)
and current.perf != 0.0
and abs(best.perf / current.perf - 1.0) < self.min_improvement_delta
):
return
current = best

def _generate_neighbors(self, base: FlatConfig) -> list[FlatConfig]:
Expand Down
Loading