MCPcopy
hub / github.com/OpenPPL/ppq / export_quantization_config

Method export_quantization_config

ppq/parser/tengine_exporter.py:91–125  ·  view source on GitHub ↗
(self, config_path: str, graph: BaseGraph)

Source from the content-addressed store, hash-verified

89 file.write(f"{k} {scale} {zp}\n")
90
91 def export_quantization_config(self, config_path: str, graph: BaseGraph):
92
93 render_buffer = {"configs": {}, "dispatchings": {}, "values": {}}
94
95 # Render quantization config.
96 for operation in graph.operations.values():
97 if isinstance(operation, QuantableOperation):
98 op_dict = {
99 var.name: {
100 "bit_width": config.num_of_bits,
101 "policy": config.policy.to_dict(),
102 "state": config.state.name,
103 "quant_min": config.quant_min,
104 "quant_max": config.quant_max,
105 "hash": config.__hash__(),
106 "dominator": config.dominated_by.__hash__(),
107 }
108 for config, var in operation.config_with_variable
109 }
110
111 for config, _ in operation.config_with_variable:
112 if config.policy.has_property(QuantizationProperty.PER_CHANNEL):
113 raise PermissionError('Tengine does not support per channel quantization.')
114
115 if config.dominated_by == config:
116 render_buffer["values"][config.__hash__()] = {
117 "scale": config.scale.item(),
118 "zero_point": config.offset.item(),
119 }
120
121 render_buffer["configs"][operation.name] = op_dict
122 render_buffer["dispatchings"][operation.name] = operation.platform.name
123
124 with open(file=config_path, mode="w") as file:
125 json.dump(render_buffer, file, indent=4)
126
127 def export_operation(self, operation: Operation) -> onnx.OperatorProto:
128 if operation.type in OPERATION_EXPORTERS:

Callers 1

exportMethod · 0.95

Calls 3

to_dictMethod · 0.80
has_propertyMethod · 0.80
__hash__Method · 0.45

Tested by

no test coverage detected