#41107·jax

jax.numpy.random.multinomial shape behavior is inconsistent with docs, similar functions, and numpy

Author: stroxlerCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbug

Description

The documentation of jax.numpy.random.multinomial suggests that the shape input should exclude the output dimension, which matches numpy behavior.

For example, numpy gives

python
p = np.array([0.2, 0.3, 0.5])
np.random.multinomial(5, p, size=(2,)).shape
  # (2, 3)
np.random.default_rng().multinomial(5, p, size=(2, 4)).shape
  # (2, 4, 3)

and this is what the documentation of jax.random.multinomial claims it should do, but it actually requires shape to match the output shape:

python
p = jnp.array([0.2, 0.3, 0.5])
key = random.key(0)
random.multinomial(key, 5, p, shape=(2,))   # Fails with ValueError due to broadcast failure
random.multinomial(key, 5, p, shape=(2, 3))   # Succeeds with output shape (2, 3)

In addition to being at odds with the documentation and with numpy, it also disagrees with comparable higher-dimensional random variable functions like multivariate_gaussian and dirichlet, whose shape inputs exclude the output dimension of the random variable itself.

I'm fairly sure that this inconsistency is a bug in multinomial behavior rather than a mistake in the documentation and I would be happy to put up a patch to fix it, but because the current implementation does work I wanted to file an issue first, because fixing the problem is a breaking change that could break existing user code.

System info (python version, jaxlib version, accelerator, etc.)

I'm using Python 3.13 on a CPU, I don't think this bug is related to anything accelerator or Python version specific.

I originally found this using JAX 0.11.2, but also verified the behavior against a git clone on master