truncate your graph, so that all operations behind outputs(function parameter) will be eliminated. A list of output variable is given as parameter of this function. PPQ will goes forward from all those variables, mark all downstream operations for removing. A truncated graph object
(graph: BaseGraph, outputs: List[str])
| 4 | |
| 5 | |
| 6 | def truncate_graph(graph: BaseGraph, outputs: List[str]): |
| 7 | """truncate your graph, so that all operations behind outputs(function |
| 8 | parameter) will be eliminated. A list of output variable is given as |
| 9 | parameter of this function. PPQ will goes forward from all those variables, |
| 10 | mark all downstream operations for removing. |
| 11 | |
| 12 | A truncated graph object will return as result. |
| 13 | |
| 14 | ATTENTION: do not attempt to delete input variable. |
| 15 | ATTETNION: you should invoke this function before quantization. |
| 16 | |
| 17 | Args: |
| 18 | graph (BaseGraph): graph to be truncated |
| 19 | outputs (List[str]): truncating from where |
| 20 | |
| 21 | Raises: |
| 22 | KeyError: truncating variable is not in graph |
| 23 | |
| 24 | Returns: |
| 25 | [type]: truncated graph |
| 26 | """ |
| 27 | for output in outputs: |
| 28 | if output not in graph.variables: |
| 29 | raise KeyError(f'Can not find variable {output} in current graph.') |
| 30 | processor = GraphFormatter(graph) |
| 31 | |
| 32 | for output in outputs: |
| 33 | output_var = graph.variables[output] |
| 34 | processor.truncate_on_var(output_var, mark_as_output=True) |
| 35 | processor.delete_isolated() |
| 36 | return graph |
nothing calls this directly
no test coverage detected