{"id":15651690,"url":"https://github.com/lucacappelletti94/silence_tensorflow","last_synced_at":"2025-04-07T10:26:29.001Z","repository":{"id":57467191,"uuid":"188526719","full_name":"LucaCappelletti94/silence_tensorflow","owner":"LucaCappelletti94","description":"Python package to shut up Tensorflow warnings and logs. ","archived":false,"fork":false,"pushed_at":"2024-11-03T21:51:10.000Z","size":83,"stargazers_count":34,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T06:03:56.960Z","etag":null,"topics":["tensorflow","utility"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucaCappelletti94.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"LucaCappelletti94"}},"created_at":"2019-05-25T05:57:04.000Z","updated_at":"2025-03-16T19:57:25.000Z","dependencies_parsed_at":"2024-10-03T12:39:51.545Z","dependency_job_id":"084e0956-0c55-4d79-a1fa-b87415d16978","html_url":"https://github.com/LucaCappelletti94/silence_tensorflow","commit_stats":{"total_commits":52,"total_committers":1,"mean_commits":52.0,"dds":0.0,"last_synced_commit":"d53a7fc53ea03bb968c3405db0bbe3afef91517c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fsilence_tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fsilence_tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fsilence_tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fsilence_tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucaCappelletti94","download_url":"https://codeload.github.com/LucaCappelletti94/silence_tensorflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634206,"owners_count":20970484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tensorflow","utility"],"created_at":"2024-10-03T12:39:43.627Z","updated_at":"2025-04-07T10:26:28.978Z","avatar_url":"https://github.com/LucaCappelletti94.png","language":"Python","readme":"# Silence TensorFlow\n\n[![pip](https://badge.fury.io/py/silence-tensorflow.svg)](https://pypi.org/project/silence-tensorflow/)\n[![python](https://img.shields.io/pypi/pyversions/silence-tensorflow)](https://pypi.org/project/silence-tensorflow/)\n[![license](https://img.shields.io/pypi/l/silence-tensorflow)](https://pypi.org/project/silence-tensorflow/)\n[![downloads](https://pepy.tech/badge/silence-tensorflow)](https://pepy.tech/project/silence-tensorflow)\n[![Github Actions](https://github.com/LucaCappelletti94/silence_tensorflow/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/silence_tensorflow/actions/)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/e6fe64db1c9042bbaa4c0a20bde585dc)](https://app.codacy.com/gh/LucaCappelletti94/silence_tensorflow/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\nPython package to shut up TensorFlow warnings and logs, letting you focus on the important errors.\n\n## How do I install this package?\n\nAs usual, just download it using pip:\n\n```shell\npip install silence_tensorflow\n```\n\n## How do I use it?\n\nYou only need to import the package before importing TensorFlow:\n\n```python\nfrom silence_tensorflow import silence_tensorflow\nsilence_tensorflow()\nimport tensorflow as tf\n\n# your code\n```\n\n### Setting the logging level\n\nWhile 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.\n\n```python\nfrom silence_tensorflow import silence_tensorflow\n\n# Set the logging level to error, meaning only errors will be logged\nsilence_tensorflow(\"ERROR\")\n\n# Set the logging level to warning, meaning only errors and warnings will be logged\nsilence_tensorflow(\"WARNING\")\n\n# Set the logging level to info, meaning errors, warnings and info will be logged\nsilence_tensorflow(\"INFO\")\n\n# Set the logging level to debug, meaning all logs will be shown\nsilence_tensorflow(\"DEBUG\")\n```\n\n## Can it be done within the import?\n\nSure, you can do everything with a single line by importing the submodule auto.\n\nThis will set the logging level to error and the affinity to no verbose.\n\n```python\nimport silence_tensorflow.auto\nimport tensorflow as tf\n\n# your code\n```\n\n## How can I get pylint to ignore the unused import?\n\nYou can use the flag `disable=unused-import` as such:\n\n```python\nimport silence_tensorflow.auto  # pylint: disable=unused-import\nimport tensorflow as tf\n\n# your code\n```\n\n## How can I get pylint to ignore the unused variable?\n\nIf 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:\n\n```python\ndef func():\n    import silence_tensorflow.auto  # pylint: disable=unused-variable\n    import tensorflow as tf\n\n    # your code\n```\n\n## How does this work under the hood?\n\nThis package will set the `KMP_AFFINITY` system variable to `noverbose` and `TF_CPP_MIN_LOG_LEVEL` to level `3` (only errors logged).\n\nIf you need a custom value for `KMP_AFFINITY` you should reset it after importing the package, as follows:\n\n```python\nimport os\nfrom silence_tensorflow import silence_tensorflow\nbackup = os.environ[\"KMP_AFFINITY\"]\nsilence_tensorflow()\nos.environ[\"KMP_AFFINITY\"] = backup\n```\n\n## Known limitations\n\nWhile I really tried to cover all possible logs that TensorFlow can produce, there are some logs that are not silenced by this package.\nBelow 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.\n\n### NUMA node read from SysFS had negative value\n\nYou may have encountered the following log:\n\n```plaintext\nsuccessful NUMA node read from SysFS had negative value (-1)\n```\n\nThis 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:\n\n```bash\nfor a in /sys/bus/pci/devices/*; do echo 0 | sudo tee -a $a/numa_node; done\n```\n\nThis 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.\n\n### TensorFlow Lite (TFLite)\n\nTFLite logs are not silenced by this package because [they have hardcoded the logging level to `INFO`](https://github.com/tensorflow/tensorflow/blob/3570f6d986066b834a7f54f3c3ec60d0245193bd/tensorflow/lite/minimal_logging_ios.cc#L50) and there is no way to change it from the Python side.\n\nTFLite will cause info logs such as the following to be printed:\n\n```plaintext\nINFO: Created TensorFlow Lite XNNPACK delegate for CPU.\n```\n\nIf 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](https://github.com/tensorflow/tensorflow/issues/58050#issuecomment-1624919480):\n\n```cpp\ntflite::LoggerOptions::SetMinimumLogSeverity(tflite::TFLITE_LOG_SILENT);\n```\n\n### oneDNN warning\n\nAnother common warning that TensorFlow prints is the following:\n\n```plaintext\nI 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`.\n```\n\nI 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.\n\n## License\n\nThis software is distributed under the MIT License.\n","funding_links":["https://github.com/sponsors/LucaCappelletti94"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fsilence_tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucacappelletti94%2Fsilence_tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fsilence_tensorflow/lists"}