keras-team/keras · error · ValueError
`name` must be passed as a keyword argument. Received: add_w
Error message
`name` must be passed as a keyword argument. Received: add_weight('{shape_arg}', ...). Use: add_weight(shape=..., name='{shape_arg}'). What it means
Error "`name` must be passed as a keyword argument. Received: add_weight('{shape_arg}', ...). Use: add_weight(shape=..., name='{shape_arg}')." thrown in keras-team/keras.
Source
Thrown at keras/src/layers/layer.py:585
Defaults to `"none"`.
overwrite_with_gradient: Boolean, whether to overwrite the variable
with the computed gradient. This is useful for float8 training.
Defaults to `False`.
name: String name of the variable. Useful for debugging purposes.
"""
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:View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/layer.py:585 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/833ad4c3d68ddd00.
Report an issue: GitHub.