Skip to content

Commit

Permalink
修改onnxexporter的导出逻辑 (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangZhiPku authored May 27, 2022
1 parent 3b9d7ae commit 54c0e3f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Empty file added ppq/IR/base/core.py
Empty file.
2 changes: 1 addition & 1 deletion ppq/IR/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def decompose_gemm(self):
output_var = op.outputs[0]

if op.num_of_input == 3:
bias_add = graph.create_operation(op_type='Add')
bias_add = graph.create_operation(op_type='Add', platform=op.platform)
bias_var = op.inputs[-1]

graph.create_link_with_op(
Expand Down
9 changes: 5 additions & 4 deletions ppq/parser/onnxruntime_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ def convert_operation(self, graph: BaseGraph, op: QuantableOperation,
for config, var in op.config_with_variable:
meta = var.meta
if var.is_parameter:
if not op.is_computing_op: continue

# we do not want to process clip value here.
if op.type in {'Clip'}: continue

assert len(var.dest_ops) == 1, (
f'Can not export variable {var.name}, cause it has more than 1 destination operations. '
'PPQ require all parameters to have only 1 destination operation.')
Expand All @@ -293,7 +294,7 @@ def convert_operation(self, graph: BaseGraph, op: QuantableOperation,
if config.state == QuantizationStates.PASSIVE_BAKED:
config.state = QuantizationStates.PASSIVE

if QuantizationStates.is_activated(config.state):
if QuantizationStates.can_export(config.state):
# if not quant parameter to int, all parameter should export as fp32.
# needs insert both quant and dequant op for them
if not quant_param_to_int:
Expand All @@ -309,7 +310,7 @@ def convert_operation(self, graph: BaseGraph, op: QuantableOperation,
else:
if not process_activation: continue

if QuantizationStates.is_activated(config.state):
if QuantizationStates.can_export(config.state):
created = self.insert_quant_on_variable(
graph=graph, var=var, config=config, related_op=op, meta=meta)
var = created.outputs[0]
Expand Down
7 changes: 2 additions & 5 deletions ppq/quantization/analyse/layerwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,14 @@ def layerwise_error_analyse(
fp_outputs = executor.forward(inputs=batch, output_names=interested_outputs)

# manually override quantization state
for cfg, _ in operation.config_with_variable:
cfg.state = QuantizationStates.ACTIVATED
operation.restore_quantize_state()
qt_outputs = executor.forward(inputs=batch, output_names=interested_outputs)

for fp_output, qt_output in zip(fp_outputs, qt_outputs):
recorder.update(y_pred = qt_output, y_real = fp_output)

# manually override quantization state
for cfg, _ in operation.config_with_variable:
cfg.state = QuantizationStates.DEQUANTIZED

operation.dequantize()
if idx >= steps: break

# restore quantization states
Expand Down

0 comments on commit 54c0e3f

Please sign in to comment.