Skip to content

Commit 4293b37

Browse files
committed
Terminate autotuning faster if progress is minimal
1 parent df51b71 commit 4293b37

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

helion/autotuner/pattern_search.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(
2828
initial_population: int = 100,
2929
copies: int = 5,
3030
max_generations: int = 20,
31+
min_improvement_delta: float = 0.001,
3132
) -> None:
3233
"""
3334
Create a PatternSearch autotuner.
@@ -38,11 +39,13 @@ def __init__(
3839
initial_population: The number of random configurations to generate for the initial population.
3940
copies: Count of top Configs to run pattern search on.
4041
max_generations: The maximum number of generations to run.
42+
min_improvement_delta: Relative stop threshold; stop if abs(best/current - 1) < this.
4143
"""
4244
super().__init__(kernel, args)
4345
self.initial_population = initial_population
4446
self.copies = copies
4547
self.max_generations = max_generations
48+
self.min_improvement_delta = min_improvement_delta
4649

4750
def _autotune(self) -> Config:
4851
self.log(
@@ -131,6 +134,15 @@ def _pattern_search_from(
131134
best = min(candidates, key=performance)
132135
if best is current:
133136
return # no improvement, stop searching
137+
# Stop if the relative improvement is smaller than a user-specified delta
138+
if (
139+
self.min_improvement_delta > 0.0
140+
and math.isfinite(best.perf)
141+
and math.isfinite(current.perf)
142+
and current.perf != 0.0
143+
and abs(best.perf / current.perf - 1.0) < self.min_improvement_delta
144+
):
145+
return
134146
current = best
135147

136148
def _generate_neighbors(self, base: FlatConfig) -> list[FlatConfig]:

0 commit comments

Comments
 (0)