keras-team/keras · error · ValueError
Cannot convert '{shape}' to a shape. Found invalid dimension
Error message
Cannot convert '{shape}' to a shape. Found invalid dimension '{d}' of type '{type(d)}'. What it means
Error "Cannot convert '{shape}' to a shape. Found invalid dimension '{d}' of type '{type(d)}'. " thrown in keras-team/keras.
Source
Thrown at keras/src/backend/common/variables.py:627
)
if config.backend() == "torch":
# Replace symbolic dimensions with None to preserve dynamic shapes
# during torch.export tracing
import torch
shape = tuple(None if isinstance(d, torch.SymInt) else d for d in shape)
# Handle dimensions that are not ints and not None, verify they're >= 0.
standardized_shape = []
for d in shape:
if d is None:
standardized_shape.append(d)
continue
# Reject these even if they can be cast to int successfully.
if isinstance(d, (str, float)):
raise ValueError(
f"Cannot convert '{shape}' to a shape. "
f"Found invalid dimension '{d}' of type '{type(d)}'. "
)
try:
# Cast numpy scalars, tf constant tensors, etc.
d = int(d)
except Exception as e:
raise ValueError(
f"Cannot convert '{shape}' to a shape. "
f"Found invalid dimension '{d}' of type '{type(d)}'. "
) from e
if d < 0:
raise ValueError(
f"Cannot convert '{shape}' to a shape. "
"Negative dimensions are not allowed."
)
standardized_shape.append(d)View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/common/variables.py:627 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/6807f06e9f899921.
Report an issue: GitHub.