|
18 | 18 | # pylint: disable=import-outside-toplevel |
19 | 19 | import logging |
20 | 20 | import os.path |
21 | | -from typing import Callable, Dict, List, Optional, Tuple, Union |
| 21 | +from typing import Callable, Dict, List, NamedTuple, Optional, Tuple, Union |
22 | 22 |
|
23 | 23 | from tvm._ffi.registry import register_func |
24 | 24 | from tvm.ir import IRModule, structural_hash |
|
40 | 40 | from .postproc import Postproc |
41 | 41 | from .runner import LocalRunner, Runner |
42 | 42 | from .schedule_rule import ScheduleRule |
43 | | -from .search_strategy import ( |
44 | | - EvolutionarySearchConfig, |
45 | | - ReplayFuncConfig, |
46 | | - ReplayTraceConfig, |
47 | | -) |
| 43 | +from .search_strategy import EvolutionarySearch, ReplayFunc, ReplayTrace |
48 | 44 | from .space_generator import PostOrderApply, SpaceGenerator |
49 | 45 | from .task_scheduler import GradientBased, TaskScheduler |
50 | 46 | from .tune_context import TuneContext |
51 | 47 | from .utils import autotvm_silencer |
52 | 48 |
|
53 | 49 | logger = logging.getLogger(__name__) # pylint: disable=invalid-name |
54 | 50 |
|
55 | | -SearchStrategyConfig = Union[ |
56 | | - ReplayFuncConfig, |
57 | | - ReplayTraceConfig, |
58 | | - EvolutionarySearchConfig, |
59 | | -] |
60 | 51 | FnSpaceGenerator = Callable[[], SpaceGenerator] |
61 | 52 | FnScheduleRule = Callable[[], List[ScheduleRule]] |
62 | 53 | FnPostproc = Callable[[], List[Postproc]] |
|
75 | 66 | ] |
76 | 67 |
|
77 | 68 |
|
| 69 | +class ReplayFuncConfig(NamedTuple): |
| 70 | + """Configuration for ReplayFunc |
| 71 | +
|
| 72 | + Parameters |
| 73 | + ---------- |
| 74 | + num_trials_per_iter : int |
| 75 | + Number of trials per iteration. |
| 76 | + max_trials_per_task : int |
| 77 | + Total number of trials for one task |
| 78 | + max_trials_global : int |
| 79 | + Total number of trials for all tasks in the task scheduler |
| 80 | + """ |
| 81 | + |
| 82 | + num_trials_per_iter: int |
| 83 | + max_trials_per_task: int |
| 84 | + max_trials_global: int |
| 85 | + |
| 86 | + def create_strategy(self) -> ReplayFunc: |
| 87 | + return ReplayFunc(self.num_trials_per_iter, self.max_trials_per_task) |
| 88 | + |
| 89 | + |
| 90 | +class ReplayTraceConfig(NamedTuple): |
| 91 | + """Configuration for ReplayTrace |
| 92 | +
|
| 93 | + Parameters |
| 94 | + ---------- |
| 95 | + num_trials_per_iter : int |
| 96 | + Number of trials per iteration. |
| 97 | + max_trials_per_task : int |
| 98 | + Total number of trials for one task |
| 99 | + max_trials_global : int |
| 100 | + Total number of trials for all tasks in the task scheduler |
| 101 | + """ |
| 102 | + |
| 103 | + num_trials_per_iter: int |
| 104 | + max_trials_per_task: int |
| 105 | + max_trials_global: int |
| 106 | + |
| 107 | + def create_strategy(self) -> ReplayTrace: |
| 108 | + return ReplayTrace(self.num_trials_per_iter, self.max_trials_per_task) |
| 109 | + |
| 110 | + |
| 111 | +class EvolutionarySearchConfig(NamedTuple): |
| 112 | + """Configuration for EvolutionarySearch |
| 113 | +
|
| 114 | + Parameters |
| 115 | + ---------- |
| 116 | + num_trials_per_iter : int |
| 117 | + Number of trials per iteration. |
| 118 | + max_trials_per_task : int |
| 119 | + Total number of trials. |
| 120 | + max_trials_global : int |
| 121 | + Total number of trials for all tasks in the task scheduler |
| 122 | + population_size : int |
| 123 | + The initial population of traces from measured samples and randomly generated samples. |
| 124 | + init_measured_ratio : int |
| 125 | + The ratio of measured samples in the initial population. |
| 126 | + init_min_unmeasured : int |
| 127 | + The minimal size of unmeasured population in the initial sampling. |
| 128 | + genetic_num_iters : int |
| 129 | + The number of iterations for genetic algorithm. |
| 130 | + genetic_mutate_prob : float |
| 131 | + The probability of mutation. |
| 132 | + genetic_max_fail_count : int |
| 133 | + The maximum number to retry mutation. |
| 134 | + eps_greedy : float |
| 135 | + The ratio of greedy selected samples in the final picks. |
| 136 | + """ |
| 137 | + |
| 138 | + num_trials_per_iter: int |
| 139 | + max_trials_per_task: int |
| 140 | + max_trials_global: int |
| 141 | + population_size: int = 2048 |
| 142 | + init_measured_ratio: float = 0.2 |
| 143 | + init_min_unmeasured: int = 50 |
| 144 | + genetic_num_iters: int = 4 |
| 145 | + genetic_mutate_prob: float = 0.85 |
| 146 | + genetic_max_fail_count: int = 10 |
| 147 | + eps_greedy: float = 0.05 |
| 148 | + |
| 149 | + def create_strategy(self) -> EvolutionarySearch: |
| 150 | + return EvolutionarySearch( |
| 151 | + num_trials_per_iter=self.num_trials_per_iter, |
| 152 | + max_trials_per_task=self.max_trials_per_task, |
| 153 | + population_size=self.population_size, |
| 154 | + init_measured_ratio=self.init_measured_ratio, |
| 155 | + init_min_unmeasured=self.init_min_unmeasured, |
| 156 | + genetic_num_iters=self.genetic_num_iters, |
| 157 | + genetic_mutate_prob=self.genetic_mutate_prob, |
| 158 | + genetic_max_fail_count=self.genetic_max_fail_count, |
| 159 | + eps_greedy=self.eps_greedy, |
| 160 | + ) |
| 161 | + |
| 162 | + |
| 163 | +SearchStrategyConfig = Union[ |
| 164 | + ReplayFuncConfig, |
| 165 | + ReplayTraceConfig, |
| 166 | + EvolutionarySearchConfig, |
| 167 | +] |
| 168 | + |
| 169 | + |
78 | 170 | class DefaultLLVM: |
79 | 171 | """Default tuning configuration for LLVM.""" |
80 | 172 |
|
|
0 commit comments