From a38de9e7b140db667658053ce7370874bbb61254 Mon Sep 17 00:00:00 2001 From: Anleeos <2937160075@qq.com> Date: Sat, 2 Dec 2023 02:33:58 +0800 Subject: [PATCH] [v0.10.0 -> v0.13.0] Task14 (#231) --- docs/how_to/autotune/01-tuning_nvidia.md | 21 ++++++++++------- docs/how_to/autotune/02-autotuning_nvidia.md | 24 +++++++++++++++++++- docs/how_to/autotune/03-autotuning_x86.md | 24 +++++++++++++++++++- docs/how_to/autotune/04-autotuning_arm.md | 24 ++++++++++++++++---- docs/how_to/autotune/05-autotuning_mobile.md | 24 +++++++++++++++++++- 5 files changed, 102 insertions(+), 15 deletions(-) diff --git a/docs/how_to/autotune/01-tuning_nvidia.md b/docs/how_to/autotune/01-tuning_nvidia.md index 0981b202..1f106d83 100644 --- a/docs/how_to/autotune/01-tuning_nvidia.md +++ b/docs/how_to/autotune/01-tuning_nvidia.md @@ -166,15 +166,20 @@ measure_option = autotvm.measure_option( runner=autotvm.LocalRunner(repeat=3, min_repeat_ms=100, timeout=4), ) +record_file = None # 开始调优,将 log 记录到 `conv2d.log` # 在调优过程中,会尝试很多无效的配置,所以你应该 # 查看许多错误报告。只要能看到非零的 GFLOPS 就可以。 -tuner = autotvm.tuner.XGBTuner(task) -tuner.tune( - n_trial=20, - measure_option=measure_option, - callbacks=[autotvm.callback.log_to_file("conv2d.log")], -) +# 我们不再在服务器上运行调优,因为太耗时间了 +# 去掉下面的注释,自己运行 + +# tuner = autotvm.tuner.XGBTuner(task) +# record_file = "conv2d.log" +# tuner.tune( +# n_trial=5, +# measure_option=measure_option, +# callbacks=[autotvm.callback.log_to_file(record_file)], +# ) ``` 输出结果: @@ -1839,13 +1844,13 @@ tvm.autotvm.task.space.InstantiationError: Skipped because of invalid gpu kernel ``` python # 检查最佳配置 -dispatch_context = autotvm.apply_history_best("conv2d.log") +dispatch_context = autotvm.apply_history_best(record_file) best_config = dispatch_context.query(task.target, task.workload) print("\nBest config:") print(best_config) # 从日志文件中应用历史最好记录 -with autotvm.apply_history_best("conv2d.log"): +with autotvm.apply_history_best(record_file): with tvm.target.Target("cuda"): s, arg_bufs = conv2d_no_batching(N, H, W, CO, CI, KH, KW, strides, padding) func = tvm.build(s, arg_bufs) diff --git a/docs/how_to/autotune/02-autotuning_nvidia.md b/docs/how_to/autotune/02-autotuning_nvidia.md index 8bb312f0..c17c9107 100644 --- a/docs/how_to/autotune/02-autotuning_nvidia.md +++ b/docs/how_to/autotune/02-autotuning_nvidia.md @@ -158,8 +158,30 @@ def tune_tasks( prefix = "[Task %2d/%2d] " % (i + 1, len(tasks)) # 创建调优器 - if tuner == "xgb" or tuner == "xgb-rank": + if tuner == "xgb": + tuner_obj = XGBTuner(tsk, loss_type="reg") + elif tuner == "xgb_knob": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="knob") + elif tuner == "xgb_itervar": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="itervar") + elif tuner == "xgb_curve": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="curve") + elif tuner == "xgb_rank": tuner_obj = XGBTuner(tsk, loss_type="rank") + elif tuner == "xgb_rank_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="knob") + elif tuner == "xgb_rank_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="itervar") + elif tuner == "xgb_rank_curve": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="curve") + elif tuner == "xgb_rank_binary": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary") + elif tuner == "xgb_rank_binary_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="knob") + elif tuner == "xgb_rank_binary_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="itervar") + elif tuner == "xgb_rank_binary_curve": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="curve") elif tuner == "ga": tuner_obj = GATuner(tsk, pop_size=100) elif tuner == "random": diff --git a/docs/how_to/autotune/03-autotuning_x86.md b/docs/how_to/autotune/03-autotuning_x86.md index 5d5326a8..18a93d05 100644 --- a/docs/how_to/autotune/03-autotuning_x86.md +++ b/docs/how_to/autotune/03-autotuning_x86.md @@ -122,8 +122,30 @@ def tune_kernels( prefix = "[Task %2d/%2d] " % (i + 1, len(tasks)) # 创建调优器 - if tuner == "xgb" or tuner == "xgb-rank": + if tuner == "xgb": + tuner_obj = XGBTuner(task, loss_type="reg") + elif tuner == "xgb_knob": + tuner_obj = XGBTuner(task, loss_type="reg", feature_type="knob") + elif tuner == "xgb_itervar": + tuner_obj = XGBTuner(task, loss_type="reg", feature_type="itervar") + elif tuner == "xgb_curve": + tuner_obj = XGBTuner(task, loss_type="reg", feature_type="curve") + elif tuner == "xgb_rank": tuner_obj = XGBTuner(task, loss_type="rank") + elif tuner == "xgb_rank_knob": + tuner_obj = XGBTuner(task, loss_type="rank", feature_type="knob") + elif tuner == "xgb_rank_itervar": + tuner_obj = XGBTuner(task, loss_type="rank", feature_type="itervar") + elif tuner == "xgb_rank_curve": + tuner_obj = XGBTuner(task, loss_type="rank", feature_type="curve") + elif tuner == "xgb_rank_binary": + tuner_obj = XGBTuner(task, loss_type="rank-binary") + elif tuner == "xgb_rank_binary_knob": + tuner_obj = XGBTuner(task, loss_type="rank-binary", feature_type="knob") + elif tuner == "xgb_rank_binary_itervar": + tuner_obj = XGBTuner(task, loss_type="rank-binary", feature_type="itervar") + elif tuner == "xgb_rank_binary_curve": + tuner_obj = XGBTuner(task, loss_type="rank-binary", feature_type="curve") elif tuner == "ga": tuner_obj = GATuner(task, pop_size=50) elif tuner == "random": diff --git a/docs/how_to/autotune/04-autotuning_arm.md b/docs/how_to/autotune/04-autotuning_arm.md index a9f20129..0b03f953 100644 --- a/docs/how_to/autotune/04-autotuning_arm.md +++ b/docs/how_to/autotune/04-autotuning_arm.md @@ -216,14 +216,30 @@ def tune_tasks( prefix = "[Task %2d/%2d] " % (i + 1, len(tasks)) # 创建调优器 - if tuner == "xgb" or tuner == "xgb-rank": - tuner_obj = XGBTuner(tsk, loss_type="rank") + if tuner == "xgb": + tuner_obj = XGBTuner(tsk, loss_type="reg") elif tuner == "xgb_knob": - tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="knob") + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="knob") elif tuner == "xgb_itervar": - tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="itervar") + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="itervar") elif tuner == "xgb_curve": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="curve") + elif tuner == "xgb_rank": + tuner_obj = XGBTuner(tsk, loss_type="rank") + elif tuner == "xgb_rank_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="knob") + elif tuner == "xgb_rank_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="itervar") + elif tuner == "xgb_rank_curve": tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="curve") + elif tuner == "xgb_rank_binary": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary") + elif tuner == "xgb_rank_binary_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="knob") + elif tuner == "xgb_rank_binary_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="itervar") + elif tuner == "xgb_rank_binary_curve": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="curve") elif tuner == "ga": tuner_obj = GATuner(tsk, pop_size=50) elif tuner == "random": diff --git a/docs/how_to/autotune/05-autotuning_mobile.md b/docs/how_to/autotune/05-autotuning_mobile.md index 0333434a..f47b58d6 100644 --- a/docs/how_to/autotune/05-autotuning_mobile.md +++ b/docs/how_to/autotune/05-autotuning_mobile.md @@ -213,8 +213,30 @@ def tune_tasks( prefix = "[Task %2d/%2d] " % (i + 1, len(tasks)) # 创建调优器 - if tuner == "xgb" or tuner == "xgb-rank": + if tuner == "xgb": + tuner_obj = XGBTuner(tsk, loss_type="reg") + elif tuner == "xgb_knob": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="knob") + elif tuner == "xgb_itervar": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="itervar") + elif tuner == "xgb_curve": + tuner_obj = XGBTuner(tsk, loss_type="reg", feature_type="curve") + elif tuner == "xgb_rank": tuner_obj = XGBTuner(tsk, loss_type="rank") + elif tuner == "xgb_rank_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="knob") + elif tuner == "xgb_rank_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="itervar") + elif tuner == "xgb_rank_curve": + tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="curve") + elif tuner == "xgb_rank_binary": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary") + elif tuner == "xgb_rank_binary_knob": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="knob") + elif tuner == "xgb_rank_binary_itervar": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="itervar") + elif tuner == "xgb_rank_binary_curve": + tuner_obj = XGBTuner(tsk, loss_type="rank-binary", feature_type="curve") elif tuner == "ga": tuner_obj = GATuner(tsk, pop_size=50) elif tuner == "random":