|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +"""Evolutionary Search Strategy""" |
| 18 | + |
| 19 | +from typing import TYPE_CHECKING, Dict |
| 20 | + |
| 21 | +from tvm._ffi import register_object |
| 22 | +from ...tir import FloatImm |
| 23 | + |
| 24 | +from .search_strategy import SearchStrategy |
| 25 | +from ..mutator import Mutator |
| 26 | +from ..database import Database |
| 27 | + |
| 28 | +from .. import _ffi_api |
| 29 | + |
| 30 | +if TYPE_CHECKING: |
| 31 | + from ..cost_model import CostModel |
| 32 | + |
| 33 | + |
| 34 | +@register_object("meta_schedule.EvolutionarySearch") |
| 35 | +class EvolutionarySearch(SearchStrategy): |
| 36 | + """ |
| 37 | + Replay Trace Search Strategy is a search strategy that always replays the trace by removing its |
| 38 | + decisions so that the decisions would be randomly re-generated. |
| 39 | +
|
| 40 | + Parameters |
| 41 | + ---------- |
| 42 | + num_trials_per_iter : int |
| 43 | + Number of trials per iteration. |
| 44 | + num_trials_total : int |
| 45 | + Total number of trials. |
| 46 | + population : int |
| 47 | + The initial population of traces from measured samples and randomly generated samples. |
| 48 | + init_measured_ratio : int |
| 49 | + The ratio of measured samples in the initial population. |
| 50 | + genetic_algo_iters : int |
| 51 | + The number of iterations for genetic algorithm. |
| 52 | + p_mutate : float |
| 53 | + The probability of mutation. |
| 54 | + eps_greedy : float |
| 55 | + The ratio of greedy selected samples in the final picks. |
| 56 | + mutator_probs: Dict[Mutator, FloatImm] |
| 57 | + The probability contribution of all mutators. |
| 58 | + database : Database |
| 59 | + The database used in the search. |
| 60 | + cost_model : CostModel |
| 61 | + The cost model used in the search. |
| 62 | + """ |
| 63 | + |
| 64 | + num_trials_per_iter: int |
| 65 | + num_trials_total: int |
| 66 | + population: int |
| 67 | + init_measured_ratio: int |
| 68 | + genetic_algo_iters: int |
| 69 | + p_mutate: float |
| 70 | + eps_greedy: float |
| 71 | + mutator_probs: Dict[Mutator, FloatImm] |
| 72 | + database: Database |
| 73 | + cost_model: "CostModel" |
| 74 | + |
| 75 | + def __init__( |
| 76 | + self, |
| 77 | + num_trials_per_iter: int, |
| 78 | + num_trials_total: int, |
| 79 | + population: int, |
| 80 | + init_measured_ratio: float, |
| 81 | + genetic_algo_iters: int, |
| 82 | + p_mutate: float, |
| 83 | + eps_greedy: float, |
| 84 | + mutator_probs: Dict[Mutator, FloatImm], |
| 85 | + database: Database, |
| 86 | + cost_model: "CostModel", |
| 87 | + ): |
| 88 | + """Constructor""" |
| 89 | + self.__init_handle_by_constructor__( |
| 90 | + _ffi_api.SearchStrategyEvolutionarySearch, # pylint: disable=no-member |
| 91 | + num_trials_per_iter, |
| 92 | + num_trials_total, |
| 93 | + population, |
| 94 | + init_measured_ratio, |
| 95 | + genetic_algo_iters, |
| 96 | + p_mutate, |
| 97 | + eps_greedy, |
| 98 | + mutator_probs, |
| 99 | + database, |
| 100 | + cost_model, |
| 101 | + ) |
0 commit comments