qbcompiler.configs.equivalent_transformation_config¶
EquivalentTransformationConfig¶
Configuration for equivalent transformation techniques.
This includes various transformation methods like NormConv, QK, UD, VO, FeedForwardMultiLUT, SpinR1, HeadOutChRotation, SpinR2, QKRotation, and FlattenQuant.
Attributes¶
| Name | Description |
|---|---|
optional |
|
py_to_cpp_name |
|
DEFAULTS |
|
min_max_check |
optional¶
py_to_cpp_name¶
DEFAULTS¶
DEFAULTS = {
"seed": 0,
"apply_hadamard_rotation_matrix": True,
# NormConv
"norm_conv_apply": False,
"norm_conv_learn": False,
"norm_conv_smoothing_factor": 0.5,
"norm_conv_min_gamma": 0.0001,
"norm_conv_max_gamma": 10000.0,
# QK
"qk_apply": False,
"qk_smoothing_factor": 0.5,
"qk_min_gamma": 0.0001,
"qk_max_gamma": 10000.0,
# UD
"ud_apply": False,
"ud_learn": False,
"ud_smoothing_factor": 0.5,
"ud_min_gamma": 0.0001,
"ud_max_gamma": 10000.0,
# VO
"vo_apply": False,
"vo_smoothing_factor": 0.5,
"vo_min_gamma": 0.0001,
"vo_max_gamma": 10000.0,
# FeedForwardMultiLUT
"ff_multi_lut_apply": False,
"ff_multi_lut_breakpoints": [-8.0, -4.0, 0],
# SpinR1
"spin_r1_apply": False,
"spin_r1_matrix_path": "",
# HeadOutChRotation
"head_out_ch_rotation_apply": False,
"head_out_ch_rotation_matrix_path": "",
# SpinR2
"spin_r2_apply": False,
"spin_r2_learn": False,
"spin_r2_matrix_path": "",
# QKRotation
"qk_rotation_apply": False,
"qk_rotation_matrix_path": "",
# FlattenQuant
"flatten_quant_apply": False,
"flatten_quant_learn": False,
"flatten_quant_apply_threshold": 0.33,
"flatten_quant_max_overhead": 0.05,
# OptimizeFFN
"optimize_ffn_apply": False,
"optimize_ffn_ch_per_ffn": -1,
}
min_max_check¶
min_max_check = {
"norm_conv_smoothing_factor": [0.0, 1.0],
"norm_conv_min_gamma": [0.0, None],
"norm_conv_max_gamma": [0.0, None],
"qk_smoothing_factor": [0.0, 1.0],
"qk_min_gamma": [0.0, None],
"qk_max_gamma": [0.0, None],
"ud_smoothing_factor": [0.0, 1.0],
"ud_min_gamma": [0.0, None],
"ud_max_gamma": [0.0, None],
"vo_smoothing_factor": [0.0, 1.0],
"vo_min_gamma": [0.0, None],
"vo_max_gamma": [0.0, None],
"flatten_quant_apply_threshold": [0.0, 1.0],
"flatten_quant_max_overhead": [0.0, None],
}
Methods¶
| Name | Description |
|---|---|
__init__ |
Initialize the EquivalentTransformationConfig. |
check_valid |
Override to skip py_to_cpp_name check (uses nested structure in to_dict) |
default_config |
|
from_dict |
Create EquivalentTransformationConfig from dictionary (JSON structure) |
to_dict |
__init__¶
def __init__(
self,
seed: int,
apply_hadamard_rotation_matrix: bool,
# NormConv
norm_conv_apply: bool,
norm_conv_learn: bool,
norm_conv_smoothing_factor: float,
norm_conv_min_gamma: float,
norm_conv_max_gamma: float,
# QK
qk_apply: bool,
qk_smoothing_factor: float,
qk_min_gamma: float,
qk_max_gamma: float,
# UD
ud_apply: bool,
ud_learn: bool,
ud_smoothing_factor: float,
ud_min_gamma: float,
ud_max_gamma: float,
# VO
vo_apply: bool,
vo_smoothing_factor: float,
vo_min_gamma: float,
vo_max_gamma: float,
# FeedForwardMultiLUT
ff_multi_lut_apply: bool,
ff_multi_lut_breakpoints: List[float],
# SpinR1
spin_r1_apply: bool,
spin_r1_matrix_path: str,
# HeadOutChRotation
head_out_ch_rotation_apply: bool,
head_out_ch_rotation_matrix_path: str,
# SpinR2
spin_r2_apply: bool,
spin_r2_learn: bool,
spin_r2_matrix_path: str,
# QKRotation
qk_rotation_apply: bool,
qk_rotation_matrix_path: str,
# FlattenQuant
flatten_quant_apply: bool,
flatten_quant_learn: bool,
flatten_quant_apply_threshold: float,
flatten_quant_max_overhead: float,
# OptimizeFFN
optimize_ffn_apply: bool,
optimize_ffn_ch_per_ffn: int,
optional: bool = optional,
)
Initialize the EquivalentTransformationConfig.
Parameters
seed— int. Random seed used for equivalent transformation operations. Default is 0.apply_hadamard_rotation_matrix— bool. If True, apply the Hadamard rotation matrix where applicable. Default is True.
NormConv¶
Parameters
norm_conv_apply— bool. If True, enable NormConv transformation. Default is False.norm_conv_learn— bool. If True, learn NormConv parameters during calibration/optimization. Default is False.norm_conv_smoothing_factor— float. Smoothing factor used in NormConv. Default is 0.5.norm_conv_min_gamma— float. Minimum gamma value (lower bound clamp) for NormConv. Default is 0.0001.norm_conv_max_gamma— float. Maximum gamma value (upper bound clamp) for NormConv. Default is 10000.0.
QK¶
Parameters
qk_apply— bool. If True, enable QK transformation. Default is False.qk_smoothing_factor— float. Smoothing factor used in QK. Default is 0.5.qk_min_gamma— float. Minimum gamma value (lower bound clamp) for QK. Default is 0.0001.qk_max_gamma— float. Maximum gamma value (upper bound clamp) for QK. Default is 10000.0.
UD¶
Parameters
ud_apply— bool. If True, enable UD transformation. Default is False.ud_learn— bool. If True, learn UD parameters during calibration/optimization. Default is False.ud_smoothing_factor— float. Smoothing factor used in UD. Default is 0.5.ud_min_gamma— float. Minimum gamma value (lower bound clamp) for UD. Default is 0.0001.ud_max_gamma— float. Maximum gamma value (upper bound clamp) for UD. Default is 10000.0.
VO¶
Parameters
vo_apply— bool. If True, enable VO transformation. Default is False.vo_smoothing_factor— float. Smoothing factor used in VO. Default is 0.5.vo_min_gamma— float. Minimum gamma value (lower bound clamp) for VO. Default is 0.0001.vo_max_gamma— float. Maximum gamma value (upper bound clamp) for VO. Default is 10000.0.
FeedForwardMultiLUT¶
Parameters
ff_multi_lut_apply— bool. If True, enable FeedForward Multi-LUT. Default is False.ff_multi_lut_breakpoints— List[float]. Breakpoints used for FeedForward Multi-LUT piecewise regions. Default is [-8.0, -4.0, 0].
SpinR1¶
Parameters
spin_r1_apply— bool. If True, enable SpinR1 rotation. Default is False.spin_r1_matrix_path— str. Path to the SpinR1 rotation matrix file. Default is "".
HeadOutChRotation¶
Parameters
head_out_ch_rotation_apply— bool. If True, enable HeadOutChRotation. Default is False.head_out_ch_rotation_matrix_path— str. Path to the HeadOutChRotation matrix file. Default is "".
SpinR2¶
Parameters
spin_r2_apply— bool. If True, enable SpinR2 rotation. Default is False.spin_r2_learn— bool. If True, learn the SpinR2 rotation matrix/parameters during calibration/optimization. Default is False.spin_r2_matrix_path— str. Path to the SpinR2 rotation matrix file. Default is "".
QKRotation¶
Parameters
qk_rotation_apply— bool. If True, enable QKRotation. Default is False.qk_rotation_matrix_path— str. Path to the QKRotation matrix file. Default is "".
FlattenQuant¶
Parameters
flatten_quant_apply— bool. If True, enable FlattenQuant. Default is False.flatten_quant_learn— bool. If True, learn FlattenQuant parameters during calibration/optimization. Default is False.flatten_quant_apply_threshold— float. Threshold for applying FlattenQuant. Default is 0.33.flatten_quant_max_overhead— float. Maximum allowed overhead when applying FlattenQuant. Default is 0.05.
OptimizeFFN¶
Parameters
optimize_ffn_apply— bool. If True, enable OptimizeFFN. Default is False.optimize_ffn_ch_per_ffn— int. Number of channels per FFN used when OptimizeFFN is enabled. Default is -1.optional— bool. Indicates whether this config is optional. Use the default value defined as a class variable.
check_valid¶
Override to skip py_to_cpp_name check (uses nested structure in to_dict)
default_config¶
from_dict¶
Create EquivalentTransformationConfig from dictionary (JSON structure)
to_dict¶
Functions¶
| Name | Description |
|---|---|
get_equivalent_transformation_config |
Create EquivalentTransformationConfig with partial parameters merged with defaults. |
get_equivalent_transformation_config¶
Create EquivalentTransformationConfig with partial parameters merged with defaults.