Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Python package to shut up TensorFlow warnings and logs, letting you focus on the important errors.
As usual, just download it using pip:
pip install silence_tensorflow
You only need to import the package before importing TensorFlow:
from silence_tensorflow import silence_tensorflow
silence_tensorflow()
import tensorflow as tf
# your code
While by default the logging level is set to error, you can set it to any level you want by passing the level as an argument to the function.
from silence_tensorflow import silence_tensorflow
# Set the logging level to error, meaning only errors will be logged
silence_tensorflow("ERROR")
# Set the logging level to warning, meaning only errors and warnings will be logged
silence_tensorflow("WARNING")
# Set the logging level to info, meaning errors, warnings and info will be logged
silence_tensorflow("INFO")
# Set the logging level to debug, meaning all logs will be shown
silence_tensorflow("DEBUG")
Sure, you can do everything with a single line by importing the submodule auto.
This will set the logging level to error and the affinity to no verbose.
import silence_tensorflow.auto
import tensorflow as tf
# your code
You can use the flag disable=unused-import
as such:
import silence_tensorflow.auto # pylint: disable=unused-import
import tensorflow as tf
# your code
If you import silence_tensorflow
in the context of a function you will get a different warning from pylint: unused variable. You can use the flag disable=unused-variable
as such:
def func():
import silence_tensorflow.auto # pylint: disable=unused-variable
import tensorflow as tf
# your code
This package will set the KMP_AFFINITY
system variable to noverbose
and TF_CPP_MIN_LOG_LEVEL
to level 3
(only errors logged).
If you need a custom value for KMP_AFFINITY
you should reset it after importing the package, as follows:
import os
from silence_tensorflow import silence_tensorflow
backup = os.environ["KMP_AFFINITY"]
silence_tensorflow()
os.environ["KMP_AFFINITY"] = backup
While I really tried to cover all possible logs that TensorFlow can produce, there are some logs that are not silenced by this package. Below you find the ones that we are aware of, alongside the reason why they are not silenced and what you can do to silence them.
You may have encountered the following log:
successful NUMA node read from SysFS had negative value (-1)
This log means that TensorFlow is trying to read the NUMA node from the system file system and it is getting a negative value. This is not an error, but a warning, and this package cannot silence it automatically without administrative privileges. Since executing code you have just found online with administrative privileges is not a good idea, you can silence this log by running as root the following command in your terminal:
for a in /sys/bus/pci/devices/*; do echo 0 | sudo tee -a $a/numa_node; done
This command will set the NUMA node to 0 for all PCI devices, which is the default value and should not cause any issues. It does not fix the underlying issue, but it silences the log until you reboot your system.
TFLite logs are not silenced by this package because they have hardcoded the logging level to INFO
and there is no way to change it from the Python side.
TFLite will cause info logs such as the following to be printed:
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
If you are willing to recompile your own version of TensorFlow Lite, you can change the logging level to ERROR
by changing the line mentioned above or set it in your C++ code as follows, as described in this issue:
tflite::LoggerOptions::SetMinimumLogSeverity(tflite::TFLITE_LOG_SILENT);
Another common warning that TensorFlow prints is the following:
I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
I tried to automatically set the environment variable TF_ENABLE_ONEDNN_OPTS
to 0
when GPU drivers are detected and in such cases using oneDNN is not necessary. However, this in some instances lead to TensorFlow occasionally deadlocking and I had to revert the change.
This software is distributed under the MIT License.
FAQs
Simple python package to shut up Tensorflow warnings and logs.
We found that silence-tensorflow demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.