tensorflow / tensorflow/probability
Error with jit and batched sampling
Open
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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