MCPcopy Index your code
hub / github.com/OpenPPL/ppq / export

Method export

ppq/samples/Tutorial/targetPlatform.py:131–149  ·  view source on GitHub ↗
(self, file_path: str, graph: BaseGraph, config_path: str, **kwargs)

Source from the content-addressed store, hash-verified

129 return value.tolist()
130
131 def export(self, file_path: str, graph: BaseGraph, config_path: str, **kwargs):
132 # ------------------------------------------------------------
133 # 接下来我们将导出量化信息,在 PPQ 中所有的量化信息都绑定在 Op 上
134 # 因此我们需要遍历图中所有的 Op, 将绑定在其上的量化信息导出到文件
135 # ------------------------------------------------------------
136 with open(config_path, 'w') as file:
137 for name, op in graph.operations.items():
138 if not isinstance(op, QuantableOperation): continue
139
140 for cfg, var in op.config_with_variable:
141 file.write(f"{name}: {var.name}\n")
142 file.write(f"Quant State: {cfg.state.name}\n")
143 file.write(f"Scale: {self.convert_value(cfg.scale)}\n")
144 file.write(f"Offset: {self.convert_value(cfg.offset)}\n")
145
146 # ------------------------------------------------------------
147 # 最后我们导出完整的计算图到 onnx
148 # ------------------------------------------------------------
149 onnx.save(self.export_graph(graph=graph), file_path)
150
151
152# ------------------------------------------------------------

Callers 9

yolo6_sample.pyFile · 0.45
fp8_sample.pyFile · 0.45
bert_sample.pyFile · 0.45
fp8_sample.pyFile · 0.45
myquantizer.pyFile · 0.45
imagenet.pyFile · 0.45
export_onnxFunction · 0.45
export_onnxFunction · 0.45
export_onnxFunction · 0.45

Calls 3

convert_valueMethod · 0.95
saveMethod · 0.80
export_graphMethod · 0.80

Tested by

no test coverage detected