Skip to content

Commit a6593bd

Browse files
authored
Fix bug in export using FQ ONNX in replacing activation holder with more than 8 bits with identity (#1464)
* Fix bug in export using FQ ONNX in replacing activation holder with more than 8 bits with identity
1 parent 35697d2 commit a6593bd

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

model_compression_toolkit/exporter/model_exporter/pytorch/fakely_quant_onnx_pytorch_exporter.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,18 @@ def export(self, output_names=None) -> None:
7878
act_holder_list = [n for n, m in self.model.named_modules()
7979
if isinstance(m, PytorchActivationQuantizationHolder) and
8080
m.activation_holder_quantizer.num_bits > 8]
81-
for act_holder in act_holder_list: # pragma: no cover
82-
delattr(self.model, act_holder)
83-
setattr(self.model, act_holder, torch.nn.Identity())
81+
for act_holder in act_holder_list: # pragma: no cover
82+
obj = self.model
83+
attrs = act_holder.split(".")
84+
for a in attrs[:-1]:
85+
obj = getattr(obj, a)
86+
if hasattr(obj, attrs[-1]):
87+
delattr(obj, attrs[-1])
88+
setattr(obj, attrs[-1], torch.nn.Identity())
89+
else:
90+
Logger.info(f"During removal of activation quantization of a quantizer (with bits > 8) in ONNX FQ "
91+
f"export, deletion of activation holder '{act_holder}' failed — could not locate one or"
92+
f"more intermediate attributes in the path.")
8493

8594
for layer in self.model.children():
8695
self.is_layer_exportable_fn(layer)

0 commit comments

Comments
 (0)