Runs inference using custom CPU reference implementations
| 30 | |
| 31 | @mod.export() |
| 32 | class PluginRefRunner(BaseRunner): |
| 33 | """ |
| 34 | Runs inference using custom CPU reference implementations |
| 35 | """ |
| 36 | |
| 37 | def __init__(self, graph, name=None): |
| 38 | """ |
| 39 | Args: |
| 40 | graph (Union[onnx_graphsurgeon.Graph, Callable() -> onnx_graphsurgeon.Graph]): |
| 41 | An ONNX-GraphSurgeon graph or a callable that returns one. |
| 42 | name (str): |
| 43 | The human-readable name prefix to use for this runner. |
| 44 | A runner count and timestamp will be appended to this prefix. |
| 45 | """ |
| 46 | super().__init__(name=name, prefix="pluginref-runner") |
| 47 | self._graph = graph |
| 48 | |
| 49 | @util.check_called_by("activate") |
| 50 | def activate_impl(self): |
| 51 | self.graph, _ = util.invoke_if_callable(self._graph) |
| 52 | |
| 53 | @util.check_called_by("get_input_metadata") |
| 54 | def get_input_metadata_impl(self): |
| 55 | return onnx_util.meta_from_gs_tensors(self.graph.inputs) |
| 56 | |
| 57 | @util.check_called_by("infer") |
| 58 | def infer_impl(self, feed_dict): |
| 59 | start = time.time() |
| 60 | |
| 61 | intermediate_tensors = copy.copy(feed_dict) |
| 62 | for node in self.graph.nodes: |
| 63 | if node.op not in OP_REGISTRY: |
| 64 | G_LOGGER.critical(f"Op: {node.op} does not have a reference implementation registered!") |
| 65 | |
| 66 | intermediate_tensors.update(OP_REGISTRY[node.op](node, intermediate_tensors)) |
| 67 | |
| 68 | outputs = OrderedDict() |
| 69 | for out in self.graph.outputs: |
| 70 | outputs[out.name] = intermediate_tensors[out.name] |
| 71 | |
| 72 | end = time.time() |
| 73 | |
| 74 | self.inference_time = end - start |
| 75 | return outputs |
| 76 | |
| 77 | @util.check_called_by("deactivate") |
| 78 | def deactivate_impl(self): |
| 79 | del self.graph |
no outgoing calls