jax-ml/jax · error · ValueError

dtype must be specified.

Error message

dtype must be specified.

What it means

check_and_canonicalize_user_dtype validates user-provided dtype= arguments for many lax/jnp operations; passing None (dtype not specified) where a concrete dtype is required raises this ValueError.

Source

Thrown at jax/_src/dtypes.py:1112

    dtype or (dtype, weak_type) depending on the value of the ``return_weak_type`` argument.
  """
  if len(args) == 0:
    raise ValueError("at least one array or dtype is required")
  dtype: DType | ExtendedDType
  dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))
  if weak_type:
    dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()
  return (dtype, weak_type) if return_weak_type_flag else dtype

def check_and_canonicalize_user_dtype(
    dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False
) -> DType:
  """Checks validity of a user-provided dtype, and returns its canonical form.

  For Python scalar types this function returns the corresponding default dtype.
  """
  if dtype is None:
    raise ValueError("dtype must be specified.")
  if isinstance(dtype, Array):
    raise ValueError("Passing an array as a dtype argument is no longer "
                     "supported; instead of dtype=arr use dtype=arr.dtype.")
  if issubdtype(dtype, extended):
    return dtype
  # Avoid using `dtype in [...]` because of numpy dtype equality overloading.
  if isinstance(dtype, type) and (f := _DEFAULT_TYPEMAP.get(dtype)) is not None:
    return f()
  np_dtype = np.dtype(dtype)
  if np_dtype not in _jax_dtype_set:
    if allow_non_jax_dtypes:
      return np_dtype
    msg = (
        f'JAX only supports number, bool, and string dtypes, got dtype {dtype}'
    )
    msg += f" in {fun_name}" if fun_name else ""
    raise TypeError(msg)
  return _maybe_canonicalize_explicit_dtype(np_dtype, fun_name or "")

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Pass an explicit dtype: dtype=jnp.float32 (or match your data)
  2. Set a default in your config layer: dtype = cfg.dtype or jnp.float32
  3. Check the function signature/docstring — if dtype is required, make it a required parameter in your wrapper

Example fix

# before
lax.conv_general_dilated(..., dtype=None)

# after
lax.conv_general_dilated(..., dtype=jnp.float32)
Defensive patterns

Strategy: validation

Validate before calling

dtype = dtype if dtype is not None else jnp.float32

Prevention

When it happens

Trigger: Calling ops like lax.conv_general_dilated(..., dtype=None), searchsorted, or scaled-matmul wrappers with dtype left unset/None because it was optional in an older API or your config defaulted to None.

Common situations: Upgrading JAX after a dtype argument became required; config-driven pipelines where the dtype field is optional and defaults to None; wrapper APIs forwarding None.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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