Skip to content

Commit d1b0326

Browse files
authored
Merge pull request #151 from testingautomated-usi/tf-upgrade-basebranch
⬆️ various dependency-version related fixes
2 parents f3bc62b + 1029d9d commit d1b0326

File tree

7 files changed

+45
-14
lines changed

7 files changed

+45
-14
lines changed

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [3.6, 3.7, 3.8]
16+
python-version: [3.8]
1717

1818
steps:
1919
- uses: actions/checkout@v2

.github/workflows/unit_tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: [3.6, 3.7, 3.8]
13-
tf-version: [2.3.0, 2.4.0, 2.5.0]
12+
python-version: [3.8]
13+
tf-version: [2.7.0, 2.8.0, 2.9.0, 2.10.0, 2.11.0]
1414

1515
steps:
1616
- uses: actions/checkout@v2
@@ -30,6 +30,11 @@ jobs:
3030
pip install tensorflow==${{ matrix.tf-version }}
3131
pip install -r test_requirements.txt
3232
33+
# Lazy fix for fact that some py/tf combinations don't like new versions of protobuf
34+
- name: Downgrade protobuf
35+
run: |
36+
pip install protobuf==3.20.0
37+
3338
- name: Run Tests
3439
run: |
3540
bash scripts/run_coverage.sh

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
tensorflow>=2.3.0
1+
tensorflow>=2.7.0
22
# The following is only required for python 3.6
3-
# dataclasses==0.6
3+
# dataclasses==0.6

tests_unit/internals_tests/test_tf_version_resolver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ def test_current_tf_version_is_older_than_is_false(self):
1919
self.call_current_tf_is_older_than("2.0.0", False)
2020

2121
# Test release candidate
22-
self.call_current_tf_is_older_than("1.2.3_rc2", False)
22+
self.call_current_tf_is_older_than("1.2.3rc2", False)
2323

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

2727
def test_current_tf_version_is_older_than_is_true(self):
2828
# Test regular case
2929
self.call_current_tf_is_older_than("3.2.1", True)
30-
self.call_current_tf_is_older_than("2.9.0", True)
30+
self.call_current_tf_is_older_than("2.36.0", True)
3131

3232
# Test release candidate
33-
self.call_current_tf_is_older_than("3.2.1_rc1", True)
33+
self.call_current_tf_is_older_than("3.2.1rc1", True)
3434

3535
def test_tf_version_is_older_than_fallback(self):
3636
invalid = "1.2.invalid"
@@ -66,7 +66,7 @@ def test_current_tf_version_is_newer_is_true(self):
6666
self.call_current_tf_is_newer_than("2.0.0", True)
6767

6868
# Test release candidate
69-
self.call_current_tf_is_newer_than("1.2.3_rc2", True)
69+
self.call_current_tf_is_newer_than("1.2.3rc2", True)
7070

7171
def test_current_tf_version_is_newer_is_false(self):
7272
# Call on same version

tests_unit/keras_assumptions_tests/test_experimental_calls_exist.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import inspect
2+
import unittest
23
from unittest import TestCase
34

45
import tensorflow as tf
56

7+
from uncertainty_wizard.internal_utils.tf_version_resolver import (
8+
current_tf_version_is_older_than,
9+
)
10+
611

712
class TestExperimentalAPIAreAvailable(TestCase):
813
"""
@@ -21,6 +26,9 @@ def test_list_physical_devices(self):
2126
self.assertTrue("device_type" in parameters)
2227
self.assertEqual(1, len(parameters))
2328

29+
@unittest.skipIf(
30+
not current_tf_version_is_older_than("2.10.0"), "Known to fail for tf >= 2.10.0"
31+
)
2432
def test_virtual_device_configuration(self):
2533
self.assertTrue("VirtualDeviceConfiguration" in dir(tf.config.experimental))
2634
parameters = inspect.signature(

uncertainty_wizard/internal_utils/tf_version_resolver.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ def _compare_expected_to_current_tf_version(expected_version) -> Union[None, int
1515
"""
1616
actual_version = tf.version.VERSION
1717

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

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

39+
if len(expected_v_splits) > len(actual_v_splits):
40+
actual_v_splits += [1000] * (len(expected_v_splits) - len(actual_v_splits))
41+
elif len(expected_v_splits) < len(actual_v_splits):
42+
expected_v_splits += [1000] * (len(actual_v_splits) - len(expected_v_splits))
43+
3844
for act, expected in zip(actual_v_splits, expected_v_splits):
3945
if expected > act:
4046
return 1

uncertainty_wizard/models/ensemble_utils/_lazy_contexts.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import tensorflow as tf
99

10+
from uncertainty_wizard.internal_utils.tf_version_resolver import (
11+
current_tf_version_is_older_than,
12+
)
1013
from uncertainty_wizard.models.ensemble_utils._save_config import SaveConfig
1114

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

231+
def __init__(self):
232+
super().__init__()
233+
if not current_tf_version_is_older_than("2.10.0"):
234+
raise RuntimeError(
235+
"The DeviceAllocatorContextManager is not compatible with tensorflow 2.10.0 "
236+
"or newer. Please fall back to a single GPU for now (see issue #75),"
237+
"or downgrade to tensorflow 2.9.0."
238+
)
239+
228240
# docstr-coverage: inherited
229241
def __enter__(self) -> "DeviceAllocatorContextManager":
230242
super().__enter__()

0 commit comments

Comments
 (0)