Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fetch op rename_input bug in QAT export model #38012

Merged
merged 1 commit into from
Dec 10, 2021
Merged
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
11 changes: 8 additions & 3 deletions python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def save_quantized_model(self, model, path, input_spec=None, **config):
model_filename=model_filename,
params_filename=params_filename))

self._gather_scales(infer_program, scope)
self._gather_scales(infer_program, scope, fetch_targets)

self._set_skip_quant_attr(infer_program)

Expand Down Expand Up @@ -520,10 +520,10 @@ def _is_target_layer(self, layer):

return flag

def _gather_scales(self, program, scope):
def _gather_scales(self, program, scope, fetch_targets):
"""
Get all scales from fake ops, save them into the corresponding ops
and delete all moving_average_abs_max_scale ops.
and delete all moving_average_abs_max_scale ops.
"""

def _gather_input_scale():
Expand Down Expand Up @@ -580,6 +580,11 @@ def _gather_output_scale():

for next_op in next_ops:
next_op._rename_input(out_var_name, in_var_name)
# If next_op is `fetch` and out_var_name in fetch_targets,
# fetch_targets must update to in_var_name when rename input.
for i in range(len(fetch_targets)):
if fetch_targets[i].name == out_var_name:
fetch_targets[i] = block.var(in_var_name)

_gather_input_scale()
_gather_output_scale()
Expand Down