keras-team/keras · error · ValueError
`shape` was passed both positionally and as a keyword argume
Error message
`shape` was passed both positionally and as a keyword argument.
What it means
Error "`shape` was passed both positionally and as a keyword argument." thrown in keras-team/keras.
Source
Thrown at keras/src/layers/layer.py:591
self._check_super_called()
if args:
# `args` is only kept to detect the legacy Keras 2 call style
# (`add_weight(shape, initializer, dtype, ...)`) and raise a clear
# error for positional `name`.
if len(args) > 3:
raise TypeError(
"add_weight() takes at most 3 positional arguments "
f"but {len(args)} were given."
)
shape_arg = args[0]
if isinstance(shape_arg, str):
raise ValueError(
"`name` must be passed as a keyword argument. "
f"Received: add_weight('{shape_arg}', ...). "
f"Use: add_weight(shape=..., name='{shape_arg}')."
)
if shape is not None:
raise ValueError(
"`shape` was passed both positionally and as "
"a keyword argument."
)
shape = shape_arg
if len(args) > 1:
if initializer is not None:
raise ValueError(
"`initializer` was passed both positionally and "
"as a keyword argument."
)
initializer = args[1]
if len(args) > 2:
if dtype is not None:
raise ValueError(
"`dtype` was passed both positionally and as a "
"keyword argument."
)
dtype = args[2]View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/layer.py:591 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/6417aae3b2b163d0.
Report an issue: GitHub.