Produces the content of `output_tensor` only after `dependencies`. In some cases, a user may want the output of an operation to be consumed externally only after some other dependencies have run first. This function ensures returns `output_tensor`, but only after all operations in `dependen
(dependencies, output_tensor, name=None)
| 2800 | |
| 2801 | |
| 2802 | def with_dependencies(dependencies, output_tensor, name=None): |
| 2803 | """Produces the content of `output_tensor` only after `dependencies`. |
| 2804 | |
| 2805 | In some cases, a user may want the output of an operation to be |
| 2806 | consumed externally only after some other dependencies have run |
| 2807 | first. This function ensures returns `output_tensor`, but only after all |
| 2808 | operations in `dependencies` have run. Note that this means that there is |
| 2809 | no guarantee that `output_tensor` will be evaluated after any `dependencies` |
| 2810 | have run. |
| 2811 | |
| 2812 | See also `tf.tuple` and `tf.group`. |
| 2813 | |
| 2814 | Args: |
| 2815 | dependencies: Iterable of operations to run before this op finishes. |
| 2816 | output_tensor: A `Tensor` or `IndexedSlices` that will be returned. |
| 2817 | name: (Optional) A name for this operation. |
| 2818 | |
| 2819 | Returns: |
| 2820 | Same as `output_tensor`. |
| 2821 | |
| 2822 | Raises: |
| 2823 | TypeError: if `output_tensor` is not a `Tensor` or `IndexedSlices`. |
| 2824 | """ |
| 2825 | if context.executing_eagerly(): |
| 2826 | return output_tensor |
| 2827 | with ops.name_scope(name, "control_dependency", |
| 2828 | list(dependencies) + [output_tensor]) as name: |
| 2829 | with ops.colocate_with(output_tensor): |
| 2830 | with ops.control_dependencies(dependencies): |
| 2831 | output_tensor = ops.convert_to_tensor_or_composite(output_tensor) |
| 2832 | if isinstance(output_tensor, ops.Tensor): |
| 2833 | return _Identity(output_tensor, name=name) |
| 2834 | else: |
| 2835 | return ops.IndexedSlices( |
| 2836 | _Identity(output_tensor.values, name=name), output_tensor.indices, |
| 2837 | output_tensor.dense_shape) |
| 2838 | |
| 2839 | |
| 2840 | def _GroupControlDeps(dev, deps, name=None): |
no test coverage detected