{"record":{"id":"8fa04c2ef988b1e0","repo":"tensorflow/models","slug":"the-input-size-hidden-size-is-not-a-multiple-o","errorCode":null,"errorMessage":"The input size ({hidden_size}) is not a multiple of the number of attention heads ({self._num_heads})","messagePattern":"The input size \\((.+?)\\) is not a multiple of the number of attention heads \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/longformer/longformer_encoder_block.py","lineNumber":131,"sourceCode":"    else:\n      self._attention_initializer = self._kernel_initializer\n    self._attention_axes = attention_axes\n\n  def build(self, input_shape):\n    if isinstance(input_shape, tf.TensorShape):\n      input_tensor_shape = input_shape\n    elif isinstance(input_shape, (list, tuple)):\n      input_tensor_shape = tf.TensorShape(input_shape[0])\n    else:\n      raise ValueError(\n          f\"The type of input shape argument is not supported, got: \"\n          f\"{type(input_shape)}\")\n    einsum_equation = \"abc,cd->abd\"\n    if len(input_tensor_shape.as_list()) > 3:\n      einsum_equation = \"...bc,cd->...bd\"\n    hidden_size = input_tensor_shape[-1]\n    if hidden_size % self._num_heads != 0:\n      raise ValueError(\n          f\"The input size ({hidden_size}) is not a multiple of the number of attention \"\n          f\"heads ({self._num_heads})\")\n    self._attention_head_size = int(hidden_size // self._num_heads)\n    common_kwargs = dict(\n        bias_initializer=self._bias_initializer,\n        kernel_regularizer=self._kernel_regularizer,\n        bias_regularizer=self._bias_regularizer,\n        activity_regularizer=self._activity_regularizer,\n        kernel_constraint=self._kernel_constraint,\n        bias_constraint=self._bias_constraint)\n    # TFLongformerSelfAttention + TFLongformerSelfOutput.dense\n    self._attention_layer = LongformerAttention(\n        # Longformer\n        layer_id=self._layer_id,\n        global_attention_size=self.global_attention_size,\n        attention_window=self._attention_window,\n        num_heads=self._num_heads,\n        key_dim=self._attention_head_size,","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/longformer/longformer_encoder_block.py#L113-L149","documentation":"Error \"The input size ({hidden_size}) is not a multiple of the number of attention heads ({self._num_heads})\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/longformer/longformer_encoder_block.py:131 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":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}