Skip to content

Commit

Permalink
Revert back to using tf.distribution instead of tfp
Browse files Browse the repository at this point in the history
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.
- pytest-dev/pytest#3527
- travis-ci/travis-ci#9153
  • Loading branch information
matthewfeickert committed Sep 18, 2018
1 parent 02b4d30 commit 0bf759e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 -
Expand Down
11 changes: 7 additions & 4 deletions pyhf/tensor/tensorflow_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import tensorflow as tf
import tensorflow_probability as tfp
# import tensorflow_probability as tfp

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down

0 comments on commit 0bf759e

Please sign in to comment.