(self, file_path: str, graph: BaseGraph, config_path: str, **kwargs)
| 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 | # ------------------------------------------------------------ |
no test coverage detected