I have been working with TensorFlow Extended (TFX) for about a month and a half now and there has always been one thing that really bothers me about it. The logging and mountain of stdout outputs from TFX pipeline (regardless of the orchestrator).
My end-goal is to only have logs/stdouts that I have defined because it makes unit tests cleaner, debugging faster, and storage of logs much cheaper. So far I have figured out how to suppress the TFX logs and other dependencies' logs with the code below.
Suppressing TFX logs:
import absl.logging
import logging
absl.logging.set_verbosity(absl.logging.FATAL)
Suppressing TensroFlow Logs (must be before TensorFlow import)
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
import tensorflow as tf
GoogleLogging outputs the following warning multiple times.
WARNING: Logging before InitGoogleLogging() is written to STDERR
I1007 12:09:16.761006 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:16.797765 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:16.826467 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:16.862852 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:16.907064 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:18.094507 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
I1007 12:09:18.169688 802336 rdbms_metadata_access_object.cc:686] No property is defined for the Type
They were suppressed with this:
os.environ["GLOG_minloglevel"] = "3"
Setuptools (I believe) causes the following warning multiple times
warning: install_lib: byte-compiling is disabled, skipping.
Suppressed with the following:
os.environ["PYTHONDONTWRITEBYTECODE"] = '0'
The problem is after all of that there still in a ton of stdout that I don't care about and that I cannot figure out how to suppress. A "small" snippet of the remaining output is below.
running bdist_wheel
running build
running build_py
creating build
creating build/lib
copying penguin_utils_cloud_tuner.py -> build/lib
copying penguin_utils_keras.py -> build/lib
copying penguin_utils_flax_experimental.py -> build/lib
copying penguin_utils_base.py -> build/lib
copying penguin_pipeline_local.py -> build/lib
copying penguin_pipeline_kubeflow.py -> build/lib
copying penguin_pipeline_local_infraval.py -> build/lib
copying penguin_pipeline_local_e2e_test.py -> build/lib
copying penguin_pipeline_kubeflow_test.py -> build/lib
copying penguin_pipeline_local_infraval_e2e_test.py -> build/lib
copying penguin_pipeline_kubeflow_e2e_test.py -> build/lib
installing to /tmp/tmpcop1boxs
running install
running install_lib
copying build/lib/penguin_utils_cloud_tuner.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_utils_keras.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_utils_flax_experimental.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_utils_base.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_local.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_kubeflow.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_local_infraval.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_local_e2e_test.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_kubeflow_test.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_local_infraval_e2e_test.py -> /tmp/tmpcop1boxs
copying build/lib/penguin_pipeline_kubeflow_e2e_test.py -> /tmp/tmpcop1boxs
running install_egg_info
running egg_info
creating tfx_user_code_Transform.egg-info
writing tfx_user_code_Transform.egg-info/PKG-INFO
writing dependency_links to tfx_user_code_Transform.egg-info/dependency_links.txt
writing top-level names to tfx_user_code_Transform.egg-info/top_level.txt
writing manifest file 'tfx_user_code_Transform.egg-info/SOURCES.txt'
reading manifest file 'tfx_user_code_Transform.egg-info/SOURCES.txt'
writing manifest file 'tfx_user_code_Transform.egg-info/SOURCES.txt'
Copying tfx_user_code_Transform.egg-info to /tmp/tmpcop1boxs/tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3.7.egg-info
running install_scripts
creating /tmp/tmpcop1boxs/tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/WHEEL
creating '/tmp/tmpbx4f359i/tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3-none-any.whl' and adding '/tmp/tmpcop1boxs' to it
adding 'penguin_pipeline_kubeflow.py'
adding 'penguin_pipeline_kubeflow_e2e_test.py'
adding 'penguin_pipeline_kubeflow_test.py'
adding 'penguin_pipeline_local.py'
adding 'penguin_pipeline_local_e2e_test.py'
adding 'penguin_pipeline_local_infraval.py'
adding 'penguin_pipeline_local_infraval_e2e_test.py'
adding 'penguin_utils_base.py'
adding 'penguin_utils_cloud_tuner.py'
adding 'penguin_utils_flax_experimental.py'
adding 'penguin_utils_keras.py'
adding 'tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/METADATA'
adding 'tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/WHEEL'
adding 'tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/top_level.txt'
adding 'tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/RECORD'
removing /tmp/tmpcop1boxs
running bdist_wheel
running build
running build_py
creating build
creating build/lib
copying penguin_utils_cloud_tuner.py -> build/lib
copying penguin_utils_keras.py -> build/lib
copying penguin_utils_flax_experimental.py -> build/lib
copying penguin_utils_base.py -> build/lib
copying penguin_pipeline_local.py -> build/lib
copying penguin_pipeline_kubeflow.py -> build/lib
copying penguin_pipeline_local_infraval.py -> build/lib
copying penguin_pipeline_local_e2e_test.py -> build/lib
copying penguin_pipeline_kubeflow_test.py -> build/lib
copying penguin_pipeline_local_infraval_e2e_test.py -> build/lib
copying penguin_pipeline_kubeflow_e2e_test.py -> build/lib
installing to /tmp/tmp61fu93hi
running install
running install_lib
copying build/lib/penguin_utils_cloud_tuner.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_utils_keras.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_utils_flax_experimental.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_utils_base.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_local.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_kubeflow.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_local_infraval.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_local_e2e_test.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_kubeflow_test.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_local_infraval_e2e_test.py -> /tmp/tmp61fu93hi
copying build/lib/penguin_pipeline_kubeflow_e2e_test.py -> /tmp/tmp61fu93hi
running install_egg_info
running egg_info
creating tfx_user_code_Trainer.egg-info
writing tfx_user_code_Trainer.egg-info/PKG-INFO
writing dependency_links to tfx_user_code_Trainer.egg-info/dependency_links.txt
writing top-level names to tfx_user_code_Trainer.egg-info/top_level.txt
writing manifest file 'tfx_user_code_Trainer.egg-info/SOURCES.txt'
reading manifest file 'tfx_user_code_Trainer.egg-info/SOURCES.txt'
writing manifest file 'tfx_user_code_Trainer.egg-info/SOURCES.txt'
Copying tfx_user_code_Trainer.egg-info to /tmp/tmp61fu93hi/tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3.7.egg-info
running install_scripts
creating /tmp/tmp61fu93hi/tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/WHEEL
creating '/tmp/tmp07op38gs/tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3-none-any.whl' and adding '/tmp/tmp61fu93hi' to it
adding 'penguin_pipeline_kubeflow.py'
adding 'penguin_pipeline_kubeflow_e2e_test.py'
adding 'penguin_pipeline_kubeflow_test.py'
adding 'penguin_pipeline_local.py'
adding 'penguin_pipeline_local_e2e_test.py'
adding 'penguin_pipeline_local_infraval.py'
adding 'penguin_pipeline_local_infraval_e2e_test.py'
adding 'penguin_utils_base.py'
adding 'penguin_utils_cloud_tuner.py'
adding 'penguin_utils_flax_experimental.py'
adding 'penguin_utils_keras.py'
adding 'tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/METADATA'
adding 'tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/WHEEL'
adding 'tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/top_level.txt'
adding 'tfx_user_code_Trainer-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0.dist-info/RECORD'
removing /tmp/tmp61fu93hi
Processing /tmp/penguin_pipeline_local_e2e_test1ysjxxgo/tmpfld7ezwr/testPenguinPipelineLocal0/tfx/pipelines/penguin_test/_wheels/tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3-none-any.whl
Installing collected packages: tfx-user-code-Transform
Successfully installed tfx-user-code-Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0
Processing /tmp/penguin_pipeline_local_e2e_test1ysjxxgo/tmpfld7ezwr/testPenguinPipelineLocal0/tfx/pipelines/penguin_test/_wheels/tfx_user_code_Transform-0.0+cfe5891c75179075cb76fc27c0a1e243f1f37e33f5b5fe3d0a6572cc4e9b3fa0-py3-none-any.whl
Installing collected packages: tfx-user-code-Transform
I have tried redirecting the stdout and stderr with no luck. For example:
with contextlib.redirect_stdout(open(os.devnull, 'w')):
LocalDagRunner().run(pipeline)
and
with contextlib.redirect_stderr(open(os.devnull, 'w')):
LocalDagRunner().run(pipeline)
I know the remaining outputs look similar to the output of a pip install or similar build process, but I have not found a programic way of suppressing its output. HERE:How do I make `python setup.py test -q` quieter?, they suppress the output of a project using setuptools with python setup.py -q test. Since I am using TFX I am not expictly making the call that is producing the output so is there another way to do this? Maybe another enviroment variable?
Any help is greatly apprecaited!