Modifies the global environment for running TensorBoard as main. This functions changes global state in the Python process, so it should not be called from library routines.
()
| 33 | |
| 34 | |
| 35 | def global_init(): |
| 36 | """Modifies the global environment for running TensorBoard as main. |
| 37 | |
| 38 | This functions changes global state in the Python process, so it should |
| 39 | not be called from library routines. |
| 40 | """ |
| 41 | # TF versions prior to 1.15.0 included default GCS filesystem caching logic |
| 42 | # that interacted pathologically with the pattern of reads used by TensorBoard |
| 43 | # for logdirs. See: https://github.com/tensorflow/tensorboard/issues/1225 |
| 44 | # The problematic behavior was fixed in 1.15.0 by |
| 45 | # https://github.com/tensorflow/tensorflow/commit/e43b94649d3e1ac5d538e4eca9166b899511d681 |
| 46 | # but for older versions of TF, we avoid a regression by setting this env var to |
| 47 | # disable the cache, which must be done before the first import of tensorflow. |
| 48 | os.environ["GCS_READ_CACHE_DISABLED"] = "1" |
| 49 | |
| 50 | if getattr(tf, "__version__", "stub") == "stub": |
| 51 | print( |
| 52 | "TensorFlow installation not found - running with reduced feature set.", |
| 53 | file=sys.stderr, |
| 54 | ) |
| 55 | |
| 56 | # Only emit log messages at WARNING and above by default to reduce spam. |
| 57 | absl.logging.set_verbosity(absl.logging.WARNING) |
| 58 | |
| 59 | # Intercept attempts to invoke `tensorboard dev` and print turndown message. |
| 60 | if sys.argv[1:] and sys.argv[1] == "dev": |
| 61 | sys.stderr.write(_TBDEV_SHUTDOWN_MESSAGE) |
| 62 | sys.stderr.flush() |
| 63 | sys.exit(1) |