From 0bf759e8b4663e0c3d1bb9cac982b4c2c0bb0466 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 18 Sep 2018 22:07:53 +0200 Subject: [PATCH] Revert back to using tf.distribution instead of tfp For reasons not fully understood, using TensorFlow Probability causes Travis CI to use too much memory and a core dump occurs. So until this is understood all use of tfp should be reverted to a combination of tf.distributions and tf.contrib.distributions (for the Poisson). This is really annoying, but at least a temporary fix that doesn't break all functionality and gains. c.f. - https://github.com/pytest-dev/pytest/issues/3527 - https://github.com/travis-ci/travis-ci/issues/9153 --- .travis.yml | 14 +++++++------- pyhf/tensor/tensorflow_backend.py | 11 +++++++---- setup.py | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff44a1225a..b4802c01ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,13 @@ python: - '2.7' - '3.6' before_install: - - pip install --upgrade pip setuptools + - pip install --upgrade pip setuptools wheel install: - pip install --ignore-installed -U -q -e .[tensorflow,torch,mxnet,minuit,develop] # Ensure right version of NumPy installed + - pip freeze script: - pyflakes pyhf - # pytest takes up too much memory in Travis if run all at once, so split off - # test_notebooks.py into its own pytest run - - pytest --ignore tests/benchmarks/ --ignore tests/test_notebooks.py - - pytest tests/test_notebooks.py + - pytest --ignore tests/benchmarks/ after_success: coveralls # always test (on both 'push' and 'pr' builds in Travis) @@ -37,18 +35,20 @@ jobs: - stage: benchmark python: '3.6' before_install: - - pip install --upgrade pip setuptools + - pip install --upgrade pip setuptools wheel install: - pip install --ignore-installed -U -q -e .[tensorflow,torch,mxnet,develop] + - pip freeze script: pytest --benchmark-sort=mean tests/benchmarks/ - stage: docs python: '3.6' before_install: - sudo apt-get update - sudo apt-get -qq install pandoc - - pip install --upgrade pip setuptools + - pip install --upgrade pip setuptools wheel install: - pip install --ignore-installed -U -q -e .[tensorflow,torch,mxnet,develop] + - pip freeze script: - python -m doctest README.md - cd docs && make html && cd - diff --git a/pyhf/tensor/tensorflow_backend.py b/pyhf/tensor/tensorflow_backend.py index ab3c6e8818..8f0cddfbdb 100644 --- a/pyhf/tensor/tensorflow_backend.py +++ b/pyhf/tensor/tensorflow_backend.py @@ -1,6 +1,6 @@ import logging import tensorflow as tf -import tensorflow_probability as tfp +# import tensorflow_probability as tfp log = logging.getLogger(__name__) @@ -226,7 +226,8 @@ def poisson(self, n, lam): """ n = self.astensor(n) lam = self.astensor(lam) - return tf.exp(tfp.distributions.Poisson(lam).log_prob(n)) + # return tf.exp(tfp.distributions.Poisson(lam).log_prob(n)) + return tf.exp(tf.contrib.distributions.Poisson(lam).log_prob(n)) def normal(self, x, mu, sigma): """ @@ -256,7 +257,8 @@ def normal(self, x, mu, sigma): x = self.astensor(x) mu = self.astensor(mu) sigma = self.astensor(sigma) - normal = tfp.distributions.Normal(mu, sigma) + # normal = tfp.distributions.Normal(mu, sigma) + normal = tf.distributions.Normal(mu, sigma) return normal.prob(x) def normal_cdf(self, x, mu=0, sigma=1): @@ -286,5 +288,6 @@ def normal_cdf(self, x, mu=0, sigma=1): x = self.astensor(x) mu = self.astensor(mu) sigma = self.astensor(sigma) - normal = tfp.distributions.Normal(mu, sigma) + # normal = tfp.distributions.Normal(mu, sigma) + normal = tf.distributions.Normal(mu, sigma) return normal.cdf(x) diff --git a/setup.py b/setup.py index 6781daec13..1e9f7d65ae 100644 --- a/setup.py +++ b/setup.py @@ -34,8 +34,8 @@ ], 'tensorflow':[ 'tensorflow>=1.10.0', + # 'tensorflow-probability>=0.3.0', # Causing troulbe with Travis CI, but *should* be used 'numpy<=1.14.5,>=1.14.0', # Lower of 1.14.0 instead of 1.13.3 to ensure doctest pass - 'tensorflow-probability>=0.3.0', 'setuptools<=39.1.0', ], 'develop': [