keras-team/keras · error · ValueError
Invalid variable value in StatelessScope: all values in argu
Error message
Invalid variable value in StatelessScope: all values in argument `mapping` must be tensors with a shape that matches the corresponding variable shape. For variable {k}, received invalid value {v} with shape {v.shape}. What it means
Error "Invalid variable value in StatelessScope: all values in argument `mapping` must be tensors with a shape that matches the corresponding variable shape. For variable {k}, received invalid value {v} with shape {v.shape}." thrown in keras-team/keras.
Source
Thrown at keras/src/backend/common/stateless_scope.py:61
self.collect_losses = collect_losses
self.initialize_variables = initialize_variables
self.losses = []
self.state_mapping = {}
state_mapping = state_mapping or {}
for k, v in state_mapping:
if not isinstance(k, Variable):
raise ValueError(
"Invalid reference variable in StatelessScope: "
"all keys in argument `mapping` must be Variable "
f"instances. Received instead: {k}"
)
if isinstance(v, Variable):
v = backend.cast(v.value, dtype=k.dtype)
else:
v = backend.convert_to_tensor(v, dtype=k.dtype)
if k.shape != v.shape:
raise ValueError(
"Invalid variable value in StatelessScope: "
"all values in argument `mapping` must be tensors with "
"a shape that matches the corresponding variable shape. "
f"For variable {k}, received invalid value {v} with shape "
f"{v.shape}."
)
self.state_mapping[id(k)] = v
def __enter__(self):
self.original_scope = get_stateless_scope()
global_state.set_global_attribute("stateless_scope", self)
return self
def add_loss(self, loss):
self.losses.append(loss)
def add_update(self, update):
variable, value = updateView on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/common/stateless_scope.py:61 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/a88916e5ca1b60c6.
Report an issue: GitHub.