Skip to content

Commit bff6d7b

Browse files
committed
Automatically adjust genetic algorithm popsize for smaller search spaces
1 parent 5e3512b commit bff6d7b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel_tuner/strategies/genetic_algorithm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ def tune(searchspace: Searchspace, runner, tuning_options):
2121

2222
options = tuning_options.strategy_options
2323
pop_size, generations, method, mutation_chance = common.get_options(options, _options)
24-
pop_size = min(round(searchspace.size / 2), pop_size)
2524
crossover = supported_methods[method]
2625

26+
# if left to the default, adjust the popsize to a sensible value for small search spaces
27+
if pop_size == _options["popsize"][1]:
28+
pop_size = min(round(searchspace.size / 2), pop_size)
29+
else:
30+
# otherwise, just make sure it doesn't exceed the search space size
31+
pop_size = min(searchspace.size, pop_size)
32+
2733
best_score = 1e20
2834
cost_func = CostFunc(searchspace, tuning_options, runner)
2935

0 commit comments

Comments
 (0)