MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _op_to_colocate_with

Function _op_to_colocate_with

tensorflow/python/framework/ops.py:6673–6696  ·  view source on GitHub ↗

Operation object corresponding to v to use for colocation constraints.

(v, graph)

Source from the content-addressed store, hash-verified

6671
6672
6673def _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
6699def _is_keras_symbolic_tensor(x):

Callers 1

colocate_withMethod · 0.85

Calls 2

captureMethod · 0.45

Tested by

no test coverage detected