{"record":{"id":"d325dac106d9fdaf","repo":"tensorflow/models","slug":"setting-diff-q-and-kv-attention-layer-norm-to-tr","errorCode":null,"errorMessage":"Setting `diff_q_and_kv_attention_layer_norm` to Truewhen `norm_first` is False is invalid.","messagePattern":"Setting `diff_q_and_kv_attention_layer_norm` to Truewhen `norm_first` is False is invalid\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/transformer_encoder_block.py","lineNumber":280,"sourceCode":"        and self._num_kv_heads is not None\n        and self._num_kv_heads != 1\n    ):\n      raise ValueError(\n          \"Block sparse attention only supports Multi-query attention.Please\"\n          \" set num_kv_heads to 1 to enable MQA with block sparse attention.\"\n      )\n    if attention_initializer:\n      self._attention_initializer = tf_keras.initializers.get(\n          attention_initializer\n      )\n    else:\n      self._attention_initializer = tf_utils.clone_initializer(\n          self._kernel_initializer\n      )\n    self._attention_axes = attention_axes\n\n    if self._diff_q_kv_att_layer_norm and not self._norm_first:\n      raise ValueError(\n          \"Setting `diff_q_and_kv_attention_layer_norm` to True\"\n          \"when `norm_first` is False is invalid.\"\n      )\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    elif isinstance(input_shape, dict):\n      input_tensor_shape = tf.TensorShape(input_shape[\"input_tensor\"])\n    else:\n      raise ValueError(\n          \"The type of input shape argument is not supported, got: %s\" %\n          type(input_shape))\n    einsum_equation = \"abc,cd->abd\"\n    if len(input_tensor_shape.as_list()) > 3:\n      einsum_equation = \"...bc,cd->...bd\"","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/transformer_encoder_block.py#L262-L298","documentation":"Error \"Setting `diff_q_and_kv_attention_layer_norm` to Truewhen `norm_first` is False is invalid.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/transformer_encoder_block.py:280 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"}