tensorflow/models · error · ValueError
src_num_blocks must be equal to tgt_num_blocks.
Error message
src_num_blocks must be equal to tgt_num_blocks.
What it means
Error "src_num_blocks must be equal to tgt_num_blocks." thrown in tensorflow/models.
Source
Thrown at official/nlp/modeling/layers/block_sparse_attention.py:276
training=training,
)
# pytype: enable=attribute-error
# src_num_blocks and tgt_num_blocks are the number of blocks in the source
# and target. Care should be taken to ensure that the number of blocks in
# the source and target are the same.
if self._query_shape[-2] % self._src_block_size != 0:
raise ValueError(
"query_shape[-2] must be divisible by src_block_size."
)
if self._key_shape[-2] % self._tgt_block_size != 0:
raise ValueError(
"key_shape[-2] must be divisible by tgt_block_size."
)
src_num_blocks = self._query_shape[-2] // self._src_block_size
tgt_num_blocks = self._key_shape[-2] // self._tgt_block_size
if src_num_blocks != tgt_num_blocks and tgt_num_blocks != 1:
raise ValueError(
"src_num_blocks must be equal to tgt_num_blocks."
)
# Convert the query/key/value into blocks to perform block diagonal
# attention.
query_blocks = tf.reshape(query, [
-1,
self._num_heads,
src_num_blocks,
self._src_block_size,
self._key_dim,
])
if tgt_num_blocks != 1 and self._num_kv_heads != 1:
key_blocks = tf.reshape(key, [
-1,
self._num_heads,
tgt_num_blocks,
self._tgt_block_size,
self._key_dim,View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/nlp/modeling/layers/block_sparse_attention.py:276 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/2b75f51bb9be8758.
Report an issue: GitHub.