jax-ml/jax · error · TypeError

Cannot interpret '{dtype}' as a data type.\n\nDid you accide

Error message

Cannot interpret '{dtype}' as a data type.\n\nDid you accidentally write `jax.numpy.zeros({shape}, {dtype})` when you meant `jax.numpy.zeros(({shape}, {dtype}))`, i.e. with a single tuple argument for the shape?

What it means

jnp.zeros detects the classic comma typo: jnp.zeros((2, 3), jnp.float32) written as jnp.zeros(2, 3, jnp.float32) — no wait, the detected form is zeros((2, 3, float32)) style, i.e. packing dtype into the shape tuple so dtype becomes uninterpretable. When the shape tuple's extra element lands in the dtype slot, JAX raises with a hint about wrapping shape and dtype in one tuple.

Source

Thrown at jax/_src/numpy/array_creation.py:89

  See also:
    - :func:`jax.numpy.zeros_like`
    - :func:`jax.numpy.empty`
    - :func:`jax.numpy.ones`
    - :func:`jax.numpy.full`

  Examples:
    >>> jnp.zeros(4)
    Array([0., 0., 0., 0.], dtype=float32)
    >>> jnp.zeros((2, 3), dtype=bool)
    Array([[False, False, False],
           [False, False, False]], dtype=bool)

  .. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html
  """
  if isinstance(shape, types.GeneratorType):
    raise TypeError("expected sequence object with len >= 0 or a single integer")
  if (m := _check_forgot_shape_tuple("zeros", shape, dtype)): raise TypeError(m)
  dtype = dtypes.check_and_canonicalize_user_dtype(
      float if dtype is None else dtype, "zeros")
  shape = canonicalize_shape(shape)
  sharding = util.choose_device_or_out_sharding(
      device, out_sharding, 'jnp.zeros')
  return lax.full(shape, 0, dtype, sharding=sharding)


@export
def ones(shape: Any, dtype: DTypeLike | None = None, *,
         device: xc.Device | Sharding | None = None,
         out_sharding: NamedSharding | P | None = None) -> Array:
  """Create an array full of ones.

  JAX implementation of :func:`numpy.ones`.

  Args:
    shape: int or sequence of ints specifying the shape of the created array.

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Split arguments: jnp.zeros((2, 3), jnp.float32)
  2. If you intended one tuple, keep it shape-only and pass dtype separately

Example fix

# before
a = jnp.zeros((2, 3, jnp.float32))
# after
a = jnp.zeros((2, 3), jnp.float32)
Defensive patterns

Strategy: validation

Validate before calling

def check_shape_dtype_split(fn_name, shape, dtype):
    # catches (2, 3, dtype) packed into shape
    return all(isinstance(s, (int, np.integer)) for s in shape)

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: jnp.zeros((2, 3, jnp.float32)) — a single tuple argument containing both shape and dtype, so 'dtype' resolves to something like the shape tuple's last element and fails interpretation.

Common situations: Migrating from other frameworks (e.g. torch.empty(size, dtype) style) or a misplaced parenthesis when editing shape/dtype on one line.

Related errors


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