pfk-beta commented on code in PR #16499: URL: https://github.com/apache/tvm/pull/16499#discussion_r1485833284
########## python/tvm/auto_scheduler/space.py: ########## @@ -0,0 +1,158 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" The class of Space used to optimize the Ansor parameters """ + +import os +from copy import deepcopy +import tvm +from tvm.auto_scheduler.measure import local_builder_build, local_run + + +class MeasureResultSpace: + """Store the results of a measurement. + + Parameters + ---------- + measureResult: List[MeasureResult] + A List of MeasureResult. + """ + + def __init__(self, measure_result): + self._costs = measure_result[0].costs + + @property + def costs(self): + return [v.value for v in self._costs] + + +class Space: + """Space class + + Parameters + ---------- + cfg: json data + A json file template + task: SearchTask + The SearchTask of this measurement. + """ + + def __init__(self, cfg, task): + self.cfg = deepcopy(cfg) + self.total_dims, self.dims, self.task = 0, [], task + self.config_space = {} + self.create_space() + + def create_space(self): + """Create the space using Ansor's space""" + sp_space = [4, 8, 16, 24, 32, 48, 64] + pr_space = [64, 128, 256, 512] + config = self.cfg["i"][1][1] + for i in range(len(config)): + opt = config[i] + if opt[0] == "SP" and opt[3] != 1: Review Comment: The only thing which I can criticize here are these magic numbers of configs. You may choose 2 different ways: - use dicts instead of tuples/lists. Which will give you name. - name magic numbers, e.g. INDEX_SP = 0, INDEX_SOMETHING = 3, and use them. ########## python/tvm/auto_scheduler/task_scheduler.py: ########## @@ -591,21 +592,21 @@ def pre_tune(self, task_scheduler, task_id): for i in range(len(task_scheduler.tasks)): id_str = f"{i}" latency_str = ( - "%.3f" % (1e3 * task_scheduler.best_costs[i]) + f"{1e3 * task_scheduler.best_costs[i]:.3f}" if task_scheduler.best_costs[i] < 1e9 else "-" ) task_desc = task_scheduler.tasks[i].desc + best_cost = task_scheduler.best_costs[i] speed_str = ( - "%.2f" - % (task_scheduler.tasks[i].compute_dag.flop_ct / task_scheduler.best_costs[i] / 1e9) + f"{task_scheduler.tasks[i].compute_dag.flop_ct / best_cost / 1e9:.2f}" if task_scheduler.best_costs[i] < 1e9 else "-" ) - trials_str = "%d" % (task_scheduler.task_cts[i] * task_scheduler.num_measures_per_round) + trials_str = f"{(task_scheduler.task_cts[i] * task_scheduler.num_measures_per_round)}" print( - "| %4s | %61s | %12s | % 14s | %6s |" - % (id_str, task_desc, latency_str, speed_str, trials_str) + f"| {id_str:4s} | {task_desc:61s} | {latency_str:12s} | " + f"{speed_str:14s} | {trials_str:6s} |" Review Comment: Last thing: you are mixing loggers and print. It is more common to use loggers in such software. When developing or testing, you may need to configure logging. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
