def tune_model(mod, params, tune_settings, target, model_name):
    '\n    Tune a model for a specified number of trials along with other tune settings.\n    Tune settings are specified using a json configuration, as per the TVM tools readme.\n    '
    early_stopping = tune_settings['early_stopping']
    number = tune_settings['number']
    save_path = tune_settings['save_path']
    save_name = tune_settings['save_name']
    repeat = tune_settings['repeat']
    debug = (tune_settings.get('debug_gadqn') or False)
    trials = tune_settings['trials']
    tuner = tune_settings['tuner']
    target = tvm.target.Target(target)
    tasks = autotvm.task.extract_from_program(mod['main'], target=target, target_host='llvm', params=params)
    runner = autotvm.LocalRunner(number=number, repeat=repeat)
    measure_option = autotvm.measure_option(builder=autotvm.LocalBuilder(build_func='default'), runner=runner)
    for (i, tsk) in enumerate(tasks):
        prefix = ('[Task %2d/%2d] ' % ((i + 1), len(tasks)))
        if (tuner in ('xgb', 'xgb-rank')):
            tuner_obj = XGBTuner(tsk, loss_type='rank')
        elif (tuner == 'xgb_knob'):
            tuner_obj = XGBTuner(tsk, loss_type='rank', feature_type='knob')
        elif (tuner == 'ga'):
            tuner_obj = GATuner(tsk, pop_size=50)
        elif (tuner == 'random'):
            tuner_obj = RandomTuner(tsk)
        elif (tuner == 'gridsearch'):
            tuner_obj = GridSearchTuner(tsk)
        elif ((tuner == 'ga-dqn') and debug):
            tuner_obj = GADQNTunerDebug(tsk)
        elif (tuner == 'ga-dqn'):
            tuner_obj = GADQNTuner(tsk)
        else:
            raise ValueError(('invalid tuner: %s ' % tuner))
        abs_path = Path((save_path + save_name)).resolve()
        abs_path.mkdir(exist_ok=True, parents=True)
        abs_path_str = str(abs_path)
        tuner_obj.tune(n_trial=min(trials, len(tsk.config_space)), early_stopping=early_stopping, measure_option=measure_option, callbacks=[autotvm.callback.progress_bar(trials, prefix=prefix), autotvm.callback.log_to_file((abs_path_str + f'/tuning_record_model={model_name}.json'))])
        if ((tuner == 'ga-dqn') and debug):
            tuner_obj.save_model(save_path, (save_name + f'_model={model_name}_layer={i}'))
        del tuner_obj
Tune a model for a specified number of trials along with other tune settings.
Tune settings are specified using a json configuration, as per the TVM tools readme.
def tune_model(mod, params, tune_settings, target, model_name):
    '\n    Tune a model for a specified number of trials along with other tune settings.\n    Tune settings are specified using a json configuration, as per the TVM tools readme.\n    '
    early_stopping = tune_settings['early_stopping']
    number = tune_settings['number']
    save_path = tune_settings['save_path']
    save_name = tune_settings['save_name']
    repeat = tune_settings['repeat']
    debug = (tune_settings.get('debug_gadqn') or False)
    trials = tune_settings['trials']
    tuner = tune_settings['tuner']
    target = tvm.target.Target(target)
    tasks = autotvm.task.extract_from_program(mod['main'], target=target, target_host='llvm', params=params)
    runner = autotvm.LocalRunner(number=number, repeat=repeat)
    measure_option = autotvm.measure_option(builder=autotvm.LocalBuilder(build_func='default'), runner=runner)
    for (i, tsk) in enumerate(tasks):
        prefix = ('[Task %2d/%2d] ' % ((i + 1), len(tasks)))
        if (tuner in ('xgb', 'xgb-rank')):
            tuner_obj = XGBTuner(tsk, loss_type='rank')
        elif (tuner == 'xgb_knob'):
            tuner_obj = XGBTuner(tsk, loss_type='rank', feature_type='knob')
        elif (tuner == 'ga'):
            tuner_obj = GATuner(tsk, pop_size=50)
        elif (tuner == 'random'):
            tuner_obj = RandomTuner(tsk)
        elif (tuner == 'gridsearch'):
            tuner_obj = GridSearchTuner(tsk)
        elif ((tuner == 'ga-dqn') and debug):
            tuner_obj = GADQNTunerDebug(tsk)
        elif (tuner == 'ga-dqn'):
            tuner_obj = GADQNTuner(tsk)
        else:
            raise ValueError(('invalid tuner: %s ' % tuner))
        abs_path = Path((save_path + save_name)).resolve()
        abs_path.mkdir(exist_ok=True, parents=True)
        abs_path_str = str(abs_path)
        tuner_obj.tune(n_trial=min(trials, len(tsk.config_space)), early_stopping=early_stopping, measure_option=measure_option, callbacks=[autotvm.callback.progress_bar(trials, prefix=prefix), autotvm.callback.log_to_file((abs_path_str + f'/tuning_record_model={model_name}.json'))])
        if ((tuner == 'ga-dqn') and debug):
            tuner_obj.save_model(save_path, (save_name + f'_model={model_name}_layer={i}'))
        del tuner_obj