From 960fde310fc8c6f3be6d26deff532074260b519a Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 00:19:47 +0200 Subject: [PATCH 1/7] added the usual modification to make edward work with current tensorflow, and modified travis to test it --- .travis.yml | 7 ++++++- edward/util/random_variables.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1e5c45eac..ef16f5820 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ matrix: include: - python: 2.7 - python: 3.4 + - python: 3.7 + env: + - TF=1.5.0 + - TF=1.7.0 + - TF=1.9.0 notifications: email: false before_install: @@ -37,7 +42,7 @@ install: - pip install keras - pip install matplotlib seaborn scipy - pip install networkx==1.9.1 observations sklearn - - pip install tensorflow==1.5.0 + - pip install tensorflow==$TF - pip install pystan - pip install nbformat nbconvert jupyter_client jupyter - python setup.py install diff --git a/edward/util/random_variables.py b/edward/util/random_variables.py index 3a581505a..a706645f1 100644 --- a/edward/util/random_variables.py +++ b/edward/util/random_variables.py @@ -12,7 +12,7 @@ from edward.models import PointMass from edward.util.graphs import random_variables from tensorflow.core.framework import attr_value_pb2 -from tensorflow.python.framework.ops import set_shapes_for_outputs +from tensorflow.python.framework.ops import set_shape_and_handle_data_for_outputs as set_shapes_for_outputs from tensorflow.python.util import compat tfb = tf.contrib.distributions.bijectors From fe2ebb321773a0b9f989ab3072eec2d51fb2fe63 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 00:31:47 +0200 Subject: [PATCH 2/7] made import name version dependent and fixed travis.yml --- .travis.yml | 17 ++++++++--------- edward/util/random_variables.py | 6 +++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef16f5820..63d7b54f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,14 @@ sudo: required dist: trusty language: python -matrix: - include: - - python: 2.7 - - python: 3.4 - - python: 3.7 - env: - - TF=1.5.0 - - TF=1.7.0 - - TF=1.9.0 +python: + - 2.7 + - 3.4 + - 3.6 +env: + - TF=1.5.0 + - TF=1.7.0 + - TF=1.9.0 notifications: email: false before_install: diff --git a/edward/util/random_variables.py b/edward/util/random_variables.py index a706645f1..4c766b005 100644 --- a/edward/util/random_variables.py +++ b/edward/util/random_variables.py @@ -12,7 +12,11 @@ from edward.models import PointMass from edward.util.graphs import random_variables from tensorflow.core.framework import attr_value_pb2 -from tensorflow.python.framework.ops import set_shape_and_handle_data_for_outputs as set_shapes_for_outputs +from tensorflow import __version__ as tf_version +if tuple(int(v) for v in tf_version.split('.')) >= (1,7,0): + from tensorflow.python.framework.ops import set_shape_and_handle_data_for_outputs as set_shapes_for_outputs +else: + from tensorflow.python.framework.ops import set_shapes_for_outputs from tensorflow.python.util import compat tfb = tf.contrib.distributions.bijectors From 356dc3172403463d7532ac5853ec6fa1b23bc026 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 08:30:29 +0200 Subject: [PATCH 3/7] make code pep8 compliant, and test TF versions more thoroughly --- .travis.yml | 2 ++ edward/util/random_variables.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 63d7b54f6..e71f99d6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,10 @@ python: - 3.4 - 3.6 env: + - TF=1.2.0rc0 - TF=1.5.0 - TF=1.7.0 + - TF=1.8.0 - TF=1.9.0 notifications: email: false diff --git a/edward/util/random_variables.py b/edward/util/random_variables.py index 4c766b005..1727bd82f 100644 --- a/edward/util/random_variables.py +++ b/edward/util/random_variables.py @@ -13,11 +13,12 @@ from edward.util.graphs import random_variables from tensorflow.core.framework import attr_value_pb2 from tensorflow import __version__ as tf_version -if tuple(int(v) for v in tf_version.split('.')) >= (1,7,0): - from tensorflow.python.framework.ops import set_shape_and_handle_data_for_outputs as set_shapes_for_outputs +from tensorflow.python.util import compat +if tuple(int(v) for v in tf_version.split('.')) >= (1, 7, 0): + from tensorflow.python.framework.ops import \ + set_shape_and_handle_data_for_outputs as set_shapes_for_outputs else: from tensorflow.python.framework.ops import set_shapes_for_outputs -from tensorflow.python.util import compat tfb = tf.contrib.distributions.bijectors From b7f22ff041d887f3f9c36a760e62b78b0495ad86 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 12:37:17 +0200 Subject: [PATCH 4/7] fixed a test that failed due to round-off; the test itself was also flawed and passed just accidentially. fixed the test, as well as the test case. --- edward/util/random_variables.py | 11 +++++------ tests/criticisms/metrics_test.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/edward/util/random_variables.py b/edward/util/random_variables.py index 1727bd82f..80b04e102 100644 --- a/edward/util/random_variables.py +++ b/edward/util/random_variables.py @@ -12,13 +12,12 @@ from edward.models import PointMass from edward.util.graphs import random_variables from tensorflow.core.framework import attr_value_pb2 -from tensorflow import __version__ as tf_version from tensorflow.python.util import compat -if tuple(int(v) for v in tf_version.split('.')) >= (1, 7, 0): - from tensorflow.python.framework.ops import \ - set_shape_and_handle_data_for_outputs as set_shapes_for_outputs -else: - from tensorflow.python.framework.ops import set_shapes_for_outputs +try: + from tensorflow.python.framework.ops import set_shapes_for_outputs +except ImportError: + from tensorflow.python.framework.ops import \ + set_shape_and_handle_data_for_outputs as set_shapes_for_outputs tfb = tf.contrib.distributions.bijectors diff --git a/tests/criticisms/metrics_test.py b/tests/criticisms/metrics_test.py index 452e357e8..621d5b00a 100644 --- a/tests/criticisms/metrics_test.py +++ b/tests/criticisms/metrics_test.py @@ -46,23 +46,27 @@ class test_metrics_class(tf.test.TestCase): def _check_averaging(self, metric, y_true, y_pred): n_classes = tf.squeeze(tf.shape(y_true)[-1]).eval() - class_scores = [metric(y_true[i], y_pred[i]) for i in range(n_classes)] + class_scores = [metric(y_true[:, i], y_pred[:, i]) + for i in range(n_classes)] # No averaging no_average = metric(y_true, y_pred, average=None) expected_no_average = tf.stack(class_scores) - self.assertAllEqual(no_average.eval(), expected_no_average.eval()) + self.assertAllCloseAccordingToType( + no_average.eval(), expected_no_average.eval()) # Macro-averaging macro_average = metric(y_true, y_pred, average='macro') expected_macro_average = tf.reduce_mean(tf.stack(class_scores)) - self.assertAllEqual(macro_average.eval(), expected_macro_average.eval()) + self.assertAllCloseAccordingToType( + macro_average.eval(), expected_macro_average.eval()) # Micro-averaging micro_average = metric(y_true, y_pred, average='micro') expected_micro_average = metric(tf.reshape(y_true, [1, -1]), tf.reshape(y_pred, [1, -1])) - self.assertAllEqual(micro_average.eval(), expected_micro_average.eval()) + self.assertAllCloseAccordingToType( + micro_average.eval(), expected_micro_average.eval()) def test_classification_metrics(self): with self.test_session(): @@ -106,7 +110,7 @@ def test_specialized_input_output_metrics(self): def test_metrics_with_binary_averaging(self): with self.test_session(): y_true = tf.constant([[1.0, 2.0, 3.0], [2.0, 3.0, 4.0], [3.0, 4.0, 5.0]]) - y_pred = tf.constant([[2.0, 4.0, 6.0], [4.0, 6.0, 8.0], [6.0, 8.0, 10.0]]) + y_pred = tf.constant([[3.0, 4.0, 3.0], [6.0, 6.0, 4.0], [9.0, 8.0, 5.0]]) for metric in all_metrics_with_binary_averaging: self._check_averaging(metric, y_true, y_pred) From 96a0281b06bdf2ec52b9769dcc1aa96361bea860 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 13:54:30 +0200 Subject: [PATCH 5/7] re-run travis with a detailed set of tensor-flow versions to identify proper limits --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e71f99d6c..07c2354ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,12 @@ python: - 3.4 - 3.6 env: - - TF=1.2.0rc0 + - TF=1.2.0 + - TF=1.3.0rc0 + - TF=1.4.0rc0 - TF=1.5.0 + - TF=1.6.0 - TF=1.7.0 - - TF=1.8.0 - - TF=1.9.0 notifications: email: false before_install: From c2f2346ec7bc14d366a24a2a91bff6c3a1d63a55 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 14:30:43 +0200 Subject: [PATCH 6/7] updated requirements to specify tensorflow 1.3.0rc0 to 1.7.0, and let travis test those two --- .travis.yml | 4 ---- setup.py | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07c2354ea..34f6022de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,7 @@ python: - 3.4 - 3.6 env: - - TF=1.2.0 - TF=1.3.0rc0 - - TF=1.4.0rc0 - - TF=1.5.0 - - TF=1.6.0 - TF=1.7.0 notifications: email: false diff --git a/setup.py b/setup.py index 45bd5742f..331fcf613 100644 --- a/setup.py +++ b/setup.py @@ -15,8 +15,8 @@ install_requires=['numpy>=1.7', 'six>=1.10.0'], extras_require={ - 'tensorflow': ['tensorflow>=1.2.0rc0'], - 'tensorflow with gpu': ['tensorflow-gpu>=1.2.0rc0'], + 'tensorflow': ['tensorflow >=1.3.0rc0, <=1.7.0'], + 'tensorflow with gpu': ['tensorflow-gpu >=1.3.0rc0, <=1.7.0'], 'neural networks': ['keras>=2.0.0', 'prettytensor>=0.7.4'], 'datasets': ['observations>=0.1.2'], 'notebooks': ['jupyter>=1.0.0'], From 8c824803a8e8bbfbd35c55069b76a81e9b86ef95 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Thu, 26 Jul 2018 16:25:06 +0200 Subject: [PATCH 7/7] added TF 1.5.0 again in travis, as the build currently seems unstable --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 34f6022de..4f47f9ea7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: - 3.6 env: - TF=1.3.0rc0 + - TF=1.5.0 - TF=1.7.0 notifications: email: false