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

[tools/mec] Add quantization parameters to tensor information #14374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 21 additions & 9 deletions tools/model_explorer_circle/src/model_explorer_circle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,27 @@ def add_output_tensor_info(self,
tensor_shape = self.dict_tensor_type_to_string[tensor.type].lower()
tensor_shape += f'{tensor.shape.tolist()}'
tensor_name = tensor.name.decode('utf-8')
me_node.outputsMetadata.append(
graph_builder.MetadataItem(
id=f'{output_id}',
attrs=[
graph_builder.KeyValue(key='shape', value=tensor_shape),
graph_builder.KeyValue(key='tensor_index', value=f'{tensor_id}'),
graph_builder.KeyValue(key='tensor_name', value=tensor_name)
],
))

metadata = graph_builder.MetadataItem(
id=f'{output_id}',
attrs=[
graph_builder.KeyValue(key='shape', value=tensor_shape),
graph_builder.KeyValue(key='tensor_index', value=f'{tensor_id}'),
graph_builder.KeyValue(key='tensor_name', value=tensor_name)
],
)

# Quantization parameter (if exists)
if tensor.quantization:
# Show the most significant 6 digits of the scale
scale = format(tensor.quantization.scale[0], '.6g')
zp = tensor.quantization.zeroPoint[0]
# If the type is larger than INT8, exponential notation will be used
quantparam = f'{scale} * (q + {zp})'
metadata.attrs.append(
graph_builder.KeyValue(key='quantization', value=quantparam))

me_node.outputsMetadata.append(metadata)

def build_graph(self, me_graph: graph_builder.Graph) -> None:
"""Build the graph using the model."""
Expand Down