tensorflow / tensorflow/probability

`None` gradients with bijectors

Open
#1,190 1 comment 0 reactions 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

Bijector cacheing causes None gradients:

with tf.GradientTape() as tape:
  d = tfd.MultivariateNormalTriL(scale_tril=tf.eye(2))
  x = d.sample()  
  tape.watch(x)
  g = tape.gradient(d.log_prob(x), x)

g is None  # True
tfp.math.value_and_gradient(d.log_prob, x)[1] is None  # True

The basic cause of this is that bijector.inverse(bijector.forward(x)) returns x from the cache, and the gradient of this will be None.

Currently, this can be worked around in the above example by breaking the cache. For example, replacing x = d.sample() with any of

x = d.sample() + 0
x = tf.identity(d.sample())
x = tf.stop_gradient(d.sample())

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 reproducer using MultivariateNormalTriL, GradientTape, and tfp.math.value_and_gradient, then inspect the bijector cache behavior described in the issue. Done means the shown gradient calls no longer return None without relying on the listed cache-breaking workarounds.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.