r""" Update the lifetime of the tensor to cover node_idx. A tensor's lifetime are represented by the index of the first and last node referring that tensor in its inputs/outputs. Arguments: spec: the TensorSpec for the tensor node_idx: extend the tensor's lifetime to
(
node: torch.fx.Node,
spec: TensorSpec,
node_idx: int,
max_node_idx: int,
gs: Optional[ExportGraphSignature] = None,
)
| 441 | |
| 442 | |
| 443 | def update_tensor_lifetime( |
| 444 | node: torch.fx.Node, |
| 445 | spec: TensorSpec, |
| 446 | node_idx: int, |
| 447 | max_node_idx: int, |
| 448 | gs: Optional[ExportGraphSignature] = None, |
| 449 | ) -> None: |
| 450 | r""" |
| 451 | Update the lifetime of the tensor to cover node_idx. A tensor's lifetime |
| 452 | are represented by the index of the first and last node referring |
| 453 | that tensor in its inputs/outputs. |
| 454 | |
| 455 | Arguments: |
| 456 | spec: the TensorSpec for the tensor |
| 457 | node_idx: extend the tensor's lifetime to cover node_idx |
| 458 | """ |
| 459 | start, end = spec.lifetime |
| 460 | if node.op == "placeholder": |
| 461 | start = 0 |
| 462 | else: |
| 463 | start = node_idx if start is None or start > node_idx else start |
| 464 | |
| 465 | if node.op == "placeholder" and _is_mutable_buffer(node, gs): |
| 466 | # mutable buffers are never freed |
| 467 | end = max_node_idx |
| 468 | else: |
| 469 | end = node_idx if end is None or end < node_idx else end |
| 470 | spec.lifetime = [start, end] |
| 471 | |
| 472 | |
| 473 | # pyre-ignore |
no test coverage detected