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.empty({shape}, {dtype})` when you meant `jax.numpy.empty(({shape}, {dtype}))`, i.e. with a single tuple argument for the shape? What it means
jnp.empty's guard for the single-tuple typo: jnp.empty((2, 3, jnp.float32)) packs dtype into the shape tuple, causing dtype interpretation to fail; JAX raises with a hint suggesting jnp.empty((shape, dtype)) be written as separate arguments — note empty's unfilled memory means the wrong call silently produces wrong shapes otherwise.
Source
Thrown at jax/_src/numpy/array_creation.py:188
Array of the specified shape and dtype, with the given device/sharding if specified.
See also:
- :func:`jax.lax.empty`
- :func:`jax.numpy.empty_like`
- :func:`jax.numpy.zeros`
- :func:`jax.numpy.ones`
- :func:`jax.numpy.full`
Examples:
>>> jnp.empty(4) # doctest: +SKIP
Array([0., 0., 0., 0.], dtype=float32)
>>> jnp.empty((2, 3), dtype=bool) # doctest: +SKIP
Array([[False, False, False],
[False, False, False]], dtype=bool)
.. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html
"""
if (m := _check_forgot_shape_tuple("empty", shape, dtype)): raise TypeError(m)
dtype = dtypes.check_and_canonicalize_user_dtype(
float if dtype is None else dtype, "empty")
shape = canonicalize_shape(shape)
if device is not None and out_sharding is None:
# lax.empty does not accept SingleDeviceSharding, so we use api.device_put.
return api.device_put(lax.empty(shape, dtype), device)
else:
final_sharding = util.choose_device_or_out_sharding(
device, out_sharding, 'jnp.empty')
return lax.empty(shape, dtype, out_sharding=final_sharding)
def _check_forgot_shape_tuple(name, shape, dtype) -> str | None:
if isinstance(dtype, int) and isinstance(shape, int):
return (f"Cannot interpret '{dtype}' as a data type."
f"\n\nDid you accidentally write "
f"`jax.numpy.{name}({shape}, {dtype})` "
f"when you meant `jax.numpy.{name}(({shape}, {dtype}))`, i.e. "View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Split into two arguments: jnp.empty((2, 3), jnp.float32)
Example fix
# before a = jnp.empty((2, 3, jnp.float32)) # after a = jnp.empty((2, 3), jnp.float32)
Defensive patterns
Strategy: validation
Validate before calling
assert all(isinstance(d, int) for d in shape), 'shape tuple should contain only ints'
Type guard
null
Try / catch
null
Prevention
- Split shape and dtype into separate arguments
- Check parenthesis placement when editing one-line creation calls
When it happens
Trigger: jnp.empty((2, 3, dtype)) — a single tuple containing shape dims plus a dtype element.
Common situations: One-line shape/dtype edits with misplaced parentheses; templated array creation code shared across zeros/ones/empty.
Related errors
- Cannot interpret '{dtype}' as a data type.\n\nDid you accide
- Cannot interpret '{dtype}' as a data type.\n\nDid you accide
- Attempting to convert array of shape {operand.shape} from {o
- Not implemented: bitcast 1D
- Not implemented: the 2nd minor dim can not be perfectly pack
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/7547f5c6b5809baf.
Report an issue: GitHub.