Creates a new Context. Args: config: (Optional.) A `ConfigProto` protocol buffer with configuration options for the Context. Note that a lot of these options may be currently unimplemented or irrelevant when eager execution is enabled. device_policy: (Optional.) What
(self,
config=None,
device_policy=None,
execution_mode=None,
server_def=None)
| 330 | # TODO(agarwal): create and link in some documentation for `execution_mode`. |
| 331 | # pylint: disable=redefined-outer-name |
| 332 | def __init__(self, |
| 333 | config=None, |
| 334 | device_policy=None, |
| 335 | execution_mode=None, |
| 336 | server_def=None): |
| 337 | """Creates a new Context. |
| 338 | |
| 339 | Args: |
| 340 | config: (Optional.) A `ConfigProto` protocol buffer with configuration |
| 341 | options for the Context. Note that a lot of these options may be |
| 342 | currently unimplemented or irrelevant when eager execution is enabled. |
| 343 | device_policy: (Optional.) What policy to use when trying to run an |
| 344 | operation on a device with inputs which are not on that device. |
| 345 | When set to None, an appropriate value will be picked automatically. |
| 346 | The value picked may change between TensorFlow releases. |
| 347 | |
| 348 | Defaults to DEVICE_PLACEMENT_SILENT. |
| 349 | Valid values: |
| 350 | - DEVICE_PLACEMENT_EXPLICIT: raises an error if the placement is |
| 351 | not correct. |
| 352 | - DEVICE_PLACEMENT_WARN: copies the tensors which are not on the |
| 353 | right device but raises a warning. |
| 354 | - DEVICE_PLACEMENT_SILENT: silently copies the tensors. This might |
| 355 | hide performance problems. |
| 356 | - DEVICE_PLACEMENT_SILENT_FOR_INT32: silently copies int32 tensors, |
| 357 | raising errors on the other ones. |
| 358 | execution_mode: (Optional.) Policy controlling how operations dispatched |
| 359 | are actually executed. When set to None, an appropriate value will be |
| 360 | picked automatically. The value picked may change between TensorFlow |
| 361 | releases. |
| 362 | Valid values: |
| 363 | - SYNC: executes each operation synchronously. |
| 364 | - ASYNC: executes each operation asynchronously. These |
| 365 | operations may return "non-ready" handles. |
| 366 | server_def: (Optional.) A tensorflow::ServerDef proto. |
| 367 | Enables execution on remote devices. GrpcServers need to be started by |
| 368 | creating an identical server_def to this, and setting the appropriate |
| 369 | task_indexes, so that the servers can communicate. It will then be |
| 370 | possible to execute operations on remote devices. |
| 371 | |
| 372 | Raises: |
| 373 | ValueError: If execution_mode is not valid. |
| 374 | """ |
| 375 | # This _id is used only to index the tensor caches. |
| 376 | # TODO(iga): Remove this when tensor caches are moved to C++. |
| 377 | self._id = _context_id_counter.increment_and_get() |
| 378 | self._tensor_cache_deleter = _TensorCacheDeleter(self._id) |
| 379 | _tensor_caches_map[self._id] = _TensorCaches() |
| 380 | |
| 381 | self._config = config |
| 382 | self._thread_local_data = _ThreadLocalData() |
| 383 | self._context_switches = _ContextSwitchStack(self.executing_eagerly()) |
| 384 | self._context_handle = None |
| 385 | self._context_devices = None |
| 386 | self._seed = None |
| 387 | self._initialize_lock = threading.Lock() |
| 388 | self._initialized = False |
| 389 | if device_policy is None: |
no test coverage detected