{"record":{"id":"acee4da0dd423763","repo":"keras-team/keras","slug":"invalid-output-shape-output-shape-when-speci","errorCode":null,"errorMessage":"Invalid `output_shape`: {output_shape}. When specified, the `output_shape` should be of type tuple, list, or int.","messagePattern":"Invalid `output_shape`: (.+?)\\. When specified, the `output_shape` should be of type tuple, list, or int\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/attention/multi_head_attention.py","lineNumber":169,"sourceCode":"                \"Received an invalid value for argument `value_dim`, \"\n                \"expected a positive integer or `None`. Received: \"\n                f\"value_dim={value_dim}\"\n            )\n        super().__init__(**kwargs)\n        self.supports_masking = True\n        self._num_heads = num_heads\n        self._key_dim = key_dim\n        self._value_dim = value_dim if value_dim else key_dim\n        self._dropout = dropout\n        self._use_bias = use_bias\n        self._use_gate = use_gate\n        if output_shape:\n            if isinstance(output_shape, int):\n                output_shape = (output_shape,)\n            try:\n                output_shape = tuple(output_shape)\n            except:\n                raise ValueError(\n                    f\"Invalid `output_shape`: {output_shape}. When \"\n                    \"specified, the `output_shape` should be of type tuple, \"\n                    \"list, or int.\"\n                )\n        self._output_shape = output_shape\n        self._flash_attention = flash_attention or is_flash_attention_enabled()\n        self._kernel_initializer = initializers.get(kernel_initializer)\n        self._bias_initializer = initializers.get(bias_initializer)\n        self._kernel_regularizer = regularizers.get(kernel_regularizer)\n        self._bias_regularizer = regularizers.get(bias_regularizer)\n        self._activity_regularizer = regularizers.get(activity_regularizer)\n        self._kernel_constraint = constraints.get(kernel_constraint)\n        self._bias_constraint = constraints.get(bias_constraint)\n        if isinstance(attention_axes, int):\n            attention_axes = (attention_axes,)\n        elif attention_axes and not isinstance(attention_axes, (list, tuple)):\n            raise ValueError(\n                \"`attention_axes` must be an int, list, or tuple.\"","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/attention/multi_head_attention.py#L151-L187","documentation":"Constructor validation in MultiHeadAttention: when `output_shape` is provided it must be an int, tuple, or list (an int is normalized to a 1-tuple); the code attempts this normalization and the bare except re-raises with this error when normalization/conversion to a shape tuple fails, meaning an unconvertible type or malformed value was passed.","triggerScenarios":"Thrown at keras/src/layers/attention/multi_head_attention.py:169 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass output_shape as an int (e.g. 10) or a tuple/list of ints (e.g. (10,) or [None, 10])","Do not pass None-like sentinels, strings, or nested/ragged structures","If loading from config, ensure output_shape was serialized as a plain list of ints/nulls"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}