Operation object corresponding to v to use for colocation constraints.
(v, graph)
| 6671 | |
| 6672 | |
| 6673 | def _op_to_colocate_with(v, graph): |
| 6674 | """Operation object corresponding to v to use for colocation constraints.""" |
| 6675 | if v is None: |
| 6676 | return None |
| 6677 | if isinstance(v, Operation): |
| 6678 | return v |
| 6679 | # We always want to colocate with the reference op. |
| 6680 | # When 'v' is a ResourceVariable, the reference op is the handle creating op. |
| 6681 | # |
| 6682 | # What this should be is: |
| 6683 | # if isinstance(v, ResourceVariable): |
| 6684 | # return v.handle.op |
| 6685 | # However, that would require a circular import dependency. |
| 6686 | # As of October 2018, there were attempts underway to remove |
| 6687 | # colocation constraints altogether. Assuming that will |
| 6688 | # happen soon, perhaps this hack to work around the circular |
| 6689 | # import dependency is acceptable. |
| 6690 | if hasattr(v, "handle") and hasattr(v.handle, "op") and isinstance( |
| 6691 | v.handle.op, Operation): |
| 6692 | if graph.building_function: |
| 6693 | return graph.capture(v.handle).op |
| 6694 | else: |
| 6695 | return v.handle.op |
| 6696 | return internal_convert_to_tensor_or_indexed_slices(v, as_ref=True).op |
| 6697 | |
| 6698 | |
| 6699 | def _is_keras_symbolic_tensor(x): |
no test coverage detected