Common logic for creating an op in this graph.
(self, op, compute_device=True)
| 3464 | return ret |
| 3465 | |
| 3466 | def _create_op_helper(self, op, compute_device=True): |
| 3467 | """Common logic for creating an op in this graph.""" |
| 3468 | # Apply any additional attributes requested. Do not overwrite any existing |
| 3469 | # attributes. |
| 3470 | for key, value in self._attr_scope_map.items(): |
| 3471 | try: |
| 3472 | op.get_attr(key) |
| 3473 | except ValueError: |
| 3474 | if callable(value): |
| 3475 | value = value(op.node_def) |
| 3476 | if not isinstance(value, (type(None), attr_value_pb2.AttrValue)): |
| 3477 | raise TypeError( |
| 3478 | "Callable for scope map key '%s' must return either None or " |
| 3479 | "an AttrValue protocol buffer; but it returned: %s" % |
| 3480 | (key, value)) |
| 3481 | if value: |
| 3482 | op._set_attr(key, value) # pylint: disable=protected-access |
| 3483 | |
| 3484 | # Apply a kernel label if one has been specified for this op type. |
| 3485 | try: |
| 3486 | kernel_label = self._op_to_kernel_label_map[op.type] |
| 3487 | op._set_attr("_kernel", # pylint: disable=protected-access |
| 3488 | attr_value_pb2.AttrValue(s=compat.as_bytes(kernel_label))) |
| 3489 | except KeyError: |
| 3490 | pass |
| 3491 | |
| 3492 | # Apply the overriding op type for gradients if one has been specified for |
| 3493 | # this op type. |
| 3494 | try: |
| 3495 | mapped_op_type = self._gradient_override_map[op.type] |
| 3496 | op._set_attr("_gradient_op_type", # pylint: disable=protected-access |
| 3497 | attr_value_pb2.AttrValue(s=compat.as_bytes(mapped_op_type))) |
| 3498 | except KeyError: |
| 3499 | pass |
| 3500 | |
| 3501 | self._record_op_seen_by_control_dependencies(op) |
| 3502 | |
| 3503 | if compute_device: |
| 3504 | self._apply_device_functions(op) |
| 3505 | self._apply_gpu_stream(op) |
| 3506 | |
| 3507 | # Snapshot the colocation stack metadata before we might generate error |
| 3508 | # messages using it. Note that this snapshot depends on the actual stack |
| 3509 | # and is independent of the op's _class attribute. |
| 3510 | # pylint: disable=protected-access |
| 3511 | op._colocation_code_locations = self._snapshot_colocation_stack_metadata() |
| 3512 | # pylint: enable=protected-access |
| 3513 | |
| 3514 | if self._colocation_stack: |
| 3515 | all_colocation_groups = [] |
| 3516 | for colocation_op in self._colocation_stack.peek_objs(): |
| 3517 | all_colocation_groups.extend(colocation_op.colocation_groups()) |
| 3518 | if colocation_op.device: |
| 3519 | # pylint: disable=protected-access |
| 3520 | op._set_device(colocation_op.device) |
| 3521 | # pylint: enable=protected-access |
| 3522 | try: |
| 3523 | stream_idx = colocation_op.get_attr("_stream_id") |
no test coverage detected