tensorflow / tensorflow/probability

Persistent GradientTape hangs with Distribution.sample()

Open
#1,136 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Drawing samples from an instance of tfp.distributions.Distribution in a persistent=True GradientTape context seems to hang:

import tensorflow as tf
import tensorflow_probability as tfp

alpha = tf.Variable([2., 0.5])
beta = tf.Variable([2., 3.])

with tf.GradientTape() as tape:
    sample = tf.random.gamma(shape=(1,), alpha=alpha, beta=beta)

print(sample)

with tf.GradientTape() as tape:
    sample = tfp.distributions.Gamma(concentration=alpha, rate=beta).sample()

print(sample)

with tf.GradientTape(persistent=True) as tape:
    sample = tf.random.gamma(shape=(1,), alpha=alpha, beta=beta)

print(sample)

with tf.GradientTape(persistent=True) as tape:
    sample = tfp.distributions.Gamma(concentration=alpha, rate=beta).sample()

print(sample)  # FIXME: never reachers here!!!

This seems to happen for TF in [2.3.0, 2.3.1, nightly], TFP in [0.11.0, 0.11.1, nightly], Python 3.7, Colab and Mac OS (have not tested release and platform combinations).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python reproduction in the issue, comparing direct tf.random.gamma sampling with tfp.distributions.Gamma.sample() under persistent and non-persistent GradientTape contexts. Confirm whether the final TFP sample still hangs across the listed TensorFlow and TensorFlow Probability versions; done means identifying and resolving the persistent-tape hang without regressing the working cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.