Record a graph for ``position`` and keep its static input buffers.
(self, position, args, kwargs)
| 105 | self._use_graphs = True |
| 106 | |
| 107 | def _capture(self, position, args, kwargs): |
| 108 | """Record a graph for ``position`` and keep its static input buffers.""" |
| 109 | static = {name: kwargs[name].clone() for name in _tensor_kwargs(kwargs)} |
| 110 | capture_kwargs = dict(kwargs) |
| 111 | capture_kwargs.update(static) |
| 112 | |
| 113 | graph = get_accelerator().create_graph() |
| 114 | if self._pool is None: |
| 115 | with get_accelerator().capture_to_graph(graph): |
| 116 | output = self._forward(*args, **capture_kwargs) |
| 117 | self._pool = graph.pool() |
| 118 | else: |
| 119 | with get_accelerator().capture_to_graph(graph, pool=self._pool): |
| 120 | output = self._forward(*args, **capture_kwargs) |
| 121 | |
| 122 | self._graphs[position] = graph |
| 123 | self._static_kwargs[position] = static |
| 124 | self._static_outputs[position] = output |
| 125 | |
| 126 | def _replay(self, position, kwargs): |
| 127 | for name, buffer in self._static_kwargs[position].items(): |
no test coverage detected