tensorflow / tensorflow/probability

Error with jit and batched sampling

Open
#1,150 0 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

The following code samples three times from the same model. Only the final attempt, which combines jax.jit and sample_shape, raises a ValueError. This is on today's tfp-nightly (0.12.0-dev20201030) and jax from earlier today (21bb501) on CPU

import jax
from tensorflow_probability.substrates import jax as tfp

tfd = tfp.distributions
Root = tfd.JointDistributionCoroutineAutoBatched.Root

@tfd.JointDistributionCoroutineAutoBatched
def model():
    x = yield Root(tfd.Sample(
        tfd.Uniform(0, 1),
        sample_shape=(),
    ))
    return x

def sample():
    return model.sample(
        sample_shape=(1,), 
        seed=jax.random.PRNGKey(0)
    )
# Works as expected without jit
sample()

@jax.jit
def sample():
    return model.sample(
        seed=jax.random.PRNGKey(0)
    )
# Works as expected with default sample shape
sample()

@jax.jit
def sample():
    return model.sample(
        sample_shape=(1,), 
        seed=jax.random.PRNGKey(0)
    )
# Raises value error now that jit and sample_shape are used
sample()
> ValueError: vmap must have at least one non-None value in in_axes

stack trace

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 by running the supplied reproduction with the reported tfp-nightly and JAX versions, then follow the linked stack trace from model.sample into the JAX sampling path. Done means the jitted call with sample_shape=(1,) no longer raises the reported ValueError and the behavior is covered by regression testing.

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.