tensorflow / tensorflow/probability

Error when inheriting from JointDistributionSequential in tfp version 0.18.0

Open
#1,617 3 comments 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

In the most recent update (0.18.0) instantiating a class which inherits from tfp.distributions.JointDistributionSequential now raises an error.

Here is a MWE (reproduced in colab):

from jax import numpy as jnp
from tensorflow_probability.substrates import jax as tfp
tfd = tfp.distributions

class HierarchicalNormal(tfd.JointDistributionSequential):
        def __init__(self, loc, scale):
            self.loc = loc
            self.prior_scale = scale

            super().__init__(model=[
                tfd.Normal(loc,scale),
                lambda mu: tfd.Normal(mu, scale)
                ])


loc = jnp.zeros(1)
scale = jnp.ones(1)
dist = HierarchicalNormal(loc,scale)

raises the following error:

    388     if not isinstance(model, collections.abc.Sequence):
    389       raise TypeError('`model` must be `list`-like (saw: {}).'.format(
--> 390           type(model).__name__))
    391     self._dist_fn = model
    392     self._dist_fn_wrapped, self._dist_fn_args = zip(*[

TypeError: `model` must be `list`-like (saw: DeviceArray).

Note that the following works:

loc = jnp.zeros(1)
scale = jnp.ones(1)
model=[tfd.Normal(loc,scale),
       lambda mu: tfd.Normal(mu, scale)] 

dist = tfd.JointDistributionSequential(model)

This seems to be new in 0.18.0 with no errors in versions 0.17.0 or 0.16.0.

(tagging @murphyk @slinderman to be kept up to date).

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 JointDistributionSequential constructor used in the reported subclass and compare its behavior in TensorFlow Probability 0.18.0 with 0.17.0 and 0.16.0. Reproduce the supplied JAX MWE and verify that inheriting from the class accepts the same model list as direct construction without raising the DeviceArray error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.