Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress OpenMP debug messages when running Tensorflow on CPU

When running a Python program on Linux that includes import tensorflow (installed without GPU support), a bunch of OpenMP debug messages are written to stdout, even when no functions from the tensorflow module are ever called. Here's an excerpt:

OMP: Info #212: KMP_AFFINITY: decoding x2APIC ids.
OMP: Info #210: KMP_AFFINITY: Affinity capable, using global cpuid leaf 11 info
OMP: Info #154: KMP_AFFINITY: Initial OS proc set respected: 0-3
OMP: Info #156: KMP_AFFINITY: 4 available OS procs
OMP: Info #157: KMP_AFFINITY: Uniform topology

Setting os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' before importing tensorflow does not get rid of these messages, how can I suppress them (from Python)?

like image 497
Peter Avatar asked May 10 '19 21:05

Peter


2 Answers

Bottom line: Set KMP_WARNINGS envvar to a false value (0,FALSE, off or no).

(If you use a multiple process setup, make sure to do this before you spawn child processes so that they inherit it.)


Googling "Affinity capable, using global cpuid leaf" (with quotes -- i.e. as a full phrase) finds https://github.com/catboost/catboost/blob/master/contrib/libs/cxxsupp/openmp/i18n/en_US.txt . It's a part of an OpenMP implementation. This code is not a part of tensorflow (and searching within https://github.com/tensorflow/tensorflow specifically for the phrase or a submodule reference named "openmp" finds nothing) but this is understandable because OpenMP is a part of a compiler implementation (this file specifically claims to be a part of LLVM -- i.e. clang). This code may not be exactly what your program is using but another version of it, but we can assume that the general logic is the same, so we can use this code for navigation.

Now, searching for references to the entity containing this phrase (namely, AffUseGlobCpuidL11 -- this is the ID of the message), then for a definition of KMP_INFORM, then for a definition of __kmp_msg ultimately finds the code doing the logging. It says that it only silences a message if ( severity != kmp_ms_fatal && __kmp_generate_warnings == kmp_warnings_off ). Looking through references to __kmp_generate_warnings to find where it's assigned finds https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_settings.c#L944 and looking for __kmp_stg_parse_warnings finds https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_settings.c#L4514 which suggests that name is "KMP_WARNINGS".

At this point, I assumed that this name should be documented. So googling for it will tell me faster how that "KMP_WARNINGS" is supposed to be set by the user and what the allowed values for it are. I was disappointed -- no official documentation comes up. Another result suggests though that it's an envvar, and valid values are: "Use "0", "FALSE". ".F.", "off", "no" as false values, "1", "TRUE", ".T.", "on", "yes" as true values." The source code also uses kmp_warnings_low as a possible value but the name __kmp_stg_parse_bool suggests that no, the user can only provide a "true" and "false" value, nothing else. The above filter criterion says that nothing but kmp_warnings_off would have an effect anyway, and https://github.com/catboost/catboost/blob/15712cfa704413d51618455326c30f5764956be5/contrib/libs/cxxsupp/openmp/kmp_global.c#L116 says that low is the default if nothing is provided by the user.

like image 161
ivan_pozdeev Avatar answered Nov 20 '22 11:11

ivan_pozdeev


As the other answer told me what to do but not exactly how to do it, I decided to add my answer.

If you want to suppress these warnings, you can do so by setting the KMP_WARNINGS environment variable to a false value. In code, you can do this as follows; in your script you need to first import os and then set the environ variable, like so:

import os
os.environ["KMP_WARNINGS"] = "FALSE" 

Any false value works here as long its a string format, "0" , "off" and "no" will also work.

like image 2
Psychotechnopath Avatar answered Nov 20 '22 11:11

Psychotechnopath