{"record":{"id":"d43e8f3026c2d4a3","repo":"tensorflow/models","slug":"query-shape-2-must-be-divisible-by-src-block-siz","errorCode":null,"errorMessage":"query_shape[-2] must be divisible by src_block_size.","messagePattern":"query_shape\\[-2\\] must be divisible by src_block_size\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/block_sparse_attention.py","lineNumber":265,"sourceCode":"    ):\n      logging.info(\n          \"Computing default attention as block sizes are equal to sequence\"\n          \" lengths.\"\n      )\n      # pytype: disable=attribute-error\n      return super()._compute_attention(\n          query,\n          key,\n          value,\n          attention_mask=attention_mask,\n          training=training,\n      )\n      # pytype: enable=attribute-error\n    # src_num_blocks and tgt_num_blocks are the number of blocks in the source\n    # and target. Care should be taken to ensure that the number of blocks in\n    # the source and target are the same.\n    if self._query_shape[-2] % self._src_block_size != 0:\n      raise ValueError(\n          \"query_shape[-2] must be divisible by src_block_size.\"\n      )\n    if self._key_shape[-2] % self._tgt_block_size != 0:\n      raise ValueError(\n          \"key_shape[-2] must be divisible by tgt_block_size.\"\n      )\n    src_num_blocks = self._query_shape[-2] // self._src_block_size\n    tgt_num_blocks = self._key_shape[-2] // self._tgt_block_size\n\n    if src_num_blocks != tgt_num_blocks and tgt_num_blocks != 1:\n      raise ValueError(\n          \"src_num_blocks must be equal to tgt_num_blocks.\"\n      )\n    # Convert the query/key/value into blocks to perform block diagonal\n    # attention.\n    query_blocks = tf.reshape(query, [\n        -1,\n        self._num_heads,","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/block_sparse_attention.py#L247-L283","documentation":"Error \"query_shape[-2] must be divisible by src_block_size.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/block_sparse_attention.py:265 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"}