Skip to content

Commit

Permalink
Merge pull request #151 from testingautomated-usi/tf-upgrade-basebranch
Browse files Browse the repository at this point in the history
⬆️ various dependency-version related fixes
  • Loading branch information
MiWeiss authored Feb 3, 2023
2 parents f3bc62b + 1029d9d commit d1b0326
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.8]

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
tf-version: [2.3.0, 2.4.0, 2.5.0]
python-version: [3.8]
tf-version: [2.7.0, 2.8.0, 2.9.0, 2.10.0, 2.11.0]

steps:
- uses: actions/checkout@v2
Expand All @@ -30,6 +30,11 @@ jobs:
pip install tensorflow==${{ matrix.tf-version }}
pip install -r test_requirements.txt
# Lazy fix for fact that some py/tf combinations don't like new versions of protobuf
- name: Downgrade protobuf
run: |
pip install protobuf==3.20.0
- name: Run Tests
run: |
bash scripts/run_coverage.sh
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tensorflow>=2.3.0
tensorflow>=2.7.0
# The following is only required for python 3.6
# dataclasses==0.6
# dataclasses==0.6
8 changes: 4 additions & 4 deletions tests_unit/internals_tests/test_tf_version_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def test_current_tf_version_is_older_than_is_false(self):
self.call_current_tf_is_older_than("2.0.0", False)

# Test release candidate
self.call_current_tf_is_older_than("1.2.3_rc2", False)
self.call_current_tf_is_older_than("1.2.3rc2", False)

# Call on same version
self.call_current_tf_is_older_than(tf.__version__, False)

def test_current_tf_version_is_older_than_is_true(self):
# Test regular case
self.call_current_tf_is_older_than("3.2.1", True)
self.call_current_tf_is_older_than("2.9.0", True)
self.call_current_tf_is_older_than("2.36.0", True)

# Test release candidate
self.call_current_tf_is_older_than("3.2.1_rc1", True)
self.call_current_tf_is_older_than("3.2.1rc1", True)

def test_tf_version_is_older_than_fallback(self):
invalid = "1.2.invalid"
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_current_tf_version_is_newer_is_true(self):
self.call_current_tf_is_newer_than("2.0.0", True)

# Test release candidate
self.call_current_tf_is_newer_than("1.2.3_rc2", True)
self.call_current_tf_is_newer_than("1.2.3rc2", True)

def test_current_tf_version_is_newer_is_false(self):
# Call on same version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import inspect
import unittest
from unittest import TestCase

import tensorflow as tf

from uncertainty_wizard.internal_utils.tf_version_resolver import (
current_tf_version_is_older_than,
)


class TestExperimentalAPIAreAvailable(TestCase):
"""
Expand All @@ -21,6 +26,9 @@ def test_list_physical_devices(self):
self.assertTrue("device_type" in parameters)
self.assertEqual(1, len(parameters))

@unittest.skipIf(
not current_tf_version_is_older_than("2.10.0"), "Known to fail for tf >= 2.10.0"
)
def test_virtual_device_configuration(self):
self.assertTrue("VirtualDeviceConfiguration" in dir(tf.config.experimental))
parameters = inspect.signature(
Expand Down
14 changes: 10 additions & 4 deletions uncertainty_wizard/internal_utils/tf_version_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ def _compare_expected_to_current_tf_version(expected_version) -> Union[None, int
"""
actual_version = tf.version.VERSION

# Note: We're currently only considering versions in the format 'x.y.z'
# (i.e., ignore RCs and multi digit versions - which is probably fine given tfs very fast major release cycles)
# replaces rc, dev and b with dots to make the version strings comparable
dotted_actual_version = actual_version.replace("rc", ".-1.")
dotted_expected_version = expected_version.replace("rc", ".-1.")

# Inspection disabling reason: We really want to catch all exceptions.
# noinspection PyBroadException
try:
expected_v_splits = [int(v) for v in expected_version[:5].split(".")]
actual_v_splits = [int(v) for v in actual_version[:5].split(".")]
expected_v_splits = [int(v) for v in dotted_expected_version.split(".")]
actual_v_splits = [int(v) for v in dotted_actual_version.split(".")]
except Exception:
warnings.warn(
f"One of the version strings '{expected_version}' (requested) "
Expand All @@ -35,6 +36,11 @@ def _compare_expected_to_current_tf_version(expected_version) -> Union[None, int
)
return None

if len(expected_v_splits) > len(actual_v_splits):
actual_v_splits += [1000] * (len(expected_v_splits) - len(actual_v_splits))
elif len(expected_v_splits) < len(actual_v_splits):
expected_v_splits += [1000] * (len(actual_v_splits) - len(expected_v_splits))

for act, expected in zip(actual_v_splits, expected_v_splits):
if expected > act:
return 1
Expand Down
14 changes: 13 additions & 1 deletion uncertainty_wizard/models/ensemble_utils/_lazy_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import tensorflow as tf

from uncertainty_wizard.internal_utils.tf_version_resolver import (
current_tf_version_is_older_than,
)
from uncertainty_wizard.models.ensemble_utils._save_config import SaveConfig

global number_of_tasks_in_this_process
Expand Down Expand Up @@ -35,7 +38,7 @@ def __init__(self, model_id: int, varargs: dict = None):
it will have to generate a context.
Later, to make it easier for custom child classes of EnsembleContextManager,
a (now still empty) varargs is also passed which may be populated with more information
in future versions of uncertainty_wizard.
in future s of uncertainty_wizard.
"""
self.ensemble_id = (model_id,)
self.varargs = varargs
Expand Down Expand Up @@ -225,6 +228,15 @@ class DeviceAllocatorContextManager(EnsembleContextManager, abc.ABC):
the abstract methods.
"""

def __init__(self):
super().__init__()
if not current_tf_version_is_older_than("2.10.0"):
raise RuntimeError(
"The DeviceAllocatorContextManager is not compatible with tensorflow 2.10.0 "
"or newer. Please fall back to a single GPU for now (see issue #75),"
"or downgrade to tensorflow 2.9.0."
)

# docstr-coverage: inherited
def __enter__(self) -> "DeviceAllocatorContextManager":
super().__enter__()
Expand Down

0 comments on commit d1b0326

Please sign in to comment.