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 ONNX export for MobileBERT #1539

Merged
merged 3 commits into from
Apr 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ def _propagate_mobilebert_embedding_quantization(model: ModelProto):
continue

embedding_array = numpy_helper.to_array(embedding_initializer)
if embedding_array.dtype != numpy.uint8:
if embedding_array.dtype not in [numpy.uint8, numpy.int8]:
continue

dequant_node = graph.get_node_single_child(gather_node)
Expand Down Expand Up @@ -1805,12 +1805,15 @@ def _propagate_mobilebert_embedding_quantization(model: ModelProto):
# switch position of dequantize node
for branch_node in graph.get_node_children(dequant_node):
if branch_node.op_type == "Slice":
zero_point = graph.get_init_by_name(dequant_node.input[2])
zero_point_array = numpy_helper.to_array(zero_point)
branch_node.input[0] = gather_node.output[0]
pad_node = graph.get_node_single_child(branch_node)
pad_value = graph.get_init_by_name(pad_node.input[2])
pad_value_array = numpy_helper.to_array(pad_value)
pad_value_array = pad_value_array + 128
pad_value_array = pad_value_array.astype(numpy.uint8)
pad_value_array = (
pad_value_array.astype(zero_point_array.dtype) + zero_point_array
)
model.graph.initializer.remove(pad_value)
pad_value = numpy_helper.from_array(
pad_value_array, name=pad_value.name
Expand Down