tensorflow/models · error · ValueError

reuse_attention_scores cannot be None when reuse_attention i

Error message

reuse_attention_scores cannot be None when reuse_attention is True or > 0.

What it means

Error "reuse_attention_scores cannot be None when reuse_attention is True or > 0." thrown in tensorflow/models.

Source

Thrown at official/nlp/modeling/layers/reuse_attention.py:577

          tf.einsum(self._combine_equation, self._dropout_layer(
              reuse_scores, training=training), value[0]))
    # Partial or no reuse
    if self._reuse_heads < self._num_heads:
      attention_output.append(
          tf.einsum(self._combine_equation, self._dropout_layer(
              new_scores, training=training), value[-1]))
    return attention_output, attention_scores

  def call(self,
           query,
           value,
           key=None,
           attention_mask=None,
           return_attention_scores=False,
           training=None,
           reuse_attention_scores=None):
    if self._reuse_heads > 0 and reuse_attention_scores is None:
      raise ValueError("reuse_attention_scores cannot be None when "
                       "reuse_attention is True or > 0.")
    if not self._built_from_signature:
      self._build_from_signature(query=query, value=value, key=key)
    if key is None:
      key = value

    #   N = `num_attention_heads`
    #   H = `size_per_head`
    # `value` = [B, S, N, H]
    value = [vd(value) for vd in self._value_dense]
    if self._reuse_heads < self._num_heads:
      # `query` = [B, T, N ,H]
      query = self._query_dense(query)

      # `key` = [B, S, N, H]
      key = self._key_dense(key)
    else:
      query, key = None, None

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/nlp/modeling/layers/reuse_attention.py:577 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/e59d2218f16797dd. Report an issue: GitHub.