keras-team/keras · error · ValueError
Illegal None dimension in
Error message
Illegal None dimension in {x} with shape {x.shape} What it means
Raised during JAX export's polymorphic-shape conversion (convert_shape inside _to_polymorphic_shape) when an input tensor has a None dimension but the context disallows None (allow_none=False, typically non-batch dims). Export needs concrete or explicitly named dims, and an unexpected None cannot be assigned a name.
Solutions
- Provide fully concrete input shapes when exporting; avoid None dims outside the batch axis.
- If dynamic dims are intended, configure the export for polymorphic shapes on those inputs instead of a concrete signature.
- Rebuild the model with fixed input shapes before export when consumers need static signatures.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/jax/export.py:159 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/7316c0b934cd3a33.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/jax/export.py:159
def _to_polymorphic_shape(self, struct, allow_none=True):
if allow_none:
# Generates unique names: a, b, ... z, aa, ab, ... az, ba, ... zz
# for unknown non-batch dims. Defined here to be scope per endpoint.
dim_names = itertools.chain(
string.ascii_lowercase,
itertools.starmap(
lambda a, b: a + b,
itertools.product(string.ascii_lowercase, repeat=2),
),
)
def convert_shape(x):
poly_shape = []
for index, dim in enumerate(list(x.shape)):
if dim is not None:
poly_shape.append(str(dim))
elif not allow_none:
raise ValueError(
f"Illegal None dimension in {x} with shape {x.shape}"
)
elif index == 0:
poly_shape.append("batch")
else:
poly_shape.append(next(dim_names))
return f"({', '.join(poly_shape)})"
return tree.map_structure(convert_shape, struct)
def _check_device_compatible(self):
from jax import default_backend as jax_device
if (
jax_device() == "gpu"
and len(tf.config.list_physical_devices("GPU")) == 0
):
warnings.warn(View on GitHub (pinned to 7a34a03db6)