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

dequantize matmul and matmul_v2 Y weights in quant2_int8 #37618

Merged
merged 8 commits into from
Dec 1, 2021
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self,
self._mul_ops = ['mul']
self._fc_ops = ['fc']
self._relu_ops = ['relu', 'relu6']
self._matmul_ops = ['matmul']
self._matmul_ops = ['matmul', 'matmul_v2']
self._gru_ops = ['fusion_gru', 'multi_gru']
self._lstm_ops = ['fusion_lstm']
self._weight_thresholds = {}
Expand Down Expand Up @@ -328,6 +328,8 @@ def _swap_inputs(self, op, old_input, new_input):
def _dequantize_weights(self, graph):
def _is_int8_weights(op_node, weight_name):
weight_var_name = op_node.input(weight_name)[0]
if self._scope.find_var(weight_var_name) is None:
return False
weight = self._load_param(self._scope, weight_var_name)
return np.all(np.mod(weight, 1) == 0)

Expand All @@ -336,6 +338,9 @@ def _is_int8_weights(op_node, weight_name):
self._dequantize_op_weights(graph, op, "Filter", "Output")
elif op.name() in self._mul_ops and _is_int8_weights(op, "Y"):
self._dequantize_op_weights(graph, op, "Y", "Out")
elif op.name() in self._matmul_ops and _is_int8_weights(op, "Y"):
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you can combine this part into one and just check op.name() in [self._mul_ops, self._matmul_ops]. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can apply your idea, but I will concatenate those lists before for loop

Copy link
Contributor Author

@sfraczek sfraczek Nov 29, 2021

Choose a reason for hiding this comment

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

I wonder if we even need matmul_ops variable separate from mul_ops

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, it looks like we are doing exactly the same things for them, so for me you can combine it.

self._dequantize_op_weights(graph, op, "Y", "Out")

return graph

def _dequantize_op_weights(self, graph, op_node, weight_name, output_name):
Expand Down