Standardize update ops. Arguments: x: Tensor, op, or callable. Returns: An update op.
(x)
| 1294 | relevant_inputs = [node.input_tensors for node in inbound_nodes] |
| 1295 | |
| 1296 | def process_update(x): |
| 1297 | """Standardize update ops. |
| 1298 | |
| 1299 | Arguments: |
| 1300 | x: Tensor, op, or callable. |
| 1301 | |
| 1302 | Returns: |
| 1303 | An update op. |
| 1304 | """ |
| 1305 | if callable(x): |
| 1306 | update = lambda: process_update(x()) |
| 1307 | if not ops.executing_eagerly_outside_functions(): |
| 1308 | # In V1 mode, call the callable right away and process. This is needed |
| 1309 | # for TPU strategy. |
| 1310 | return update() |
| 1311 | elif isinstance(x, ops.Operation): |
| 1312 | update = x |
| 1313 | elif hasattr(x, 'op'): |
| 1314 | update = x.op |
| 1315 | else: |
| 1316 | update = ops.convert_to_tensor(x) |
| 1317 | |
| 1318 | reachable = tf_utils.get_reachable_from_inputs(relevant_inputs, [update]) |
| 1319 | update._unconditional_update = update not in reachable |
| 1320 | return update |
| 1321 | |
| 1322 | updates = [process_update(x) for x in updates] |
| 1323 | # Non-callable Updates are run automatically inside `call` in V2, so |