Skip to content

Commit

Permalink
Replace distutils's LooseVersion with packaging's Version
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698767136
  • Loading branch information
tensorflower-gardener committed Nov 22, 2024
1 parent ba90314 commit 0fcb483
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tensorflow_privacy/privacy/bolt_on/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
# limitations under the License.
"""BoltOn Method for privacy."""

from distutils import version
import sys

from packaging import version
import tensorflow.compat.v1 as tf

if version.LooseVersion(tf.__version__) < version.LooseVersion("2.0.0"):
if version.Version(tf.__version__) < version.Version("2.0.0"):
raise ImportError("Please upgrade your version "
"of tensorflow from: {0} to at least 2.0.0 to "
"use privacy/bolt_on".format(
version.LooseVersion(tf.__version__)))
version.Version(tf.__version__)))
if hasattr(sys, "skip_tf_privacy_import"): # Useful for standalone scripts.
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_privacy/privacy/dp_query/tree_range_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
'Offline' means all the leaf nodes are ready before the protocol starts.
"""

import distutils
import math
from typing import Any, NamedTuple, Optional

import dp_accounting
import packaging
import tensorflow as tf
from tensorflow_privacy.privacy.dp_query import distributed_discrete_gaussian_query
from tensorflow_privacy.privacy.dp_query import dp_query
Expand Down Expand Up @@ -270,8 +270,8 @@ def build_distributed_discrete_gaussian_query(cls,

def _get_add_noise(stddev, seed: Optional[int] = None):
"""Utility function to decide which `add_noise` to use according to tf version."""
if distutils.version.LooseVersion(
tf.__version__) < distutils.version.LooseVersion('2.0.0'):
if packaging.version.Version(
tf.__version__) < packaging.version.Version('2.0.0'):

# The seed should be only used for testing purpose.
if seed is not None:
Expand Down

0 comments on commit 0fcb483

Please sign in to comment.