1"""Auto-generated Pydantic models from config_schema.yaml."""
3from __future__
import annotations
4from typing
import Any, Dict, List, Optional, Union
5from pydantic
import BaseModel, Field, ConfigDict, model_validator
8from pathlib
import Path
10SCHEMA_VERSION =
"1.0.0"
15 @brief Configuration for uint8 input handling
17 @details Defines whether inputs should be treated as uint8 and which specific inputs to apply this to.
19 @param apply bool. If true, treat specified inputs as uint8
20 @param inputs List[str]. List of input names to treat as uint8. If empty and apply is true, applies to all inputs
21 @param division_factor float. Division factor for uint8 to float conversion (e.g., 255.0 for [0,1], 127.5 for [0,2])
24 model_config = ConfigDict(
25 populate_by_name=
True,
30 default=
False, description=
"If true, treat specified inputs as uint8"
32 inputs: List[str] = Field(
34 description=
"List of input names to treat as uint8. If empty and apply is true, applies to all inputs",
36 division_factor: float = Field(
38 alias=
"divisionFactor",
39 description=
"Division factor for uint8 to float conversion (e.g., 255.0 for [0,1], 127.5 for [0,2])",
43 """Return a copy with updated fields."""
44 return self.model_copy(update=kwargs)
49 @brief Configuration for input preprocessing pipeline
51 @details Defines preprocessing operations to be applied to model inputs,
52 including operations like resize, normalize, color conversion, etc.
54 @param apply bool. If true, apply preprocessing pipeline
55 @param auto_convert_format bool. If true, automatically convert input format
56 @param pipeline List[Dict[str, Any]]. List of preprocessing operations to apply globally
57 @param input_configs Dict[str, Any]. Per-input preprocessing configurations. Keys are input names
60 model_config = ConfigDict(
61 populate_by_name=
True,
66 default=
False, description=
"If true, apply preprocessing pipeline"
68 auto_convert_format: bool = Field(
70 alias=
"autoConvertFormat",
71 description=
"If true, automatically convert input format",
73 pipeline: Any = Field(
74 default=[], description=
"List of preprocessing operations to apply globally"
76 input_configs: Any = Field(
79 description=
"Per-input preprocessing configurations. Keys are input names",
83 """Return a copy with updated fields."""
84 return self.model_copy(update=kwargs)
89 @brief Configuration for resource management during model compilation
91 @details Controls GPU and memory management settings during the compilation process.
93 @param weight_dtype str. Weight data type for calibration (e.g., 'float32', 'float16')
94 @param use_gpu_only_for_calibration bool. If True, use GPU only during the calibration phase
95 @param weight_memory WeightMemory. Weight memory management configuration
98 model_config = ConfigDict(
99 populate_by_name=
True,
103 weight_dtype: str = Field(
106 description=
"Weight data type for calibration (e.g., 'float32', 'float16')",
108 use_gpu_only_for_calibration: bool = Field(
110 alias=
"useGPUOnlyForCalibration",
111 description=
"If True, use GPU only during the calibration phase",
116 @brief Weight memory management configuration
118 @param method int. Weight memory management method index:<br>
119 0: DeleteFloat - Delete float weights after quantization.<br>
120 1: SaveFloat - Save float weights to disk.<br>
121 2: MoveFloat - Move float weights to CPU.<br>
122 3: KeepFloat - Keep float weights in memory.<br>
123 4: KeepAll - Keep all weights in memory.<br>
126 method_list: List[str] = Field(
127 default=[
"DeleteFloat",
"SaveFloat",
"MoveFloat",
"KeepFloat",
"KeepAll"],
130 method: int = Field(default=0, alias=
"method")
132 weight_memory: WeightMemory = Field(
133 default_factory=WeightMemory, alias=
"weightMemory"
137 """Return a copy with updated fields."""
138 return self.model_copy(update=kwargs)
143 @brief Configuration for calibration during quantization
145 @details Defines calibration and quantization parameterization used to derive activation/weight scales
146 and related statistics during quantized compilation.
148 @param method int. Calibration method index:<br>
149 0: WChALayer - Weight per-channel, Activation per-layer.<br>
150 1: WChAMulti - Weight per-channel, Activation multi-layer.<br>
151 2: WChALayerZeropoint - Weight per-channel, Activation per-layer with zeropoint.<br>
152 3: WChAMultiZeropoint - Weight per-channel, Activation multi-layer with zeropoint.<br>
153 @param output int. Output quantization type index:<br>
154 0: Layer - Per-layer quantization.<br>
155 1: Ch - Per-channel quantization.<br>
156 2: Sigmoid - Sigmoid-based quantization.<br>
157 @param mode int. Quantization mode index:<br>
158 0: Max - Maximum value calibration.<br>
159 1: MaxPercentile - Maximum percentile calibration.<br>
160 2: Histogram - Histogram-based calibration.<br>
161 @param act_scale_min float. Minimum allowed activation scale (lower bound clamp)
162 @param act16_scale_min float. Minimum 16-bit activation scale (actScaleMin / 256)
163 @param weight_scale_min float. Minimum allowed weight scale (lower bound clamp)
164 @param weight16_scale_min float. Minimum 16-bit weight scale (weightScaleMin / 256)
165 @param min_clip_ratio float. Minimum clip ratio constraint applied during calibration
166 @param max_calib_data_size int. Maximum number of calibration samples kept after loading or generation
167 @param max_sample_size_for_quant_scheme int. Maximum number of calibration samples used per quant scheme stage
168 @param max_percentile MaxPercentile. MaxPercentile mode configuration
169 @param fast_dist FastDist. Fast distribution calibration configuration
170 @param histogram Histogram. Histogram-based calibration configuration
171 @param layer_overrides LayerOverrides. Layer-specific override settings for calibration
172 @param statistics Statistics. Statistics save/load configuration with percentile selection
173 @param group_lut GroupLut. LUT grouping algorithm configuration
174 @param optimize_lut OptimizeLut. LUT optimization configuration
177 model_config = ConfigDict(
178 populate_by_name=
True,
182 method_list: List[str] = Field(
183 default=[
"WChALayer",
"WChAMulti",
"WChALayerZeropoint",
"WChAMultiZeropoint"],
186 method: int = Field(default=1, alias=
"method")
187 output_list: List[str] = Field(
188 default=[
"Layer",
"Ch",
"Sigmoid"], alias=
"outputList"
190 output: int = Field(default=0, alias=
"output")
191 mode_list: List[str] = Field(
192 default=[
"Max",
"MaxPercentile",
"Histogram"], alias=
"modeList"
194 mode: int = Field(default=1, alias=
"mode")
196 act_scale_min: float = Field(
199 description=
"Minimum allowed activation scale (lower bound clamp)",
203 act16_scale_min: float = Field(
204 default=1.953125e-06,
205 alias=
"act16ScaleMin",
206 description=
"Minimum 16-bit activation scale (actScaleMin / 256)",
208 weight_scale_min: float = Field(
210 alias=
"weightScaleMin",
211 description=
"Minimum allowed weight scale (lower bound clamp)",
215 weight16_scale_min: float = Field(
217 alias=
"weight16ScaleMin",
218 description=
"Minimum 16-bit weight scale (weightScaleMin / 256)",
220 min_clip_ratio: float = Field(
222 alias=
"minClipRatio",
223 description=
"Minimum clip ratio constraint applied during calibration",
227 max_calib_data_size: int = Field(
229 alias=
"maxCalibDataSize",
230 description=
"Maximum number of calibration samples kept after loading or generation",
233 max_sample_size_for_quant_scheme: int = Field(
235 alias=
"maxSampleSizeForQuantScheme",
236 description=
"Maximum number of calibration samples used per quant scheme stage",
241 model_config = ConfigDict(populate_by_name=
True)
244 @brief MaxPercentile mode configuration
246 @param percentile float. Percentile value for maxPercentile mode
247 @param topk_ratio float. Top-k ratio used in maxPercentile mode
248 @param max_each int. Maximum number of samples processed per iteration
249 @param max_total int. Total maximum number of samples
250 @param per_ch_divisor int. Divisor for per-channel buffer capacity (bufferCap = max(maxTotal / perChDivisor, maxEach))
252 percentile: float = Field(
253 default=0.9999, description=
"Percentile value for maxPercentile mode"
255 topk_ratio: float = Field(
258 description=
"Top-k ratio used in maxPercentile mode",
260 max_each: int = Field(
263 description=
"Maximum number of samples processed per iteration",
265 max_total: int = Field(
268 description=
"Total maximum number of samples",
270 per_ch_divisor: int = Field(
272 alias=
"perChDivisor",
273 description=
"Divisor for per-channel buffer capacity (bufferCap = max(maxTotal / perChDivisor, maxEach))",
277 max_percentile: MaxPercentile = Field(
278 default_factory=MaxPercentile, alias=
"maxPercentile"
282 model_config = ConfigDict(populate_by_name=
True)
285 @brief Fast distribution calibration configuration
287 @param size_cali int.
288 @param kernel_size int.
289 @param stack_size int.
291 size_cali: int = Field(default=100, alias=
"sizeCali")
292 kernel_size: int = Field(default=9, alias=
"kernelSize")
293 stack_size: int = Field(default=32768, alias=
"stackSize")
295 fast_dist: FastDist = Field(default_factory=FastDist, alias=
"fastDist")
298 model_config = ConfigDict(populate_by_name=
True)
301 @brief Histogram-based calibration configuration
303 @param search_type int. Search type for histogram calibration:<br>
307 @param percentile float. Percentile value for histogram calibration
308 @param use_gpu bool. Use GPU for histogram computation
309 @param num_bins int. Number of bins for histogram
310 @param num_samples int. Number of samples for histogram calibration
311 @param buffer_size int. Buffer size for histogram computation (-1 for auto)
312 @param min_bin_width float. Minimum bin width for histogram
313 @param search_percentile_min float. Minimum search percentile
314 @param search_percentile_max float. Maximum search percentile
315 @param num_search int. Number of search iterations
317 search_type_list: List[str] = Field(
318 default=[
"Percentile",
"MSE",
"KL"], alias=
"searchTypeList"
320 search_type: int = Field(default=0, alias=
"searchType")
321 percentile: float = Field(
322 default=0.9999, description=
"Percentile value for histogram calibration"
324 use_gpu: bool = Field(
327 description=
"Use GPU for histogram computation",
329 num_bins: int = Field(
330 default=256, alias=
"numBins", description=
"Number of bins for histogram"
332 num_samples: int = Field(
335 description=
"Number of samples for histogram calibration",
337 buffer_size: int = Field(
340 description=
"Buffer size for histogram computation (-1 for auto)",
342 min_bin_width: float = Field(
345 description=
"Minimum bin width for histogram",
347 search_percentile_min: float = Field(
349 alias=
"searchPercentileMin",
350 description=
"Minimum search percentile",
352 search_percentile_max: float = Field(
354 alias=
"searchPercentileMax",
355 description=
"Maximum search percentile",
357 num_search: int = Field(
358 default=128, alias=
"numSearch", description=
"Number of search iterations"
361 histogram: Histogram = Field(default_factory=Histogram, alias=
"histogram")
364 model_config = ConfigDict(populate_by_name=
True)
367 @brief Layer-specific override settings for calibration
369 @param act_scale_min dict. Per-layer activation scale minimum overrides. Keys are actScaleMin values (e.g. '0.0005'), values are lists of layer names to apply that override. (e.g. {'0.0005' : ['layer1', 'layer2']})
370 @param percentile dict. Per-layer maxPercentile percentile overrides. Keys are layer names, values are percentile floats. (e.g. {'/model/layer0/conv': 0.999, '/model/layer5/attn': 0.99})
371 @param method dict. Per-layer calibration method overrides. Keys are layer names, values are method ints (0=WChALayer, 1=WChAMulti, 2=WChALayerZeropoint, 3=WChAMultiZeropoint). (e.g. {'/model/layer0/conv': 1, '/model/layer5/attn': 3})
373 act_scale_min: Any = Field(
376 description=
"Per-layer activation scale minimum overrides. Keys are actScaleMin values (e.g. '0.0005'), values are lists of layer names to apply that override. (e.g. {'0.0005' : ['layer1', 'layer2']})",
378 percentile: Any = Field(
380 description=
"Per-layer maxPercentile percentile overrides. Keys are layer names, values are percentile floats. (e.g. {'/model/layer0/conv': 0.999, '/model/layer5/attn': 0.99})",
384 description=
"Per-layer calibration method overrides. Keys are layer names, values are method ints (0=WChALayer, 1=WChAMulti, 2=WChALayerZeropoint, 3=WChAMultiZeropoint). (e.g. {'/model/layer0/conv': 1, '/model/layer5/attn': 3})",
387 layer_overrides: LayerOverrides = Field(
388 default_factory=LayerOverrides, alias=
"layerOverrides"
392 model_config = ConfigDict(populate_by_name=
True)
395 @brief Statistics save/load configuration with percentile selection
397 @param apply bool. Enable statistics save/load
398 @param save_path str. Path to save statistics. If empty, not saved
399 @param load_path str. Path to load statistics. If empty, not loaded
400 @param percentiles List[float]. List of percentile candidates
401 @param percentile_index int. Index into percentiles list to select active percentile
403 apply: bool = Field(default=
False, description=
"Enable statistics save/load")
404 save_path: str = Field(
407 description=
"Path to save statistics. If empty, not saved",
409 load_path: str = Field(
412 description=
"Path to load statistics. If empty, not loaded",
414 percentiles: List[float] = Field(
415 default=[0.9999, 0.999, 0.99, 0.9],
416 description=
"List of percentile candidates",
418 percentile_index: int = Field(
420 alias=
"percentileIndex",
421 description=
"Index into percentiles list to select active percentile",
424 statistics: Statistics = Field(default_factory=Statistics, alias=
"statistics")
427 model_config = ConfigDict(populate_by_name=
True)
430 @brief LUT grouping algorithm configuration
432 @param irls_iter int. Number of IRLS iterations for optimal scale computation (1 = single WLS)
433 @param dro_eps float. DRO worst-point coefficient; larger = more conservative clipping (0 = disable)
434 @param cover_floor float. LUTAM cluster scale lower bound as fraction of coverage
436 irls_iter: int = Field(
439 description=
"Number of IRLS iterations for optimal scale computation (1 = single WLS)",
442 dro_eps: float = Field(
445 description=
"DRO worst-point coefficient; larger = more conservative clipping (0 = disable)",
448 cover_floor: float = Field(
451 description=
"LUTAM cluster scale lower bound as fraction of coverage",
456 group_lut: GroupLut = Field(default_factory=GroupLut, alias=
"groupLut")
459 model_config = ConfigDict(populate_by_name=
True)
462 @brief LUT optimization configuration
464 @param optimization_level int. Optimizer search depth (0 = surrogate-only fast, 1 = surrogate + true-objective refinement)
466 optimization_level: int = Field(
468 alias=
"optimizationLevel",
469 description=
"Optimizer search depth (0 = surrogate-only fast, 1 = surrogate + true-objective refinement)",
474 optimize_lut: OptimizeLut = Field(default_factory=OptimizeLut, alias=
"optimizeLut")
477 """Return a copy with updated fields."""
478 return self.model_copy(update=kwargs)
483 @brief Configuration for bit precision
485 @details Defines bit-width parameterization for activations and weights used in
486 mixed-precision quantization (e.g., attention and FFN components).
488 @param transformer Transformer. Transformer-specific bit-width configuration
489 @param save_info SaveInfo. Bit allocation save/load configuration
490 @param layer_overrides LayerOverrides. Layer-specific bit-width override settings
493 model_config = ConfigDict(
494 populate_by_name=
True,
499 model_config = ConfigDict(populate_by_name=
True)
502 @brief Transformer-specific bit-width configuration
504 @param activation Activation. Activation bit-widths for transformer components
505 @param weight Weight. Weight bit-widths for transformer components
506 @param mixed_precision MixedPrecision. Mixed precision configuration
510 model_config = ConfigDict(populate_by_name=
True)
513 @brief Activation bit-widths for transformer components
515 @param query int. Query activation bit-width
516 @param key int. Key activation bit-width
517 @param value int. Value activation bit-width
518 @param output int. Output activation bit-width
519 @param head int. Head activation bit-width
520 @param router int. MoE router gate activation bit-width
521 @param ffn Ffn. FFN activation bit-widths (int shorthand sets all sublayers)
523 query: int = Field(default=8, description=
"Query activation bit-width")
524 key: int = Field(default=8, description=
"Key activation bit-width")
525 value: int = Field(default=8, description=
"Value activation bit-width")
526 output: int = Field(default=16, description=
"Output activation bit-width")
527 head: int = Field(default=8, description=
"Head activation bit-width")
529 default=8, description=
"MoE router gate activation bit-width"
534 @brief FFN activation bit-widths (int shorthand sets all sublayers)
536 @param up int. FFN up-projection activation bit-width
537 @param gate int. FFN gate (SwiGLU) activation bit-width
538 @param down int. FFN down-projection activation bit-width
541 @model_validator(mode="before")
543 def expand_int_shorthand(cls, v):
544 if isinstance(v, bool):
545 raise ValueError(
"bool is not a valid bit-width")
546 if isinstance(v, int):
547 return {
"up": int(v),
"gate": int(v),
"down": int(v)}
551 default=16, description=
"FFN up-projection activation bit-width"
554 default=16, description=
"FFN gate (SwiGLU) activation bit-width"
557 default=16, description=
"FFN down-projection activation bit-width"
560 ffn: Ffn = Field(default_factory=Ffn, alias=
"ffn")
562 activation: Activation = Field(default_factory=Activation, alias=
"activation")
565 model_config = ConfigDict(populate_by_name=
True)
568 @brief Weight bit-widths for transformer components
570 @param query int. Query weight bit-width
571 @param key int. Key weight bit-width
572 @param value int. Value weight bit-width
573 @param output int. Output weight bit-width
574 @param head int. Head weight bit-width
575 @param router int. MoE router gate weight bit-width
576 @param ffn Ffn. FFN weight bit-widths (int shorthand sets all sublayers)
578 query: int = Field(default=8, description=
"Query weight bit-width")
579 key: int = Field(default=8, description=
"Key weight bit-width")
580 value: int = Field(default=8, description=
"Value weight bit-width")
581 output: int = Field(default=8, description=
"Output weight bit-width")
582 head: int = Field(default=8, description=
"Head weight bit-width")
584 default=8, description=
"MoE router gate weight bit-width"
589 @brief FFN weight bit-widths (int shorthand sets all sublayers)
591 @param up int. FFN up-projection weight bit-width
592 @param gate int. FFN gate (SwiGLU) weight bit-width
593 @param down int. FFN down-projection weight bit-width
596 @model_validator(mode="before")
598 def expand_int_shorthand(cls, v):
599 if isinstance(v, bool):
600 raise ValueError(
"bool is not a valid bit-width")
601 if isinstance(v, int):
602 return {
"up": int(v),
"gate": int(v),
"down": int(v)}
606 default=8, description=
"FFN up-projection weight bit-width"
609 default=8, description=
"FFN gate (SwiGLU) weight bit-width"
612 default=8, description=
"FFN down-projection weight bit-width"
615 ffn: Ffn = Field(default_factory=Ffn, alias=
"ffn")
617 weight: Weight = Field(default_factory=Weight, alias=
"weight")
620 model_config = ConfigDict(populate_by_name=
True)
623 @brief Mixed precision configuration
625 @param weight Weight. Mixed precision configuration for weights
626 @param activation Activation. Per-layer activation mixed precision configuration
630 model_config = ConfigDict(populate_by_name=
True)
633 @brief Mixed precision configuration for weights
635 @param apply bool. If true, apply mixed-precision according to the specified bit-widths
636 @param type_wise bool. Apply type-wise mixed precision
637 @param prune float. Pruning ratio
638 @param bit_2 float. Ratio of 2-bit quantization
639 @param bit_4 float. Ratio of 4-bit quantization
640 @param bit_8 float. Ratio of 8-bit quantization
641 @param importance_threshold_low float. Low importance threshold
642 @param importance_threshold_high float. High importance threshold
646 description=
"If true, apply mixed-precision according to the specified bit-widths",
648 type_wise: bool = Field(
651 description=
"Apply type-wise mixed precision",
653 prune: float = Field(default=0, description=
"Pruning ratio")
654 bit_2: float = Field(
655 default=0, alias=
"bit2", description=
"Ratio of 2-bit quantization"
657 bit_4: float = Field(
658 default=0, alias=
"bit4", description=
"Ratio of 4-bit quantization"
660 bit_8: float = Field(
661 default=1, alias=
"bit8", description=
"Ratio of 8-bit quantization"
663 importance_threshold_low: float = Field(
665 alias=
"importanceThreshold_low",
666 description=
"Low importance threshold",
668 importance_threshold_high: float = Field(
670 alias=
"importanceThreshold_high",
671 description=
"High importance threshold",
674 weight: Weight = Field(default_factory=Weight, alias=
"weight")
677 model_config = ConfigDict(populate_by_name=
True)
680 @brief Per-layer activation mixed precision configuration
682 @param apply bool. If true, apply per-layer activation mixed precision
683 @param ratio_16bit float. Ratio of layers assigned 16-bit (used when importanceThreshold < 0)
684 @param importance_threshold float. Normalized importance threshold for 16-bit assignment (negative = use ratio_16bit)
685 @param search_range int. Target layer range: -1=all layers, N=first N layers
689 description=
"If true, apply per-layer activation mixed precision",
691 ratio_16bit: float = Field(
694 description=
"Ratio of layers assigned 16-bit (used when importanceThreshold < 0)",
696 importance_threshold: float = Field(
698 alias=
"importanceThreshold",
699 description=
"Normalized importance threshold for 16-bit assignment (negative = use ratio_16bit)",
701 search_range: int = Field(
704 description=
"Target layer range: -1=all layers, N=first N layers",
707 activation: Activation = Field(
708 default_factory=Activation, alias=
"activation"
711 mixed_precision: MixedPrecision = Field(
712 default_factory=MixedPrecision, alias=
"mixedPrecision"
715 transformer: Transformer = Field(default_factory=Transformer, alias=
"transformer")
718 model_config = ConfigDict(populate_by_name=
True)
721 @brief Bit allocation save/load configuration
723 @param save_path str. Path to save the bit allocation. If empty, not saved
724 @param load_path str. Path to load the bit allocation. If empty, not loaded
726 save_path: str = Field(
729 description=
"Path to save the bit allocation. If empty, not saved",
731 load_path: str = Field(
734 description=
"Path to load the bit allocation. If empty, not loaded",
737 save_info: SaveInfo = Field(default_factory=SaveInfo, alias=
"saveInfo")
740 model_config = ConfigDict(populate_by_name=
True)
743 @brief Layer-specific bit-width override settings
745 @param activation_16bits list[string]. Layer names to force 16-bit activations
746 @param weight_16bits list[string]. Layer names to force 16-bit weights
747 @param weight_8bits list[string]. Layer names to force 8-bit weights
749 activation_16bits: List[str] = Field(
751 alias=
"activation16Bits",
752 description=
"Layer names to force 16-bit activations",
754 weight_16bits: List[str] = Field(
756 alias=
"weight16Bits",
757 description=
"Layer names to force 16-bit weights",
759 weight_8bits: List[str] = Field(
762 description=
"Layer names to force 8-bit weights",
765 layer_overrides: LayerOverrides = Field(
766 default_factory=LayerOverrides, alias=
"layerOverrides"
770 """Return a copy with updated fields."""
771 return self.model_copy(update=kwargs)
776 @brief Configuration for HessianQuant algorithm
778 @details Defines parameters controlling whether and how HessianQuant is applied during quantization,
779 including layer-level inclusion/exclusion lists.
781 @param apply bool. If true, apply HessianQuant
782 @param hessian_dtype str. Storage dtype for the accumulated HessianQuant Hessian. bf16 halves its memory footprint (host RAM when the Hessian lives on CPU, VRAM when on GPU) — critical for large models such as MoE with thousands of expert FFN Hessians. Compute stays float32 regardless: the per-batch matmul and accumulation run in float32 and the solve upcasts back to float32; only the persistent accumulator is bfloat16.:<br>
783 0: fp32 - Store the Hessian in float32.<br>
784 1: bf16 - Store the Hessian in bfloat16 (half the memory).<br>
785 @param accumulation_device str. Device the HessianQuant Hessian is accumulated on during calibration. gpu accumulates on the calibration device, which is 3-5x faster because the whole d x d accumulator is otherwise copied off the device once per layer per batch; the Hessian is parked on the host as soon as the last batch is in, so this does not raise peak VRAM for the rest of the compile. cpu accumulates on the host instead, bounding VRAM during calibration itself for models whose summed Hessian does not fit alongside the activations. auto follows resourceManagement.useGPUOnlyForCalibration, which is the knob that already says whether this compile is VRAM-bound: false picks gpu, true picks cpu. Resolved once at config load and logged; a CPU compile always accumulates on the host regardless.:<br>
786 0: auto - Follow useGPUOnlyForCalibration: false picks gpu, true picks cpu.<br>
787 1: cpu - Accumulate on the host, bounding VRAM during calibration itself.<br>
788 2: gpu - Accumulate on the calibration device, then park on the host.<br>
789 @param attributes Attributes. HessianQuant algorithm attributes
792 model_config = ConfigDict(
793 populate_by_name=
True,
797 apply: bool = Field(default=
False, description=
"If true, apply HessianQuant")
798 hessian_dtype: str = Field(
800 alias=
"hessianDtype",
801 description=
"Storage dtype for the accumulated HessianQuant Hessian. bf16 halves its memory footprint (host RAM when the Hessian lives on CPU, VRAM when on GPU) — critical for large models such as MoE with thousands of expert FFN Hessians. Compute stays float32 regardless: the per-batch matmul and accumulation run in float32 and the solve upcasts back to float32; only the persistent accumulator is bfloat16.",
803 accumulation_device: str = Field(
805 alias=
"accumulationDevice",
806 description=
"Device the HessianQuant Hessian is accumulated on during calibration. gpu accumulates on the calibration device, which is 3-5x faster because the whole d x d accumulator is otherwise copied off the device once per layer per batch; the Hessian is parked on the host as soon as the last batch is in, so this does not raise peak VRAM for the rest of the compile. cpu accumulates on the host instead, bounding VRAM during calibration itself for models whose summed Hessian does not fit alongside the activations. auto follows resourceManagement.useGPUOnlyForCalibration, which is the knob that already says whether this compile is VRAM-bound: false picks gpu, true picks cpu. Resolved once at config load and logged; a CPU compile always accumulates on the host regardless.",
810 model_config = ConfigDict(populate_by_name=
True)
813 @brief HessianQuant algorithm attributes
815 @param act_order bool. If true, use activation order
816 @param block_size int. Block size used for HessianQuant
817 @param perc_damp float. Percentage dampening factor
818 @param apply_layers List[str]. Layer names to apply HessianQuant. If empty, applies to all eligible layers
819 @param exclude_layers List[str]. Layer names to exclude from HessianQuant
821 act_order: bool = Field(
822 default=
True, alias=
"actOrder", description=
"If true, use activation order"
824 block_size: int = Field(
827 description=
"Block size used for HessianQuant",
829 perc_damp: float = Field(
830 default=0.01, alias=
"percDamp", description=
"Percentage dampening factor"
832 apply_layers: List[str] = Field(
835 description=
"Layer names to apply HessianQuant. If empty, applies to all eligible layers",
837 exclude_layers: List[str] = Field(
839 alias=
"excludeLayers",
840 description=
"Layer names to exclude from HessianQuant",
843 attributes: Attributes = Field(default_factory=Attributes, alias=
"attributes")
846 """Return a copy with updated fields."""
847 return self.model_copy(update=kwargs)
852 @brief Configuration for calibration-derived layer bias correction
854 @details Measures systematic per-channel float-to-integer activation error throughout
855 the quantized network and folds damped corrections into integer convolution
856 biases. Corrections are recomputed between iterations to account for upstream
857 changes. This is calibration-only bias correction and does not use labels or
858 Minimum Output Difference optimization.
860 @param apply bool. If true, correct systematic per-layer quantization bias
861 @param attributes Attributes. Layer bias correction attributes
864 model_config = ConfigDict(
865 populate_by_name=
True,
871 description=
"If true, correct systematic per-layer quantization bias",
875 model_config = ConfigDict(populate_by_name=
True)
878 @brief Layer bias correction attributes
880 @param num_samples int. Maximum number of calibration samples used per iteration
881 @param iterations int. Number of damped correction iterations
882 @param correction_rate float. Fraction of the measured bias error applied per iteration
884 num_samples: int = Field(
887 description=
"Maximum number of calibration samples used per iteration",
890 iterations: int = Field(
891 default=5, description=
"Number of damped correction iterations", ge=1
893 correction_rate: float = Field(
895 alias=
"correctionRate",
896 description=
"Fraction of the measured bias error applied per iteration",
901 attributes: Attributes = Field(default_factory=Attributes, alias=
"attributes")
904 """Return a copy with updated fields."""
905 return self.model_copy(update=kwargs)
910 @brief Configuration for Minimum Output Difference algorithm
912 @details Defines parameters controlling whether and how MOD is applied during quantization,
913 including layer-level inclusion/exclusion lists.
915 @param apply bool. If true, apply MOD
916 @param attributes Attributes. MOD algorithm attributes
919 model_config = ConfigDict(
920 populate_by_name=
True,
924 apply: bool = Field(default=
False, description=
"If true, apply MOD")
927 model_config = ConfigDict(populate_by_name=
True)
930 @brief MOD algorithm attributes
932 @param epochs int. Number of training epochs
933 @param warmup_epochs int. Number of warmup epochs
934 @param lr_min_ratio float. Minimum learning rate ratio
935 @param save_dir str. Directory to save MOD results
936 @param seed int. Random seed for MOD
937 @param apply_layers List[str]. Layer names to apply MOD. If empty, applies to all eligible layers
938 @param exclude_layers List[str]. Layer names to exclude from MOD
939 @param mod_after_layer_name str. Apply MOD after this layer
940 @param anchors List. Anchor configurations for detection models. Nested list of anchor box sizes for detection models. Structure: List[List[List[int]]] where outer list is per detection head (e.g. small/medium/large), middle list is anchors per head, inner list is [width, height]. Example: [[[12,16],[19,36],[40,28]], [[36,75],[76,55],[72,146]], [[142,110],[192,243],[459,401]]]
941 @param use_xyxy bool. Use XYXY format for bounding boxes
942 @param learning_rates LearningRates. Learning rate configuration for MOD
943 @param training Training. MOD training configuration
944 @param loss Loss. MOD loss configuration
945 @param post_processing PostProcessing. Post-processing configuration for detection models
947 epochs: int = Field(default=4, description=
"Number of training epochs")
948 warmup_epochs: int = Field(
949 default=1, alias=
"warmupEpochs", description=
"Number of warmup epochs"
951 lr_min_ratio: float = Field(
954 description=
"Minimum learning rate ratio",
956 save_dir: str = Field(
957 default=
"", alias=
"saveDir", description=
"Directory to save MOD results"
959 seed: int = Field(default=0, description=
"Random seed for MOD")
960 apply_layers: List[str] = Field(
963 description=
"Layer names to apply MOD. If empty, applies to all eligible layers",
965 exclude_layers: List[str] = Field(
967 alias=
"excludeLayers",
968 description=
"Layer names to exclude from MOD",
970 mod_after_layer_name: str = Field(
972 alias=
"modAfterLayerName",
973 description=
"Apply MOD after this layer",
975 anchors: Any = Field(
977 description=
"Anchor configurations for detection models. Nested list of anchor box sizes for detection models. Structure: List[List[List[int]]] where outer list is per detection head (e.g. small/medium/large), middle list is anchors per head, inner list is [width, height]. Example: [[[12,16],[19,36],[40,28]], [[36,75],[76,55],[72,146]], [[142,110],[192,243],[459,401]]]",
979 use_xyxy: bool = Field(
982 description=
"Use XYXY format for bounding boxes",
986 model_config = ConfigDict(populate_by_name=
True)
989 @brief Learning rate configuration for MOD
991 @param act_scale float. Learning rate for activation scale
992 @param zeropoint float. Learning rate for zeropoint
993 @param weight_scale float. Learning rate for weight scale
994 @param weight float. Learning rate for weight
995 @param bias float. Learning rate for bias
997 act_scale: float = Field(
1000 description=
"Learning rate for activation scale",
1002 zeropoint: float = Field(
1003 default=0.0, description=
"Learning rate for zeropoint"
1005 weight_scale: float = Field(
1007 alias=
"weightScale",
1008 description=
"Learning rate for weight scale",
1010 weight: float = Field(default=4e-06, description=
"Learning rate for weight")
1011 bias: float = Field(default=4e-06, description=
"Learning rate for bias")
1013 learning_rates: LearningRates = Field(
1014 default_factory=LearningRates, alias=
"learningRates"
1018 model_config = ConfigDict(populate_by_name=
True)
1021 @brief MOD training configuration
1023 @param batch_size int. Batch size for MOD training
1024 @param q_drop float. Quantization drop probability
1025 @param quantize_weight bool. Whether to quantize weights
1026 @param weight_scale_init str. Weight scale initialization method
1027 @param downresol_mode str. Downresolution mode
1028 @param scheduler_type str. LR scheduler type
1030 batch_size: int = Field(
1031 default=1, alias=
"batchSize", description=
"Batch size for MOD training"
1033 q_drop: float = Field(
1034 default=0.0, alias=
"qDrop", description=
"Quantization drop probability"
1036 quantize_weight: bool = Field(
1038 alias=
"quantizeWeight",
1039 description=
"Whether to quantize weights",
1041 weight_scale_init: str = Field(
1043 alias=
"weightScaleInit",
1044 description=
"Weight scale initialization method",
1046 downresol_mode: str = Field(
1047 default=
"STE", alias=
"downresolMode", description=
"Downresolution mode"
1049 scheduler_type: str = Field(
1050 default=
"Cosine", alias=
"schedulerType", description=
"LR scheduler type"
1053 training: Training = Field(default_factory=Training, alias=
"training")
1056 model_config = ConfigDict(populate_by_name=
True)
1059 @brief MOD loss configuration
1061 @param type str. Loss type (MSE, KL, etc.)
1062 @param use_outputs bool. Use model outputs for loss computation
1063 @param kl_temperature float. KL divergence temperature
1064 @param recon_prob float. Reconstruction probability
1065 @param recon_coeff float. Reconstruction coefficient
1066 @param lambda_0 float. Loss weight lambda_0
1067 @param lambda_1 float. Loss weight lambda_1
1068 @param lambda_2 float. Loss weight lambda_2
1069 @param lambda_3 float. Loss weight lambda_3
1070 @param custom_loss_jit_path str. Path to custom JIT-compiled loss function. Refer to /workspace/quantizer/pyutils/mel.pt
1072 type: str = Field(default=
"MSE", description=
"Loss type (MSE, KL, etc.)")
1073 use_outputs: bool = Field(
1076 description=
"Use model outputs for loss computation",
1078 kl_temperature: float = Field(
1080 alias=
"KLTemperature",
1081 description=
"KL divergence temperature",
1083 recon_prob: float = Field(
1084 default=1.0, alias=
"reconProb", description=
"Reconstruction probability"
1086 recon_coeff: float = Field(
1089 description=
"Reconstruction coefficient",
1091 lambda_0: float = Field(
1092 default=1.0, alias=
"lambda0", description=
"Loss weight lambda_0"
1094 lambda_1: float = Field(
1095 default=1.0, alias=
"lambda1", description=
"Loss weight lambda_1"
1097 lambda_2: float = Field(
1098 default=1.0, alias=
"lambda2", description=
"Loss weight lambda_2"
1100 lambda_3: float = Field(
1101 default=1.0, alias=
"lambda3", description=
"Loss weight lambda_3"
1103 custom_loss_jit_path: str = Field(
1105 alias=
"customLossJITPath",
1106 description=
"Path to custom JIT-compiled loss function. Refer to /workspace/quantizer/pyutils/mel.pt",
1109 loss: Loss = Field(default_factory=Loss, alias=
"loss")
1112 model_config = ConfigDict(populate_by_name=
True)
1115 @brief Post-processing configuration for detection models
1117 @param post str. Post-processing type
1118 @param box_conf_thres float. Box confidence threshold
1119 @param box_iou_thres float. Box IoU threshold
1121 post: str = Field(default=
"", description=
"Post-processing type")
1122 box_conf_thres: float = Field(
1123 default=0, alias=
"boxConfThres", description=
"Box confidence threshold"
1125 box_iou_thres: float = Field(
1126 default=0, alias=
"boxIoUThres", description=
"Box IoU threshold"
1129 post_processing: PostProcessing = Field(
1130 default_factory=PostProcessing, alias=
"postProcessing"
1133 attributes: Attributes = Field(default_factory=Attributes, alias=
"attributes")
1136 """Return a copy with updated fields."""
1137 return self.model_copy(update=kwargs)
1142 @brief Configuration for Large Language Model (LLM) compilation
1144 @details Defines LLM-specific settings including sequence lengths, cache configurations,
1145 and runtime parameters for efficient LLM inference.
1147 @param apply bool. If True, apply LLM-specific configurations
1148 @param npu_parallel_degree int. Number of NPU partitions for FFN tensor parallelism (1 = disabled). Applied before OptimizeFFN if both active.
1149 @param attributes Attributes. LLM attributes configuration
1152 model_config = ConfigDict(
1153 populate_by_name=
True,
1157 apply: bool = Field(
1158 default=
False, description=
"If True, apply LLM-specific configurations"
1160 npu_parallel_degree: int = Field(
1162 alias=
"npuParallelDegree",
1163 description=
"Number of NPU partitions for FFN tensor parallelism (1 = disabled). Applied before OptimizeFFN if both active.",
1167 model_config = ConfigDict(populate_by_name=
True)
1170 @brief LLM attributes configuration
1172 @param max_data_length int. Maximum data length
1173 @param max_sequence_length int. Maximum sequence length
1174 @param max_cache_length int. Maximum cache length
1175 @param max_core_data_length int. Maximum core data length
1176 @param calibration Calibration. LLM calibration settings
1177 @param runtime Runtime. LLM runtime settings
1178 @param debug Debug. LLM debug settings
1180 max_data_length: int = Field(
1181 default=4096, alias=
"maxDataLength", description=
"Maximum data length"
1183 max_sequence_length: int = Field(
1185 alias=
"maxSequenceLength",
1186 description=
"Maximum sequence length",
1188 max_cache_length: int = Field(
1189 default=4096, alias=
"maxCacheLength", description=
"Maximum cache length"
1191 max_core_data_length: int = Field(
1193 alias=
"maxCoreDataLength",
1194 description=
"Maximum core data length",
1198 model_config = ConfigDict(populate_by_name=
True)
1201 @brief LLM calibration settings
1203 @param random_seq_length int. Random sequence length used for calibration
1204 @param use_full_seq_length bool. If True, use the full sequence length for calibration
1206 random_seq_length: int = Field(
1208 alias=
"randomSeqLength",
1209 description=
"Random sequence length used for calibration",
1211 use_full_seq_length: bool = Field(
1213 alias=
"useFullSeqLength",
1214 description=
"If True, use the full sequence length for calibration",
1217 calibration: Calibration = Field(
1218 default_factory=Calibration, alias=
"calibration"
1222 model_config = ConfigDict(populate_by_name=
True)
1225 @brief LLM runtime settings
1227 @param use_global_core bool. If True, use a global core
1228 @param batch_size int. Batch size
1229 @param npu_core_ids List[int]. List of NPU core IDs
1230 @param dynamic_rope bool. If True, enable dynamic RoPE (rotary position embedding)
1231 @param dynamic_mask bool. If True, enable dynamic mask (attention mask as runtime input)
1233 use_global_core: bool = Field(
1235 alias=
"useGlobalCore",
1236 description=
"If True, use a global core",
1238 batch_size: int = Field(
1239 default=1, alias=
"batchSize", description=
"Batch size"
1241 npu_core_ids: List[int] = Field(
1242 default=[0], alias=
"npuCoreIds", description=
"List of NPU core IDs"
1244 dynamic_rope: bool = Field(
1246 alias=
"dynamicRope",
1247 description=
"If True, enable dynamic RoPE (rotary position embedding)",
1249 dynamic_mask: bool = Field(
1251 alias=
"dynamicMask",
1252 description=
"If True, enable dynamic mask (attention mask as runtime input)",
1255 runtime: Runtime = Field(default_factory=Runtime, alias=
"runtime")
1258 model_config = ConfigDict(populate_by_name=
True)
1261 @brief LLM debug settings
1263 @param apply bool. Enable LLM debug mode
1264 @param batch_debug_bundle_size int. Batch debug bundle size
1266 apply: bool = Field(default=
False, description=
"Enable LLM debug mode")
1267 batch_debug_bundle_size: int = Field(
1269 alias=
"batchDebugBundleSize",
1270 description=
"Batch debug bundle size",
1273 debug: Debug = Field(default_factory=Debug, alias=
"debug")
1275 attributes: Attributes = Field(default_factory=Attributes, alias=
"attributes")
1278 """Return a copy with updated fields."""
1279 return self.model_copy(update=kwargs)
1284 @brief Sparse MoE expert-selection configuration (calibration only)
1286 @details Controls which experts are calibrated inside SparseMoe modules. selectionMode
1287 is a calibration-only knob: it picks which experts collect statistics (and, for
1288 TopK, on which tokens). It does NOT change inference routing — the forward path
1289 always routes the router's top-K experts regardless of this setting.
1290 scoreThreshold is only used when selectionMode is Threshold.
1292 @param selection_mode int. Expert selection mode index (calibration only; inference is always top-K):<br>
1293 0: TopK - Calibrate only the router's top-K experts per token (matches inference routing).<br>
1294 1: All - Calibrate every expert on the full sequence.<br>
1295 2: Threshold - Calibrate all experts whose routing score exceeds scoreThreshold.<br>
1296 @param score_threshold float. Routing score threshold used when selectionMode is Threshold (calibration only)
1299 model_config = ConfigDict(
1300 populate_by_name=
True,
1304 selection_mode_list: List[str] = Field(
1305 default=[
"TopK",
"All",
"Threshold"], alias=
"selectionModeList"
1307 selection_mode: int = Field(default=0, alias=
"selectionMode")
1309 score_threshold: float = Field(
1311 alias=
"scoreThreshold",
1312 description=
"Routing score threshold used when selectionMode is Threshold (calibration only)",
1317 """Return a copy with updated fields."""
1318 return self.model_copy(update=kwargs)
1323 @brief Configuration for equivalent transformation techniques
1325 @details Defines parameters for various equivalent transformation methods including
1326 NormConv, QK smoothing, and rotation matrices for improved quantization.
1328 @param seed int. Random seed for transformation
1329 @param apply_hadamard_rotation_matrix bool. Apply Hadamard rotation matrix
1330 @param norm_conv NormConv. NormConv equivalent transformation
1331 @param qk Qk. QK smoothing transformation
1332 @param ud Ud. UD transformation
1333 @param vo Vo. VO transformation
1334 @param feed_forward_multi_lut FeedForwardMultiLut. Feed-forward multi-LUT transformation
1335 @param spin_r1 SpinR1. SpinR1 rotation transformation
1336 @param head_out_ch_rotation HeadOutChRotation. Head output channel rotation transformation
1337 @param in_rotation InRotation. Input rotation transformation
1338 @param spin_r2 SpinR2. SpinR2 rotation transformation
1339 @param qk_rotation QkRotation. QK rotation transformation
1340 @param flatten_quant FlattenQuant. Flatten quantization transformation
1341 @param optimize_ffn OptimizeFfn. FFN optimization
1344 model_config = ConfigDict(
1345 populate_by_name=
True,
1349 seed: int = Field(default=0, description=
"Random seed for transformation")
1350 apply_hadamard_rotation_matrix: bool = Field(
1352 alias=
"applyHadamardRotationMatrix",
1353 description=
"Apply Hadamard rotation matrix",
1357 model_config = ConfigDict(populate_by_name=
True)
1360 @brief NormConv equivalent transformation
1362 @param apply bool. Apply NormConv transformation
1363 @param learn bool. Learn transformation parameters
1364 @param smoothing_factor float. Smoothing factor
1365 @param min_gamma float. Minimum gamma value
1366 @param max_gamma float. Maximum gamma value
1368 apply: bool = Field(default=
False, description=
"Apply NormConv transformation")
1369 learn: bool = Field(
1370 default=
False, description=
"Learn transformation parameters"
1372 smoothing_factor: float = Field(
1373 default=0.5, alias=
"smoothingFactor", description=
"Smoothing factor"
1375 min_gamma: float = Field(
1376 default=0.0001, alias=
"minGamma", description=
"Minimum gamma value"
1378 max_gamma: float = Field(
1379 default=10000.0, alias=
"maxGamma", description=
"Maximum gamma value"
1382 norm_conv: NormConv = Field(default_factory=NormConv, alias=
"NormConv")
1385 model_config = ConfigDict(populate_by_name=
True)
1388 @brief QK smoothing transformation
1390 @param apply bool. Apply QK transformation
1391 @param smoothing_factor float. Smoothing factor
1392 @param min_gamma float. Minimum gamma value
1393 @param max_gamma float. Maximum gamma value
1395 apply: bool = Field(default=
False, description=
"Apply QK transformation")
1396 smoothing_factor: float = Field(
1397 default=0.5, alias=
"smoothingFactor", description=
"Smoothing factor"
1399 min_gamma: float = Field(
1400 default=0.0001, alias=
"minGamma", description=
"Minimum gamma value"
1402 max_gamma: float = Field(
1403 default=10000.0, alias=
"maxGamma", description=
"Maximum gamma value"
1406 qk: Qk = Field(default_factory=Qk, alias=
"QK")
1409 model_config = ConfigDict(populate_by_name=
True)
1412 @brief UD transformation
1414 @param apply bool. Apply UD transformation
1415 @param learn bool. Learn transformation parameters
1416 @param smoothing_factor float. Smoothing factor
1417 @param min_gamma float. Minimum gamma value
1418 @param max_gamma float. Maximum gamma value
1420 apply: bool = Field(default=
False, description=
"Apply UD transformation")
1421 learn: bool = Field(
1422 default=
False, description=
"Learn transformation parameters"
1424 smoothing_factor: float = Field(
1425 default=0.5, alias=
"smoothingFactor", description=
"Smoothing factor"
1427 min_gamma: float = Field(
1428 default=0.0001, alias=
"minGamma", description=
"Minimum gamma value"
1430 max_gamma: float = Field(
1431 default=10000.0, alias=
"maxGamma", description=
"Maximum gamma value"
1434 ud: Ud = Field(default_factory=Ud, alias=
"UD")
1437 model_config = ConfigDict(populate_by_name=
True)
1440 @brief VO transformation
1442 @param apply bool. Apply VO transformation
1443 @param smoothing_factor float. Smoothing factor
1444 @param min_gamma float. Minimum gamma value
1445 @param max_gamma float. Maximum gamma value
1447 apply: bool = Field(default=
False, description=
"Apply VO transformation")
1448 smoothing_factor: float = Field(
1449 default=0.5, alias=
"smoothingFactor", description=
"Smoothing factor"
1451 min_gamma: float = Field(
1452 default=0.0001, alias=
"minGamma", description=
"Minimum gamma value"
1454 max_gamma: float = Field(
1455 default=10000.0, alias=
"maxGamma", description=
"Maximum gamma value"
1458 vo: Vo = Field(default_factory=Vo, alias=
"VO")
1462 @brief Feed-forward multi-LUT transformation
1464 @param apply bool. Apply feed-forward multi-LUT transformation
1465 @param breakpoints List[float]. Breakpoints for multi-LUT
1468 apply: bool = Field(
1469 default=
False, description=
"Apply feed-forward multi-LUT transformation"
1471 breakpoints: List[float] = Field(
1472 default=[-8.0, -4.0, 0], description=
"Breakpoints for multi-LUT"
1475 feed_forward_multi_lut: FeedForwardMultiLut = Field(
1476 default_factory=FeedForwardMultiLut, alias=
"FeedForwardMultiLUT"
1480 model_config = ConfigDict(populate_by_name=
True)
1483 @brief SpinR1 rotation transformation
1485 @param apply bool. Apply SpinR1 transformation
1486 @param matrix_path str. Path to rotation matrix file
1488 apply: bool = Field(default=
False, description=
"Apply SpinR1 transformation")
1489 matrix_path: str = Field(
1490 default=
"", alias=
"matrixPath", description=
"Path to rotation matrix file"
1493 spin_r1: SpinR1 = Field(default_factory=SpinR1, alias=
"SpinR1")
1496 model_config = ConfigDict(populate_by_name=
True)
1499 @brief Head output channel rotation transformation
1501 @param apply bool. Apply head output channel rotation
1502 @param matrix_path str. Path to rotation matrix file
1504 apply: bool = Field(
1505 default=
False, description=
"Apply head output channel rotation"
1507 matrix_path: str = Field(
1508 default=
"", alias=
"matrixPath", description=
"Path to rotation matrix file"
1511 head_out_ch_rotation: HeadOutChRotation = Field(
1512 default_factory=HeadOutChRotation, alias=
"HeadOutChRotation"
1516 model_config = ConfigDict(populate_by_name=
True)
1519 @brief Input rotation transformation
1521 @param apply bool. Apply input rotation
1522 @param matrix_path str. Path to rotation matrix file
1523 @param input_names List[str]. Names of the input layers to rotate
1525 apply: bool = Field(default=
False, description=
"Apply input rotation")
1526 matrix_path: str = Field(
1527 default=
"", alias=
"matrixPath", description=
"Path to rotation matrix file"
1529 input_names: List[str] = Field(
1532 description=
"Names of the input layers to rotate",
1535 in_rotation: InRotation = Field(default_factory=InRotation, alias=
"InRotation")
1538 model_config = ConfigDict(populate_by_name=
True)
1541 @brief SpinR2 rotation transformation
1543 @param apply bool. Apply SpinR2 transformation
1544 @param learn bool. Learn rotation matrix
1545 @param matrix_path str. Path to rotation matrix file
1547 apply: bool = Field(default=
False, description=
"Apply SpinR2 transformation")
1548 learn: bool = Field(default=
False, description=
"Learn rotation matrix")
1549 matrix_path: str = Field(
1550 default=
"", alias=
"matrixPath", description=
"Path to rotation matrix file"
1553 spin_r2: SpinR2 = Field(default_factory=SpinR2, alias=
"SpinR2")
1556 model_config = ConfigDict(populate_by_name=
True)
1559 @brief QK rotation transformation
1561 @param apply bool. Apply QK rotation transformation
1562 @param matrix_path str. Path to rotation matrix file
1564 apply: bool = Field(
1565 default=
False, description=
"Apply QK rotation transformation"
1567 matrix_path: str = Field(
1568 default=
"", alias=
"matrixPath", description=
"Path to rotation matrix file"
1571 qk_rotation: QkRotation = Field(default_factory=QkRotation, alias=
"QKRotation")
1574 model_config = ConfigDict(populate_by_name=
True)
1577 @brief Flatten quantization transformation
1579 @param apply bool. Apply flatten quantization
1580 @param learn bool. Learn flattening parameters
1581 @param apply_threshold float. Threshold for applying flatten quantization
1582 @param max_overhead float. Maximum overhead allowed for flattening
1584 apply: bool = Field(default=
False, description=
"Apply flatten quantization")
1585 learn: bool = Field(default=
False, description=
"Learn flattening parameters")
1586 apply_threshold: float = Field(
1588 alias=
"applyThreshold",
1589 description=
"Threshold for applying flatten quantization",
1591 max_overhead: float = Field(
1593 alias=
"maxOverhead",
1594 description=
"Maximum overhead allowed for flattening",
1597 flatten_quant: FlattenQuant = Field(
1598 default_factory=FlattenQuant, alias=
"FlattenQuant"
1602 model_config = ConfigDict(populate_by_name=
True)
1605 @brief FFN optimization
1607 @param apply bool. Apply FFN optimization
1608 @param ch_per_ffn int. Optimize FFN split (-1 for auto)
1610 apply: bool = Field(default=
False, description=
"Apply FFN optimization")
1611 ch_per_ffn: int = Field(
1612 default=-1, alias=
"chPerFFN", description=
"Optimize FFN split (-1 for auto)"
1615 optimize_ffn: OptimizeFfn = Field(default_factory=OptimizeFfn, alias=
"OptimizeFFN")
1618 """Return a copy with updated fields."""
1619 return self.model_copy(update=kwargs)
1624 @brief Configuration for weight scale search
1626 @details Defines which transformer components should have their weight scales
1627 searched for optimal quantization.
1629 @param apply bool. If true, apply weight scale search
1630 @param transformer Transformer. Transformer components for weight scale search
1633 model_config = ConfigDict(
1634 populate_by_name=
True,
1638 apply: bool = Field(default=
False, description=
"If true, apply weight scale search")
1642 @brief Transformer components for weight scale search
1644 @param query bool. Search weight scale for query
1645 @param key bool. Search weight scale for key
1646 @param value bool. Search weight scale for value
1647 @param out bool. Search weight scale for output
1648 @param ffn bool. Search weight scale for FFN
1651 query: bool = Field(default=
False, description=
"Search weight scale for query")
1652 key: bool = Field(default=
False, description=
"Search weight scale for key")
1653 value: bool = Field(default=
False, description=
"Search weight scale for value")
1654 out: bool = Field(default=
False, description=
"Search weight scale for output")
1655 ffn: bool = Field(default=
False, description=
"Search weight scale for FFN")
1657 transformer: Transformer = Field(default_factory=Transformer, alias=
"transformer")
1660 """Return a copy with updated fields."""
1661 return self.model_copy(update=kwargs)
1666 @brief QAT activation scale loading configuration
1668 @details Loads pre-trained activation scales from safetensors files and applies them
1669 to specified layers before scale/zeropoint computation.
1670 NOTE: entries is stored as raw JSON (type: list) because the generator does
1671 not support list[CustomStruct]. The schema records the field shape; parsing
1672 is done manually in applyQATLoadScaleQuantType / applyQATLoadScales.
1674 @param apply bool. If true, load and apply QAT scales from safetensors files
1675 @param entries List. List of file entries. Each entry is a dict:
1676 { path: str, scales: [ { key: str, layers: [str] } ] }
1677 path: safetensors file path; key: tensor name in the file;
1678 layers: layer names whose activation scale will be overridden.
1682 model_config = ConfigDict(
1683 populate_by_name=
True,
1687 apply: bool = Field(
1689 description=
"If true, load and apply QAT scales from safetensors files",
1691 entries: Any = Field(
1693 description=
"List of file entries. Each entry is a dict: { path: str, scales: [ { key: str, layers: [str] } ] } path: safetensors file path; key: tensor name in the file; layers: layer names whose activation scale will be overridden.",
1697 """Return a copy with updated fields."""
1698 return self.model_copy(update=kwargs)
1703 @brief Runtime options for compilation
1705 @details Contains runtime-specific settings like version info and cache options.
1707 @param version str. Compiler version string (e.g., 0.0.0)
1710 model_config = ConfigDict(
1711 populate_by_name=
True,
1715 version: str = Field(
1716 default=
"0.0.0", description=
"Compiler version string (e.g., 0.0.0)"
1720 """Return a copy with updated fields."""
1721 return self.model_copy(update=kwargs)
1726 @brief Sample data generation and saving configuration
1728 @param apply bool. Enable sample data saving
1729 @param mode str. Inference mode: infer (standard) or inferWithCache (LLM cache models)
1730 @param batch_size int. Number of inference batches to generate
1731 @param batch_seq_lens List. Per-batch step-wise sequence lengths for inferWithCache mode. e.g. [[80, 1], [240, 10]]
1732 @param save_folder str. Output folder for sample data
1733 @param dtype str. Data type for saved samples: float or int8
1736 model_config = ConfigDict(
1737 populate_by_name=
True,
1741 apply: bool = Field(default=
False, description=
"Enable sample data saving")
1744 description=
"Inference mode: infer (standard) or inferWithCache (LLM cache models)",
1746 batch_size: int = Field(
1749 description=
"Number of inference batches to generate",
1751 batch_seq_lens: Any = Field(
1753 alias=
"batchSeqLens",
1754 description=
"Per-batch step-wise sequence lengths for inferWithCache mode. e.g. [[80, 1], [240, 10]]",
1756 save_folder: str = Field(
1757 default=
"sampleInout",
1759 description=
"Output folder for sample data",
1762 default=
"float", description=
"Data type for saved samples: float or int8"
1766 """Return a copy with updated fields."""
1767 return self.model_copy(update=kwargs)
1770class GroupWiseConfig(BaseModel):
1772 @brief Group-wise streaming quantization configuration for large LLMs
1774 @details Configuration for the group-wise (streaming) quantization pipeline used for
1775 LLMs that do not fit fully on GPU. Partitions the model into groups of
1776 transformer blocks and quantizes each group independently.
1778 @param apply bool. Enable group-wise streaming quantization pipeline
1779 @param group_size int. Group size in number of transformer blocks (0 = auto)
1780 @param gpu_budget_gb float. GPU memory budget in GiB for group-wise execution (0 = auto-detect)
1781 @param gpu_safety_margin_gb float. Safety margin in GiB subtracted from detected GPU budget
1782 @param cache_dir str. Directory for group-wise activation/state cache (empty = system temp)
1783 @param keep_cache bool. Retain group-wise cache after run completes (for debugging)
1784 @param partition_policy str. Partitioning policy (e.g. transformer_block, moe_expert_subgroup)
1785 @param expert_groups List[List[int]]. MoE fallback partitioner: list of expert-index lists (List[List[int]]).
1786 @param retain_topology_weights bool. Keep inflated FP weights across groups (false = release after each group for tight memory budgets).
1787 @param checkpoint bool. Save per-group checkpoint so quantization can resume from the last completed group after a crash.
1790 model_config = ConfigDict(
1791 populate_by_name=
True,
1795 apply: bool = Field(
1796 default=
False, description=
"Enable group-wise streaming quantization pipeline"
1798 group_size: int = Field(
1801 description=
"Group size in number of transformer blocks (0 = auto)",
1803 gpu_budget_gb: float = Field(
1805 alias=
"gpuBudgetGb",
1806 description=
"GPU memory budget in GiB for group-wise execution (0 = auto-detect)",
1808 gpu_safety_margin_gb: float = Field(
1810 alias=
"gpuSafetyMarginGb",
1811 description=
"Safety margin in GiB subtracted from detected GPU budget",
1813 cache_dir: str = Field(
1816 description=
"Directory for group-wise activation/state cache (empty = system temp)",
1818 keep_cache: bool = Field(
1821 description=
"Retain group-wise cache after run completes (for debugging)",
1823 partition_policy: str = Field(
1824 default=
"transformer_block",
1825 alias=
"partitionPolicy",
1826 description=
"Partitioning policy (e.g. transformer_block, moe_expert_subgroup)",
1828 expert_groups: Any = Field(
1830 alias=
"expertGroups",
1831 description=
"MoE fallback partitioner: list of expert-index lists (List[List[int]]).",
1833 retain_topology_weights: bool = Field(
1835 alias=
"retainTopologyWeights",
1836 description=
"Keep inflated FP weights across groups (false = release after each group for tight memory budgets).",
1838 checkpoint: bool = Field(
1840 description=
"Save per-group checkpoint so quantization can resume from the last completed group after a crash.",
1844 """Return a copy with updated fields."""
1845 return self.model_copy(update=kwargs)
1849 """Unified compilation configuration for Mobilint MXQ compilation."""
1851 model_config = ConfigDict(
1852 populate_by_name=
True,
1856 model_paths: List[str] = Field(
1857 default=[], alias=
"modelPaths", description=
"Paths to model files"
1859 calib_data_path: List[str] = Field(
1860 default=[], alias=
"calibDataPaths", description=
"Paths to calibration datasets"
1862 save_paths: List[str] = Field(
1863 default=[
"./tmp.mxq"],
1865 description=
"Output MXQ filename/paths",
1867 use_random_calib: bool = Field(
1868 default=
False, alias=
"useRandomCalib", description=
"Use random calibration"
1870 inference_scheme: str = Field(
1871 default=
"single", alias=
"inferenceScheme", description=
"NPU inference scheme"
1873 cpu_offload: bool = Field(
1876 description=
"Enable CPU offload for unsupported operators",
1878 force_npu_input_reposition: bool = Field(
1880 alias=
"forceNpuInputReposition",
1881 description=
"Force input reposition operations to run on NPU instead of CPU",
1883 force_npu_output_reposition: bool = Field(
1885 alias=
"forceNpuOutputReposition",
1886 description=
"Force output reposition operations to run on NPU instead of CPU",
1888 optimize_option: int = Field(
1890 alias=
"optimizeOption",
1891 description=
"Compiler optimization selector",
1894 buffer_mode: int = Field(
1895 default=1, alias=
"bufferMode", description=
"Buffer serialization mode"
1897 input_shape_dict: Any = Field(
1898 default={}, alias=
"inputShapeDict", description=
"Dictionary of input shapes"
1900 device: str = Field(default=
"gpu", description=
"Device for computation")
1901 dtype: str = Field(default=
"float", description=
"Data type for computation")
1902 debug: bool = Field(default=
False, description=
"Enable debug mode")
1903 trace: bool = Field(default=
False, description=
"Enable trace mode")
1904 image_channels: int = Field(
1906 alias=
"imageChannels",
1907 description=
"Number of image channels (0 for auto-detect)",
1909 config_version: str = Field(
1910 default=
"1.0.0", alias=
"configVersion", description=
"Config schema version"
1912 split_blocks: List[int] = Field(
1914 alias=
"splitBlocks",
1915 description=
"Multi-MXQ split points by transformer block index",
1917 split_parts: int = Field(
1920 description=
"Evenly split transformer blocks into N MXQ parts",
1923 uint8_input: Uint8InputConfig = Field(
1924 default_factory=Uint8InputConfig, alias=
"uint8Input"
1926 preprocessing: PreprocessingConfig = Field(default_factory=PreprocessingConfig)
1927 resource_management: ResourceManagementConfig = Field(
1928 default_factory=ResourceManagementConfig, alias=
"resourceManagement"
1930 calibration: CalibrationConfig = Field(default_factory=CalibrationConfig)
1931 bit: BitConfig = Field(default_factory=BitConfig)
1932 hessian_quant: HessianQuantConfig = Field(
1933 default_factory=HessianQuantConfig, alias=
"hessianQuant"
1935 layer_bias_correction: LayerBiasCorrectionConfig = Field(
1936 default_factory=LayerBiasCorrectionConfig, alias=
"layerBiasCorrection"
1938 mod: ModConfig = Field(default_factory=ModConfig)
1939 llm: LlmConfig = Field(default_factory=LlmConfig)
1940 moe: MoeConfig = Field(default_factory=MoeConfig)
1941 equivalent_transformation: EquivalentTransformationConfig = Field(
1942 default_factory=EquivalentTransformationConfig, alias=
"equivalentTransformation"
1944 search_weight_scale: SearchWeightScaleConfig = Field(
1945 default_factory=SearchWeightScaleConfig, alias=
"searchWeightScale"
1947 load_scale: LoadScaleConfig = Field(
1948 default_factory=LoadScaleConfig, alias=
"loadScale"
1950 runtime_options: RuntimeOptions = Field(
1951 default_factory=RuntimeOptions, alias=
"runtimeOptions"
1953 save_sample: SaveSampleConfig = Field(
1954 default_factory=SaveSampleConfig, alias=
"saveSample"
1956 group_wise: GroupWiseConfig = Field(
1957 default_factory=GroupWiseConfig, alias=
"groupWise"
1961 """Return a copy with uint8_input settings enabled."""
1962 data = {
"apply":
True, **kwargs}
1963 new_cfg = self.
uint8_input.model_copy(update=data)
1964 return self.model_copy(update={
"uint8_input": new_cfg})
1967 """Return a copy with preprocessing settings enabled."""
1968 data = {
"apply":
True, **kwargs}
1970 return self.model_copy(update={
"preprocessing": new_cfg})
1973 """Return a copy with hessian_quant settings enabled."""
1974 data = {
"apply":
True, **kwargs}
1976 return self.model_copy(update={
"hessian_quant": new_cfg})
1979 """Return a copy with layer_bias_correction settings enabled."""
1980 data = {
"apply":
True, **kwargs}
1982 return self.model_copy(update={
"layer_bias_correction": new_cfg})
1985 """Return a copy with mod settings enabled."""
1986 data = {
"apply":
True, **kwargs}
1987 new_cfg = self.
mod.model_copy(update=data)
1988 return self.model_copy(update={
"mod": new_cfg})
1991 """Return a copy with llm settings enabled."""
1992 data = {
"apply":
True, **kwargs}
1993 new_cfg = self.
llm.model_copy(update=data)
1994 return self.model_copy(update={
"llm": new_cfg})
1997 """Return a copy with search_weight_scale settings enabled."""
1998 data = {
"apply":
True, **kwargs}
2000 return self.model_copy(update={
"search_weight_scale": new_cfg})
2003 """Return a copy with load_scale settings enabled."""
2004 data = {
"apply":
True, **kwargs}
2005 new_cfg = self.
load_scale.model_copy(update=data)
2006 return self.model_copy(update={
"load_scale": new_cfg})
2009 """Return a copy with save_sample settings enabled."""
2010 data = {
"apply":
True, **kwargs}
2011 new_cfg = self.
save_sample.model_copy(update=data)
2012 return self.model_copy(update={
"save_sample": new_cfg})
2014 def with_group_wise(self, **kwargs) -> "CompileConfig":
2015 """Return a copy with group_wise settings enabled."""
2016 data = {
"apply":
True, **kwargs}
2017 new_cfg = self.
group_wise.model_copy(update=data)
2018 return self.model_copy(update={
"group_wise": new_cfg})
2021 def from_file(cls, path: Union[str, Path]) ->
"CompileConfig":
2022 """Load config from YAML or JSON file."""
2024 with open(path)
as f:
2025 if path.suffix
in (
".yaml",
".yml"):
2026 data = yaml.safe_load(f)
2030 return cls.model_validate(data)
2034 """Flatten grouped JSON keys (e.g. quantization.calibration) to flat structure."""
2036 if "quantization" in data:
2037 group = data.pop(
"quantization")
2038 if "calibration" in group:
2039 data[
"calibration"] = group[
"calibration"]
2041 data[
"bit"] = group[
"bit"]
2042 if "advancedQuantization" in data:
2043 group = data.pop(
"advancedQuantization")
2044 if "hessianQuant" in group:
2045 data[
"hessianQuant"] = group[
"hessianQuant"]
2046 if "layerBiasCorrection" in group:
2047 data[
"layerBiasCorrection"] = group[
"layerBiasCorrection"]
2049 data[
"mod"] = group[
"mod"]
2050 if "EquivalentTransformation" in group:
2051 data[
"equivalentTransformation"] = group[
"EquivalentTransformation"]
2052 if "searchWeightScale" in group:
2053 data[
"searchWeightScale"] = group[
"searchWeightScale"]
2054 if "loadScale" in group:
2055 data[
"loadScale"] = group[
"loadScale"]
2060 """Load config from a preset."""
2061 from .presets
import get_preset
2063 return get_preset(name)
2067 """Group flat keys back into nested JSON structure (inverse of _flatten_grouped_json)."""
2069 quantization_group = {}
2070 if "calibration" in data:
2071 quantization_group[
"calibration"] = data.pop(
"calibration")
2073 quantization_group[
"bit"] = data.pop(
"bit")
2074 if quantization_group:
2075 data[
"quantization"] = quantization_group
2076 advancedQuantization_group = {}
2077 if "hessianQuant" in data:
2078 advancedQuantization_group[
"hessianQuant"] = data.pop(
"hessianQuant")
2079 if "layerBiasCorrection" in data:
2080 advancedQuantization_group[
"layerBiasCorrection"] = data.pop(
2081 "layerBiasCorrection"
2084 advancedQuantization_group[
"mod"] = data.pop(
"mod")
2085 if "equivalentTransformation" in data:
2086 advancedQuantization_group[
"EquivalentTransformation"] = data.pop(
2087 "equivalentTransformation"
2089 if "searchWeightScale" in data:
2090 advancedQuantization_group[
"searchWeightScale"] = data.pop(
2093 if "loadScale" in data:
2094 advancedQuantization_group[
"loadScale"] = data.pop(
"loadScale")
2095 if advancedQuantization_group:
2096 data[
"advancedQuantization"] = advancedQuantization_group
2099 def to_file(self, path: Union[str, Path]) ->
None:
2100 """Save config to YAML or JSON file."""
2102 data = self.model_dump(by_alias=
True, exclude_none=
True)
2104 with open(path,
"w")
as f:
2105 if path.suffix
in (
".yaml",
".yml"):
2106 yaml.dump(data, f, default_flow_style=
False)
2108 json.dump(data, f, indent=2)
Configuration for bit precision.
"BitConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for calibration during quantization.
"CalibrationConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Unified compilation configuration for Mobilint MXQ compilation.
"CompileConfig" with_llm(self, **kwargs)
Return a copy with llm settings enabled.
PreprocessingConfig preprocessing
"CompileConfig" from_preset(cls, str name)
Load config from a preset.
"CompileConfig" with_search_weight_scale(self, **kwargs)
Return a copy with search_weight_scale settings enabled.
LoadScaleConfig load_scale
Uint8InputConfig uint8_input
SearchWeightScaleConfig search_weight_scale
HessianQuantConfig hessian_quant
"CompileConfig" with_layer_bias_correction(self, **kwargs)
Return a copy with layer_bias_correction settings enabled.
LayerBiasCorrectionConfig layer_bias_correction
"CompileConfig" with_load_scale(self, **kwargs)
Return a copy with load_scale settings enabled.
SaveSampleConfig save_sample
"CompileConfig" with_preprocessing(self, **kwargs)
Return a copy with preprocessing settings enabled.
dict _flatten_grouped_json(dict data)
Flatten grouped JSON keys (e.g.
"CompileConfig" with_mod(self, **kwargs)
Return a copy with mod settings enabled.
"CompileConfig" with_hessian_quant(self, **kwargs)
Return a copy with hessian_quant settings enabled.
dict _group_to_json(dict data)
Group flat keys back into nested JSON structure (inverse of _flatten_grouped_json).
"CompileConfig" with_save_sample(self, **kwargs)
Return a copy with save_sample settings enabled.
"CompileConfig" from_file(cls, Union[str, Path] path)
Load config from YAML or JSON file.
None to_file(self, Union[str, Path] path)
Save config to YAML or JSON file.
"CompileConfig" with_uint8_input(self, **kwargs)
Return a copy with uint8_input settings enabled.
Configuration for HessianQuant algorithm.
"HessianQuantConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for calibration-derived layer bias correction.
"LayerBiasCorrectionConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for Large Language Model (LLM) compilation.
"LlmConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
"LoadScaleConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for Minimum Output Difference algorithm.
"ModConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Sparse MoE expert-selection configuration (calibration only)
"MoeConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for input preprocessing pipeline.
"PreprocessingConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Weight memory management configuration.
Configuration for resource management during model compilation.
"ResourceManagementConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Runtime options for compilation.
"RuntimeOptions" with_updates(self, **kwargs)
Return a copy with updated fields.
Sample data generation and saving configuration.
"SaveSampleConfig" with_updates(self, **kwargs)
Return a copy with updated fields.
Configuration for weight scale search.
"SearchWeightScaleConfig" with_updates(self, **kwargs)
Return a copy with updated fields.