Enables eager execution for the lifetime of this program. Most of the doc string for enable_eager_execution is relevant here as well. Args: config: See enable_eager_execution doc string device_policy: See enable_eager_execution doc string execution_mode: See enable_eager_execution
(config=None,
device_policy=None,
execution_mode=None,
server_def=None)
| 5815 | |
| 5816 | |
| 5817 | def enable_eager_execution_internal(config=None, |
| 5818 | device_policy=None, |
| 5819 | execution_mode=None, |
| 5820 | server_def=None): |
| 5821 | """Enables eager execution for the lifetime of this program. |
| 5822 | |
| 5823 | Most of the doc string for enable_eager_execution is relevant here as well. |
| 5824 | |
| 5825 | Args: |
| 5826 | config: See enable_eager_execution doc string |
| 5827 | device_policy: See enable_eager_execution doc string |
| 5828 | execution_mode: See enable_eager_execution doc string |
| 5829 | server_def: (Optional.) A tensorflow::ServerDef proto. Enables execution on |
| 5830 | remote devices. GrpcServers need to be started by creating an identical |
| 5831 | server_def to this, and setting the appropriate task_indexes, so that the |
| 5832 | servers can communicate. It will then be possible to execute operations on |
| 5833 | remote devices. |
| 5834 | |
| 5835 | Raises: |
| 5836 | ValueError |
| 5837 | |
| 5838 | """ |
| 5839 | if config is not None and not isinstance(config, config_pb2.ConfigProto): |
| 5840 | raise TypeError("config must be a tf.ConfigProto, but got %s" % |
| 5841 | type(config)) |
| 5842 | if device_policy not in (None, context.DEVICE_PLACEMENT_EXPLICIT, |
| 5843 | context.DEVICE_PLACEMENT_WARN, |
| 5844 | context.DEVICE_PLACEMENT_SILENT, |
| 5845 | context.DEVICE_PLACEMENT_SILENT_FOR_INT32): |
| 5846 | raise ValueError( |
| 5847 | "device_policy must be one of None, tf.contrib.eager.DEVICE_PLACEMENT_*" |
| 5848 | ) |
| 5849 | if execution_mode not in (None, context.SYNC, context.ASYNC): |
| 5850 | raise ValueError( |
| 5851 | "execution_mode must be one of None, tf.contrib.eager.SYNC, " |
| 5852 | "tf.contrib.eager.ASYNC") |
| 5853 | if context.default_execution_mode == context.GRAPH_MODE: |
| 5854 | graph_mode_has_been_used = ( |
| 5855 | _default_graph_stack._global_default_graph is not None) # pylint: disable=protected-access |
| 5856 | if graph_mode_has_been_used: |
| 5857 | raise ValueError( |
| 5858 | "tf.enable_eager_execution must be called at program startup.") |
| 5859 | context.default_execution_mode = context.EAGER_MODE |
| 5860 | # pylint: disable=protected-access |
| 5861 | with context._context_lock: |
| 5862 | if context._context is None: |
| 5863 | context._set_context_locked(context.Context( |
| 5864 | config=config, |
| 5865 | device_policy=device_policy, |
| 5866 | execution_mode=execution_mode, |
| 5867 | server_def=server_def)) |
| 5868 | elif ((config is not None and config is not context._context._config) or |
| 5869 | (device_policy is not None and |
| 5870 | device_policy is not context._context._device_policy) or |
| 5871 | (execution_mode is not None and |
| 5872 | execution_mode is not context._context._execution_mode)): |
| 5873 | raise ValueError( |
| 5874 | "Trying to change the options of an active eager" |
no test coverage detected