image.domain\self_evolve\param_tune.mbt
83.3% · 35 / 42 points · 164 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 参数调优 self_evolve/param_tune - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 自适应参数调优 — 根据历史自动调优参数 - 7
// Adaptive parameter tuning: auto-tune parameters based on history - 8
// - 9
// Phase 10 v308: 将演化从"策略组合"推向"参数调优" — 根据历史数据自动调整参数。 - 10
- 11
///| - 12
/// 参数类型。 - 13
/// 描述 Parameter kind. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum ParamKind { - 18
Threshold - 19
Weight - 20
StepSize - 21
MaxIter - 22
} - 23
- 24
///| - 25
pub extend ParamKind with @debug.Debug::{to_repr} - 26
- 27
///| - 28
pub extend ParamKind with Eq::{not_equal, equal} - 29
- 30
///| - 31
/// 单个调优参数。 - 32
/// 描述 Single tuned parameter. - 33
#derive(Eq, @debug.Debug) - 34
pub(all) struct TunedParam { - 35
param_kind : ParamKind - 36
old_value : Int32 - 37
new_value : Int32 - 38
adjustment : Int32 - 39
rationale : String - 40
} - 41
- 42
///| - 43
pub extend TunedParam with @debug.Debug::{to_repr} - 44
- 45
///| - 46
pub extend TunedParam with Eq::{not_equal, equal} - 47
- 48
///| - 49
/// 参数调优报告。 - 50
/// 描述 Parameter tuning report. - 51
#derive(Eq, @debug.Debug) - 52
pub(all) struct TuneReport { - 53
params : Array[TunedParam] - 54
total : Int32 - 55
adjusted_count : Int32 - 56
summary : String - 57
} - 58
- 59
///| - 60
pub extend TuneReport with @debug.Debug::{to_repr} - 61
- 62
///| - 63
pub extend TuneReport with Eq::{not_equal, equal} - 64
- 65
///| - 66
/// 为单个算子调优参数。 - 67
/// 调优 Tune parameters for a single op. - 68
pub fn tune_params(op : @imgir.IROp) -> Array[TunedParam] { - 69●
let tag = op.tag() - 70
let params : Array[TunedParam] = [] - 71●
let degs = detect_degradation(op) - 72●
let cov = coverage_percentage(op) - 73●
let score = score_op(op) - 74
let old_threshold = 50 - 75
let new_threshold = if cov < 50 { - 76●
30 - 77●
} else if cov > 80 { - 78●
60 - 79
} else { - 80●
old_threshold - 81
} - 82
if new_threshold != old_threshold { - 83●
params.push({ - 84
param_kind: Threshold, - 85
old_value: old_threshold, - 86
new_value: new_threshold, - 87
adjustment: new_threshold - old_threshold, - 88●
rationale: tag + " 覆盖 " + cov.to_string() + "%, 调整阈值", - 89
}) - 90
} - 91
let old_weight = 10 - 92●
let new_weight = if degs.length() > 0 { - 93●
old_weight + degs.length() * 2 - 94
} else { - 95●
old_weight - 96
} - 97
if new_weight != old_weight { - 98●
params.push({ - 99
param_kind: Weight, - 100
old_value: old_weight, - 101
new_value: new_weight, - 102
adjustment: new_weight - old_weight, - 103
rationale: tag + - 104
" 退化 " + - 105●
degs.length().to_string() + - 106
" 个, 调整权重", - 107
}) - 108
} - 109
let old_step = 1 - 110◐
let new_step = if score.score > 70 { 2 } else { old_step } - 111
if new_step != old_step { - 112○
params.push({ - 113
param_kind: StepSize, - 114
old_value: old_step, - 115
new_value: new_step, - 116
adjustment: new_step - old_step, - 117○
rationale: tag + " 评分 " + score.score.to_string() + ", 加大步长", - 118
}) - 119
} - 120
let old_max_iter = 100 - 121◐
let new_max_iter = if degs.length() > 1 { 200 } else { old_max_iter } - 122
if new_max_iter != old_max_iter { - 123○
params.push({ - 124
param_kind: MaxIter, - 125
old_value: old_max_iter, - 126
new_value: new_max_iter, - 127
adjustment: new_max_iter - old_max_iter, - 128
rationale: tag + " 多退化, 增加最大迭代", - 129
}) - 130
} - 131
params - 132
} - 133
- 134
///| - 135
/// 为所有算子调优参数。 - 136
/// 调优 Tune parameters for all ops. - 137
pub fn tune_all_params() -> TuneReport { - 138●
let params : Array[TunedParam] = [] - 139●
for op in all_ops() { - 140●
for p in tune_params(op) { - 141●
params.push(p) - 142
} - 143
} - 144●
let total = params.length() - 145
let mut adjusted = 0 - 146
for p in params { - 147●
if p.adjustment != 0 { - 148●
adjusted = adjusted + 1 - 149
} - 150
} - 151
let summary = "参数调优: " + - 152●
total.to_string() + - 153
" 参数, " + - 154●
adjusted.to_string() + - 155
" 已调整" - 156
{ params, total, adjusted_count: adjusted, summary, } - 157
} - 158
- 159
///| - 160
/// 调优报告是否有参数调整。 - 161
/// 描述 Whether tune report has adjustments. - 162
pub fn TuneReport::has_adjustments(self : TuneReport) -> Bool { - 163●
self.adjusted_count > 0 - 164
}