Skip to content

Commit

Permalink
chore(tf): filter TF deprecation warnings
Browse files Browse the repository at this point in the history
Fix deepmodeling#2367. Fix deepmodeling#3069.

These warnings are not true - these deprecated APIs have existed for several years and never been removed.

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Oct 10, 2024
1 parent 3939786 commit 3101e8e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions deepmd/tf/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Module that sets tensorflow working environment and exports inportant constants."""

import ctypes
import logging
import os
import platform
from importlib import (
Expand Down Expand Up @@ -75,17 +76,27 @@ def dlopen_library(module: str, filename: str):
dlopen_library("nvidia.cusparse.lib", "libcusparse.so*")
dlopen_library("nvidia.cudnn.lib", "libcudnn.so*")


FILTER_MSGS = [
"is deprecated and will be removed in a future version.",
"disable_mixed_precision_graph_rewrite() called when mixed precision is already disabled.",
]


class TFWarningFilter(logging.Filter):
def filter(self, record):
return not any(msg in record.getMessage().strip() for msg in FILTER_MSGS)


# keras 3 is incompatible with tf.compat.v1
# https://keras.io/getting_started/#tensorflow--keras-2-backwards-compatibility
# 2024/04/24: deepmd.tf doesn't import tf.keras any more

# import tensorflow v1 compatability
try:
import tensorflow.compat.v1 as tf
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
except ImportError:
import tensorflow as tf
tf.get_logger().addFilter(TFWarningFilter())
tf.disable_v2_behavior()
try:
import tensorflow.compat.v2 as tfv2
except ImportError:
Expand Down

0 comments on commit 3101e8e

Please sign in to comment.