{"record":{"id":"b1ca69ab1362c6ae","repo":"tensorflow/models","slug":"the-hidden-size-d-is-not-a-multiple-of-the-numb","errorCode":null,"errorMessage":"The hidden size (%d) is not a multiple of the number of attention heads (%d)","messagePattern":"The hidden 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.py","lineNumber":261,"sourceCode":"    if cross_attention_cls is not None:\n      self._cross_attention_cls = cross_attention_cls\n      if self.multi_channel_cross_attention:\n        logging.warning(\n            \"%s will be used for cross attention\", cross_attention_cls\n        )\n    elif self.multi_channel_cross_attention:\n      self._cross_attention_cls = multi_channel_attention.MultiChannelAttention\n    else:\n      self._cross_attention_cls = attention.MultiHeadAttention\n\n  def build(self, input_shape):\n    target_tensor_shape = tf.TensorShape(input_shape[0])\n    if len(target_tensor_shape.as_list()) != 3:\n      raise ValueError(\"TransformerLayer expects a three-dimensional input of \"\n                       \"shape [batch, sequence, width].\")\n    hidden_size = target_tensor_shape[2]\n    if hidden_size % self.num_attention_heads != 0:\n      raise ValueError(\n          \"The hidden size (%d) is not a multiple of the number of attention \"\n          \"heads (%d)\" % (hidden_size, self.num_attention_heads))\n    self.attention_head_size = int(hidden_size) // self.num_attention_heads\n    common_kwargs = dict(\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    # Self attention.\n    self.self_attention = self._self_attention_cls(\n        num_heads=self.num_attention_heads,\n        key_dim=self.attention_head_size,\n        dropout=self.attention_dropout_rate,\n        use_bias=self._use_bias,\n        kernel_initializer=tf_utils.clone_initializer(\n            self._attention_initializer),\n        bias_initializer=tf_utils.clone_initializer(self._bias_initializer),","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/transformer.py#L243-L279","documentation":"Error \"The hidden 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.py:261 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"}