jax-ml/jax · error · ValueError

Explicitly requested dtype {}{} is not available. To enable

Error message

Explicitly requested dtype {}{} is not available. To enable more dtypes, set the jax_enable_x64 or allow_explicit_x64_dtypes configuration options.See https://github.com/jax-ml/jax#current-gotchas for more.

What it means

A 64-bit dtype (e.g. np.float64/int64/uint64, or a non-canonical variant) was explicitly requested, but JAX runs with x64 disabled (the default), so the dtype is unavailable. With jax_numpy_dtype_promotion / allow_explicit_x64_dtypes in ERROR mode this raises instead of silently truncating to 32 bits.

Source

Thrown at jax/_src/dtypes.py:972

    raise TypeError(f"Dtype {dtype} is not a valid JAX array "
                    "type. Only arrays of numeric types are supported by JAX.")

def _maybe_canonicalize_explicit_dtype(dtype: DType, fun_name: str) -> DType:
  "Canonicalizes explicitly requested dtypes, per explicit_x64_dtypes."
  allow = config.explicit_x64_dtypes.value
  if allow == config.ExplicitX64Mode.ALLOW or config.enable_x64.value:
    return dtype
  canonical_dtype = canonicalize_dtype(dtype)
  if canonical_dtype == dtype:
    return dtype
  fun_name = f" requested in {fun_name}" if fun_name else ""
  if allow == config.ExplicitX64Mode.ERROR:
    msg = ("Explicitly requested dtype {}{} is not available. To enable more "
           "dtypes, set the jax_enable_x64 or allow_explicit_x64_dtypes "
           "configuration options."
          "See https://github.com/jax-ml/jax#current-gotchas for more.")
    msg = msg.format(dtype, fun_name, canonical_dtype.name)
    raise ValueError(msg)
  else:  # WARN
    msg = ("Explicitly requested dtype {}{} is not available, "
          "and will be truncated to dtype {}. To enable more dtypes, set the "
          "jax_enable_x64 configuration option or the JAX_ENABLE_X64 shell "
          "environment variable. "
          "See https://github.com/jax-ml/jax#current-gotchas for more.")
    msg = msg.format(dtype, fun_name, canonical_dtype.name)
    warnings.warn(msg, stacklevel=4)
    return canonical_dtype


_types_whose_dtype_should_not_be_canonicalized: tuple[type, ...] = (
    Array,
)

def register_type_whose_dtype_should_not_be_canonicalized(typ: type):
  global _types_whose_dtype_should_not_be_canonicalized
  _types_whose_dtype_should_not_be_canonicalized += (typ,)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Enable 64-bit: jax.config.update('jax_enable_x64', True) at startup (or set JAX_ENABLE_X64=true before importing JAX)
  2. Or allow explicit 64-bit dtypes only: jax.config.update('allow_explicit_x64_dtypes', 'allow')
  3. Or change the requested dtype to a 32-bit equivalent (np.float32/int32) if 64-bit precision is not required

Example fix

# before
import jax.numpy as jnp
x = jnp.zeros(10, dtype=jnp.float64)

# after
import jax
jax.config.update('jax_enable_x64', True)
import jax.numpy as jnp
x = jnp.zeros(10, dtype=jnp.float64)
Defensive patterns

Strategy: validation

Validate before calling

import jax
if not jax.config.jax_enable_x64 and np.dtype(requested).itemsize == 8 and np.dtype(requested).kind in 'iuf':
    requested = np.dtype(f'{np.dtype(requested).kind}4')  # or enable x64

Type guard

def is_x64_dtype(dt) -> bool:
    import numpy as np
    return np.dtype(dt).itemsize == 8

Try / catch

try:
    arr = jnp.zeros(n, dtype=dt)
except ValueError:
    jax.config.update('jax_enable_x64', True)
    arr = jnp.zeros(n, dtype=dt)

Prevention

When it happens

Trigger: Calling jnp.zeros(n, dtype=np.float64) or passing dtype=jnp.int64 when jax_enable_x64=False and explicit-x64 policy is set to 'error' (e.g. via JAX_NUMPY_DTYPE_PROMOTION or allow_explicit_x64_dtypes='error'). Common entry points: jax.numpy.dtype, check_and_canonicalize_user_dtype (dtype= args to lax ops, searchsorted, conv_general_dilated).

Common situations: Porting NumPy code that uses float64/int64; running on TPU where 64-bit is undesired; library code that must guarantee no silent truncation setting the ERROR policy; env var JAX_ENABLE_X64 unset on a fresh install.

Related errors


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