16 @brief Configuration for Minimum Output Difference algorithm.
18 @details Defines parameters controlling whether and how Mod is applied during quantization, including layer-level inclusion/exclusion lists.
28 "lr_weight_scale": 0.0,
34 "quantize_weight":
True,
35 "weight_scale_init":
"MinMax",
36 "downresol_mode":
"STE",
37 "post_processing":
"",
42 "kl_temperature": 1.0,
49 [[12, 16], [19, 36], [40, 28]],
50 [[36, 75], [76, 55], [72, 146]],
51 [[142, 110], [192, 243], [459, 401]],
63 "warmup_epochs":
"warmupEpochs",
64 "lr_min_ratio":
"lrMinRatio",
65 "lr_act_scale":
"actScaleLR",
66 "lr_zeropoint":
"zeropointLR",
67 "lr_weight_scale":
"weightScaleLR",
68 "lr_weight":
"weightLR",
70 "batch_size":
"batchSize",
72 "quantize_weight":
"quantizeWeight",
73 "weight_scale_init":
"weightScaleInit",
74 "downresol_mode":
"downresolMode",
75 "post_processing":
"post",
76 "box_conf_thres":
"boxConfThres",
77 "box_iou_thres":
"boxIoUThres",
78 "loss_type":
"lossType",
79 "use_outputs":
"useOutputs",
80 "kl_temperature":
"KLTemperature",
81 "recon_prob":
"reconProb",
82 "recon_coeff":
"reconCoeff",
83 "lambda_0":
"lambda_0",
84 "lambda_1":
"lambda_1",
85 "lambda_2":
"lambda_2",
86 "use_xyxy":
"useXYXY",
87 "save_dir":
"saveDir",
93 "warmup_epochs": [0,
None],
94 "lr_min_ratio": [0,
None],
95 "lr_act_scale": [0,
None],
96 "lr_zeropoint": [0,
None],
97 "lr_weight_scale": [0,
None],
98 "lr_weight": [0,
None],
100 "batch_size": [0,
None],
102 "box_conf_thres": [0,
None],
103 "box_iou_thres": [0,
None],
104 "kl_temperature": [0,
None],
105 "recon_prob": [0, 1],
106 "recon_coeff": [0,
None],
107 "lambda_0": [0,
None],
108 "lambda_1": [0,
None],
109 "lambda_2": [0,
None],
119 lr_act_scale: numbers.Number,
120 lr_zeropoint: numbers.Number,
121 lr_weight_scale: numbers.Number,
122 lr_weight: numbers.Number,
123 lr_bias: numbers.Number,
124 lr_min_ratio: numbers.Number,
126 q_drop: numbers.Number,
127 quantize_weight: bool,
128 weight_scale_init: str,
130 post_processing: str,
131 box_conf_thres: numbers.Number,
132 box_iou_thres: numbers.Number,
135 kl_temperature: numbers.Number,
136 recon_prob: numbers.Number,
137 recon_coeff: numbers.Number,
138 lambda_0: numbers.Number,
139 lambda_1: numbers.Number,
140 lambda_2: numbers.Number,
145 apply_layers: List[str],
146 exclude_layers: List[str],
147 optional: bool = optional,
150 @brief Initialize the ModConfig.
151 @param apply bool. Whether to apply MOD.
152 @param epochs int. Number of training epochs.
153 @param warmup_epochs int. Number of warmup epochs.
154 @param lr_act_scale float. Learning rate for activation scale.
155 @param lr_zeropoint float. Learning rate for zeropoint.
156 @param lr_weight_scale float. Learning rate for weight scale.
157 @param lr_weight float. Learning rate for weight.
158 @param lr_bias float. Learning rate for bias.
159 @param lr_min_ratio float. Minimum learning rate ratio for scheduler.
160 @param batch_size int. Batch size for training.
161 @param q_drop float. QDrop ratio.
162 @param quantize_weight bool. Quantize weight during training.
163 @param weight_scale_init str. Weight scale initialization method.
164 @param downresol_mode str. Down-resolution mode for fake quantization.
165 @param post_processing str. Post-processing function.
166 @param box_conf_thres float. Box confidence threshold for NMS.
167 @param box_iou_thres float. Box IoU threshold for NMS.
168 @param loss_type str. Loss function type.
169 @param use_outputs bool. Compare only intermediate layers.
170 @param kl_temperature float. Temperature for KL divergence loss.
171 @param recon_prob float. Sampling probability for intermediate layers.
172 @param recon_coeff float. Coefficient for intermediate layer loss.
173 @param lambda_0 float. First coefficient for AnchorlessDetection loss.
174 @param lambda_1 float. Second coefficient for AnchorlessDetection loss.
175 @param lambda_2 float. Third coefficient for AnchorlessDetection loss.
176 @param anchors List. Anchor boxes configuration.
177 @param use_xyxy bool. Use XYXY format.
178 @param save_dir str. Directory to save results.
179 @param seed int. Random seed.
180 @param apply_layers List[str]. Layers to apply MOD.
181 @param exclude_layers List[str]. Layers to exclude from MOD.
182 @param optional bool. Indicates whether this config is optional. Use the default value defined as a class variable.
217 except_list=[
"optional",
"anchors",
"apply_layers",
"exclude_layers"]
221 def default_config(cls):
226 """Create ModConfig from dictionary (JSON structure)"""
229 if "apply" in config_dict:
230 params[
"apply"] = config_dict[
"apply"]
232 if "attributes" in config_dict:
233 attributes = config_dict[
"attributes"]
235 if "epochs" in attributes:
236 params[
"epochs"] = attributes[
"epochs"]
237 if "warmupEpochs" in attributes:
238 params[
"warmup_epochs"] = attributes[
"warmupEpochs"]
239 if "lrMinRatio" in attributes:
240 params[
"lr_min_ratio"] = attributes[
"lrMinRatio"]
241 if "anchors" in attributes:
242 params[
"anchors"] = attributes[
"anchors"]
243 if "useXYXY" in attributes:
244 params[
"use_xyxy"] = attributes[
"useXYXY"]
245 if "saveDir" in attributes:
246 params[
"save_dir"] = attributes[
"saveDir"]
247 if "seed" in attributes:
248 params[
"seed"] = attributes[
"seed"]
249 if "applyLayers" in attributes:
250 params[
"apply_layers"] = attributes[
"applyLayers"]
251 if "excludeLayers" in attributes:
252 params[
"exclude_layers"] = attributes[
"excludeLayers"]
254 if "learningRates" in attributes:
255 learning_rates = attributes[
"learningRates"]
256 if "actScale" in learning_rates:
257 params[
"lr_act_scale"] = learning_rates[
"actScale"]
258 if "zeropoint" in learning_rates:
259 params[
"lr_zeropoint"] = learning_rates[
"zeropoint"]
260 if "weightScale" in learning_rates:
261 params[
"lr_weight_scale"] = learning_rates[
"weightScale"]
262 if "weight" in learning_rates:
263 params[
"lr_weight"] = learning_rates[
"weight"]
264 if "bias" in learning_rates:
265 params[
"lr_bias"] = learning_rates[
"bias"]
267 if "training" in attributes:
268 training = attributes[
"training"]
269 if "batchSize" in training:
270 params[
"batch_size"] = training[
"batchSize"]
271 if "qDrop" in training:
272 params[
"q_drop"] = training[
"qDrop"]
273 if "quantizeWeight" in training:
274 params[
"quantize_weight"] = training[
"quantizeWeight"]
275 if "weightScaleInit" in training:
276 params[
"weight_scale_init"] = training[
"weightScaleInit"]
277 if "downresolMode" in training:
278 params[
"downresol_mode"] = training[
"downresolMode"]
280 if "postProcessing" in attributes:
281 post_processing = attributes[
"postProcessing"]
282 if "post" in post_processing:
283 params[
"post_processing"] = post_processing[
"post"]
284 if "boxConfThres" in post_processing:
285 params[
"box_conf_thres"] = post_processing[
"boxConfThres"]
286 if "boxIoUThres" in post_processing:
287 params[
"box_iou_thres"] = post_processing[
"boxIoUThres"]
289 if "loss" in attributes:
290 loss = attributes[
"loss"]
292 params[
"loss_type"] = loss[
"type"]
293 if "useOutputs" in loss:
294 params[
"use_outputs"] = loss[
"useOutputs"]
295 if "KLTemperature" in loss:
296 params[
"kl_temperature"] = loss[
"KLTemperature"]
297 if "reconProb" in loss:
298 params[
"recon_prob"] = loss[
"reconProb"]
299 if "reconCoeff" in loss:
300 params[
"recon_coeff"] = loss[
"reconCoeff"]
301 if "lambda_0" in loss:
302 params[
"lambda_0"] = loss[
"lambda_0"]
303 if "lambda_1" in loss:
304 params[
"lambda_1"] = loss[
"lambda_1"]
305 if "lambda_2" in loss:
306 params[
"lambda_2"] = loss[
"lambda_2"]
__init__(self, bool apply, int epochs, int warmup_epochs, numbers.Number lr_act_scale, numbers.Number lr_zeropoint, numbers.Number lr_weight_scale, numbers.Number lr_weight, numbers.Number lr_bias, numbers.Number lr_min_ratio, int batch_size, numbers.Number q_drop, bool quantize_weight, str weight_scale_init, str downresol_mode, str post_processing, numbers.Number box_conf_thres, numbers.Number box_iou_thres, str loss_type, bool use_outputs, numbers.Number kl_temperature, numbers.Number recon_prob, numbers.Number recon_coeff, numbers.Number lambda_0, numbers.Number lambda_1, numbers.Number lambda_2, List anchors, bool use_xyxy, str save_dir, int seed, List[str] apply_layers, List[str] exclude_layers, bool optional=optional)
Initialize the ModConfig.