|
| 1 | +# Copyright 2021 Google LLC. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Check that version of TensorFlow is compatible with TF-DF.""" |
| 16 | + |
| 17 | +import logging |
| 18 | +import tensorflow as tf |
| 19 | + |
| 20 | + |
| 21 | +def check_version(tf_df_version, |
| 22 | + compatible_tf_versions, |
| 23 | + tf_version=None, |
| 24 | + external_logic=False): |
| 25 | + """Checks the compatibility of the TF version. |
| 26 | +
|
| 27 | + Prints a warning message and return False in care of likely incompatible |
| 28 | + versions. |
| 29 | + """ |
| 30 | + |
| 31 | + if not external_logic: |
| 32 | + |
| 33 | + if tf_version is None: |
| 34 | + tf_version = tf.__version__ |
| 35 | + if tf_version not in compatible_tf_versions: |
| 36 | + logging.warning( |
| 37 | + "TensorFlow Decision Forests %s is compatible with the following " |
| 38 | + "TensorFlow Versions: %s. However, TensorFlow %s was detected. " |
| 39 | + "This can cause issues with the TF API and symbols in the custom C++ " |
| 40 | + "ops. See the TF and TF-DF compatibility table at " |
| 41 | + "https://github.com/tensorflow/decision-forests/blob/main/documentation/known_issues.md#compatibility-table.", |
| 42 | + tf_df_version, compatible_tf_versions, tf_version) |
| 43 | + return False |
| 44 | + return True |
| 45 | + |
| 46 | + |
| 47 | +def info_fail_to_load_custom_op(exception): |
| 48 | + logging.warning("Failure to load the custom c++ tensorflow ops. " |
| 49 | + "This error is likely caused the version of TensorFlow and " |
| 50 | + "TensorFlow Decision Forests are not compatible.") |
0 commit comments