(op, gradient_uid, ignore_existing=False)
| 5269 | |
| 5270 | |
| 5271 | def _colocate_with_for_gradient(op, gradient_uid, ignore_existing=False): |
| 5272 | if context.executing_eagerly(): |
| 5273 | if op is not None: |
| 5274 | if not hasattr(op, "device"): |
| 5275 | op = internal_convert_to_tensor_or_indexed_slices(op) |
| 5276 | return device(op.device) |
| 5277 | else: |
| 5278 | return NullContextmanager() |
| 5279 | else: |
| 5280 | default_graph = get_default_graph() |
| 5281 | if isinstance(op, EagerTensor): |
| 5282 | if default_graph.building_function: |
| 5283 | return default_graph.device(op.device) |
| 5284 | else: |
| 5285 | raise ValueError("Encountered an Eager-defined Tensor during graph " |
| 5286 | "construction, but a function was not being built.") |
| 5287 | return default_graph._colocate_with_for_gradient( |
| 5288 | op, gradient_uid=gradient_uid, ignore_existing=ignore_existing) |
| 5289 | |
| 5290 | |
| 5291 | # Internal interface to colocate_with. colocate_with has been deprecated from |
no test coverage detected