jax-ml/jax · error · ValueError

dtype argument to `logistic` must be a float dtype, got {dty

Error message

dtype argument to `logistic` must be a float dtype, got {dtype}

What it means

jax.random.logistic requires a floating-point dtype because the logistic sampler computes log(u/(1-u)) in float arithmetic. Integer or complex dtypes raise ValueError before the jit-compiled sampler runs.

Source

Thrown at jax/_src/random/core.py:2517

    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).
    out_sharding: Optional. Specifies how the output array should be sharded
      across devices in multi-device computation. Can be a
      :class:`~jax.sharding.NamedSharding`, a :class:`~jax.sharding.PartitionSpec`
      (``P``), or ``None`` (default). When specified, the output will be sharded
      according to the given sharding specification. Primarily used in explicit
      sharding mode.
      See the `explicit sharding tutorial <https://docs.jax.dev/en/latest/parallel.html>`_
      for more details.

  Returns:
    A random array with the specified shape and dtype.
  """
  key, _ = _check_prng_key("logistic", key)
  dtype = dtypes.check_and_canonicalize_user_dtype(
      float if dtype is None else dtype)
  if not dtypes.issubdtype(dtype, np.floating):
    raise ValueError(f"dtype argument to `logistic` must be a float "
                     f"dtype, got {dtype}")
  shape = core.canonicalize_shape(shape)
  out_sharding = canonicalize_sharding_for_samplers(out_sharding, "logistic", shape)
  return maybe_auto_axes(_logistic, out_sharding,
                         shape=shape, dtype=dtype)(key)

@jit(static_argnums=(1, 2))
def _logistic(key, shape, dtype):
  _check_shape("logistic", shape)
  x = uniform(key, shape, dtype, minval=dtypes.finfo(dtype).tiny, maxval=1.)
  return lax.sub(lax.log(x), lax.log1p(lax.neg(x)))


def pareto(key: ArrayLike,
           b: RealArray,
           shape: Shape | None = None,
           dtype: DTypeLikeFloat | None = None,
           *,

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use jnp.float32/jnp.float64 or omit dtype.
  2. Validate dtypes against np.floating in any dtype-configurable pipeline.

Example fix

// before
x = jax.random.logistic(key, (100,), dtype=jnp.int32)

// after
x = jax.random.logistic(key, (100,), dtype=jnp.float32)
Defensive patterns

Strategy: type-guard

Validate before calling

from jax._src import dtypes
assert dtypes.issubdtype(dtypes.check_and_canonicalize_user_dtype(dtype or float), np.floating)

Type guard

def is_float_dtype(dtype) -> bool:
    from jax._src import dtypes
    import numpy as np
    return dtypes.issubdtype(dtypes.check_and_canonicalize_user_dtype(dtype or float), np.floating)

Prevention

When it happens

Trigger: jax.random.logistic(key, shape, dtype=jnp.int32) or any non-floating dtype argument.

Common situations: Configured dtype reuse across samplers; assuming default dtype is int for distribution samplers; typos like passing jnp.int64 during experimentation.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/ea5161e96375da80. Report an issue: GitHub.