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,
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.
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.