Selectively captures external tensors. If `whitelisted` is False only allows capturing tensors in the `_forward_graph`. Args: tensor: Tensor. May be from this FuncGraph or a different graph. name: Optional name if a placeholder is created. whitelisted: If False (defau
(self, tensor, name=None, whitelisted=False)
| 896 | return self.empty_tensor_lists |
| 897 | |
| 898 | def capture(self, tensor, name=None, whitelisted=False): |
| 899 | """Selectively captures external tensors. |
| 900 | |
| 901 | If `whitelisted` is False only allows capturing tensors in the |
| 902 | `_forward_graph`. |
| 903 | |
| 904 | Args: |
| 905 | tensor: Tensor. May be from this FuncGraph or a different graph. |
| 906 | name: Optional name if a placeholder is created. |
| 907 | whitelisted: If False (default), only allows capturing tensors from the |
| 908 | forward graph. |
| 909 | |
| 910 | Returns: |
| 911 | The placeholder in this graph for the tensor. |
| 912 | |
| 913 | Raises: |
| 914 | ValueError: If attempting to capture an external tensor not in the forward |
| 915 | graph with `whitelisted` set to False. |
| 916 | """ |
| 917 | if (not whitelisted and tensor.graph is not self and |
| 918 | tensor.graph != self._forward_graph): |
| 919 | raise ValueError("Attempting to capture tensor %s which is not in the " |
| 920 | "forward graph but in %s." % |
| 921 | (str(tensor), _graph_name(tensor.graph))) |
| 922 | return super(_WhileBodyGradFuncGraph, self).capture(tensor, name) |
| 923 | |
| 924 | def _capture_helper(self, tensor, name): |
| 925 | if tensor.graph is not self._forward_graph: |
no test coverage detected