{"record":{"id":"791b918dababd0df","repo":"tensorflow/models","slug":"transformerlayer-expects-a-three-dimensional-input-791b91","errorCode":null,"errorMessage":"TransformerLayer expects a three-dimensional input of shape [batch, sequence, width].","messagePattern":"TransformerLayer expects a three-dimensional input of shape \\[batch, sequence, width\\]\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/detr/modeling/transformer.py","lineNumber":667,"sourceCode":"    self._activity_regularizer = tf_keras.regularizers.get(activity_regularizer)\n    self._kernel_constraint = tf_keras.constraints.get(kernel_constraint)\n    self._bias_constraint = tf_keras.constraints.get(bias_constraint)\n    self._use_bias = use_bias\n    self._norm_first = norm_first\n    self._norm_epsilon = norm_epsilon\n    self._intermediate_dropout = intermediate_dropout\n    if attention_initializer:\n      self._attention_initializer = tf_keras.initializers.get(\n          attention_initializer)\n    else:\n      self._attention_initializer = tf_utils.clone_initializer(\n          self._kernel_initializer)\n    self._cross_attention_cls = layers.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        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    # Self attention.\n    self.self_attention = layers.attention.CachedAttention(\n        num_heads=self.num_attention_heads,\n        key_dim=self.attention_head_size,","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/detr/modeling/transformer.py#L649-L685","documentation":"Error \"TransformerLayer expects a three-dimensional input of shape [batch, sequence, width].\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/detr/modeling/transformer.py:667 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"}