{"record":{"id":"a88916e5ca1b60c6","repo":"keras-team/keras","slug":"invalid-variable-value-in-statelessscope-all-valu","errorCode":null,"errorMessage":"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}.","messagePattern":"Invalid variable value in StatelessScope: all values in argument `mapping` must be tensors with a shape that matches the corresponding variable shape\\. For variable (.+?), received invalid value (.+?) with shape (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/stateless_scope.py","lineNumber":61,"sourceCode":"\n        self.collect_losses = collect_losses\n        self.initialize_variables = initialize_variables\n        self.losses = []\n        self.state_mapping = {}\n        state_mapping = state_mapping or {}\n        for k, v in state_mapping:\n            if not isinstance(k, Variable):\n                raise ValueError(\n                    \"Invalid reference variable in StatelessScope: \"\n                    \"all keys in argument `mapping` must be Variable \"\n                    f\"instances. Received instead: {k}\"\n                )\n            if isinstance(v, Variable):\n                v = backend.cast(v.value, dtype=k.dtype)\n            else:\n                v = backend.convert_to_tensor(v, dtype=k.dtype)\n            if k.shape != v.shape:\n                raise ValueError(\n                    \"Invalid variable value in StatelessScope: \"\n                    \"all values in argument `mapping` must be tensors with \"\n                    \"a shape that matches the corresponding variable shape. \"\n                    f\"For variable {k}, received invalid value {v} with shape \"\n                    f\"{v.shape}.\"\n                )\n            self.state_mapping[id(k)] = v\n\n    def __enter__(self):\n        self.original_scope = get_stateless_scope()\n        global_state.set_global_attribute(\"stateless_scope\", self)\n        return self\n\n    def add_loss(self, loss):\n        self.losses.append(loss)\n\n    def add_update(self, update):\n        variable, value = update","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/stateless_scope.py#L43-L79","documentation":"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.","triggerScenarios":"Thrown at keras/src/backend/common/stateless_scope.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}