{"record":{"id":"51d28a60725664a7","repo":"tensorflow/models","slug":"the-input-size-d-is-not-a-multiple-of-the-numbe-51d28a","errorCode":null,"errorMessage":"The input size (%d) is not a multiple of the number of attention heads (%d)","messagePattern":"The input size \\((.+?)\\) is not a multiple of the number of attention heads \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/transformer_xl.py","lineNumber":143,"sourceCode":"    input_tensor = input_shape[0] if len(input_shape) == 2 else input_shape\n    input_tensor_shape = tf.TensorShape(input_tensor)\n    if len(input_tensor_shape.as_list()) != 3:\n      raise ValueError(\"TransformerLayer expects a three-dimensional input of \"\n                       \"shape [batch, sequence, width].\")\n    batch_size, sequence_length, hidden_size = input_tensor_shape\n\n    if len(input_shape) == 2:\n      mask_tensor_shape = tf.TensorShape(input_shape[1])\n      expected_mask_tensor_shape = tf.TensorShape(\n          [batch_size, sequence_length, sequence_length])\n      if not expected_mask_tensor_shape.is_compatible_with(mask_tensor_shape):\n        raise ValueError(\"When passing a mask tensor to TransformerXLBlock, \"\n                         \"the mask tensor must be of shape [batch, \"\n                         \"sequence_length, sequence_length] (here %s). Got a \"\n                         \"mask tensor of shape %s.\" %\n                         (expected_mask_tensor_shape, mask_tensor_shape))\n    if hidden_size % self._num_heads != 0:\n      raise ValueError(\n          \"The input size (%d) is not a multiple of the number of attention \"\n          \"heads (%d)\" % (hidden_size, self._num_heads))\n    self._attention_layer = self._attention_layer_type(\n        num_heads=self._num_heads,\n        key_dim=self._head_size,\n        value_dim=self._head_size,\n        dropout=self._attention_dropout_rate,\n        use_bias=False,\n        kernel_initializer=tf_utils.clone_initializer(self._kernel_initializer),\n        name=\"rel_attn\")\n    self._attention_dropout = tf_keras.layers.Dropout(\n        rate=self._attention_dropout_rate)\n    self._attention_layer_norm = tf_keras.layers.LayerNormalization(\n        name=\"self_attention_layer_norm\",\n        axis=-1,\n        epsilon=self._norm_epsilon,\n        dtype=tf.float32)\n    self._inner_dense = tf_keras.layers.EinsumDense(","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/transformer_xl.py#L125-L161","documentation":"Error \"The input size (%d) is not a multiple of the number of attention heads (%d)\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/transformer_xl.py:143 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"}