Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion model_compression_toolkit/core/common/graph/base_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ def override_fused_node_activation_quantization_candidates(self):
if fusing_op_quantization_cfg is not None and fusing_op_quantization_cfg.enable_activation_quantization:
def update(qc):
qc.activation_quantization_cfg = NodeActivationQuantizationConfig(fusing_op_quantization_cfg)
qc.activation_quantization_cfg.quant_mode = ActivationQuantizationMode.FLN_QUANT
qc.activation_quantization_cfg.set_quant_mode(ActivationQuantizationMode.FLN_QUANT)
node.quantization_cfg.update_all(update, remove_duplicates=True)
else:
node.quantization_cfg.update_activation_quantization_mode(ActivationQuantizationMode.FLN_NO_QUANT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def __init__(self, origin_node: BaseNode, kernel_attr: str):
base_quantization_cfg=None, validate=False
)
for c in self.quantization_cfg.candidates_quantization_cfg:
c.activation_quantization_cfg.quant_mode = ActivationQuantizationMode.NO_QUANT
c.activation_quantization_cfg.activation_n_bits = FLOAT_BITWIDTH
c.activation_quantization_cfg.set_quant_mode(ActivationQuantizationMode.NO_QUANT)


class VirtualSplitActivationNode(VirtualSplitNode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ def _build_mp_model(self, graph, outputs, disable_activations: bool) -> Tuple[An
# be added to the model).
for n in evaluation_graph.get_topo_sorted_nodes():
if disable_activations or not n.has_configurable_activation():
for c in n.candidates_quantization_cfg:
c.activation_quantization_cfg.quant_mode = ActivationQuantizationMode.NO_QUANT
n.quantization_cfg.update_activation_quantization_mode(ActivationQuantizationMode.NO_QUANT)
if not n.has_any_configurable_weight():
for c in n.candidates_quantization_cfg:
c.weights_quantization_cfg.disable_all_weights_quantization()
n.quantization_cfg.disable_weights_quantization()

model_mp, _, conf_node2layers = self.fw_impl.model_builder(evaluation_graph,
mode=ModelBuilderMode.MIXEDPRECISION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ class NodeQuantizationConfig:

validate: InitVar[bool] = True

def __post_init__(self, validate=True):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can __post_init__ take input arguments?

if validate:
if not any(self.base_quantization_cfg == qc for qc in self.candidates_quantization_cfg):
raise ValueError('Candidates should contain the base config.')
self._validate_consistent_activation_quant_mode()
self._validate_consistent_weights_quant_mode()

self.remove_duplicates()

# TODO irena
# for now make sure they are separate objects so that one doesnt inadvertently modify the other
if any(self.base_quantization_cfg is qc for qc in self.candidates_quantization_cfg):
self.base_quantization_cfg = copy.deepcopy(self.base_quantization_cfg)

def update_all(self, update_fn: Callable[[CandidateNodeQuantizationConfig], None], remove_duplicates: bool = True):
"""
Apply update function on the base config and all candidates configs.
Expand All @@ -69,7 +83,7 @@ def update_activation_quantization_mode(self, mode: ActivationQuantizationMode):
mode: quantization mode.
"""
def fn(c):
c.activation_quantization_cfg.quant_mode = mode
c.activation_quantization_cfg.set_quant_mode(mode)

self.update_all(fn)

Expand Down Expand Up @@ -102,17 +116,6 @@ def remove_duplicates(self):
uniq_qcs.append(qc)
self.candidates_quantization_cfg = uniq_qcs

def __post_init__(self, validate=True):
if validate:
if not any(self.base_quantization_cfg == qc for qc in self.candidates_quantization_cfg):
raise ValueError('Candidates should contain the base config.')
self._validate_consistent_activation_quant_mode()
self._validate_consistent_weights_quant_mode()
# TODO irena
# for now make sure they are separate objects so that one doesnt inadvertently modify the other
if any(self.base_quantization_cfg is qc for qc in self.candidates_quantization_cfg):
self.base_quantization_cfg = copy.deepcopy(self.base_quantization_cfg)

def _validate_consistent_activation_quant_mode(self):
"""
Validate that base config and all candidates configs contain identical activation quantization mode.
Expand Down

This file was deleted.

Loading
Loading