Set a global eager mode seed for random ops.
(self, seed)
| 421 | # pylint: enable=redefined-outer-name |
| 422 | |
| 423 | def _set_global_seed(self, seed): |
| 424 | """Set a global eager mode seed for random ops.""" |
| 425 | self._seed = seed |
| 426 | # `random.Random(seed)` needs `seed` to be hashable, while values of type |
| 427 | # e.g. `np.int64` or `np.ndarray` are not. We use `int(...)` to convert them |
| 428 | # to int. |
| 429 | try: |
| 430 | hash(seed) |
| 431 | except TypeError: |
| 432 | seed = int(np.array(seed)) |
| 433 | self._rng = random.Random(seed) |
| 434 | # Also clear the kernel cache, to reset any existing seeds |
| 435 | if self._context_handle is not None: |
| 436 | pywrap_tensorflow.TFE_ContextClearCaches(self._context_handle) |
| 437 | |
| 438 | def _internal_operation_seed(self): |
| 439 | """Returns a fake operation seed. |