tensorflow/models · error · ValueError
Invalid attention bias type
Error message
Invalid attention bias type: %s
What it means
Raised by get_attention_bias in NHNet's decoder when bias_type is not one of the supported values (e.g. 'bias', 'mask', 'both'). It is a generic dispatch guard for the attention-bias builder; the caller passed an unrecognized bias_type string.
Solutions
- Check the bias_type argument passed by the decoder call and correct typos/casing
- Pass one of the helper's supported bias types listed in its docstring
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/nhnet/decoder.py:146 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/299e81bc73977287.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/nhnet/decoder.py:146
# Gets the cache for decoding.
if cache is None:
output_tensor, _ = self.layers[layer_idx](transformer_inputs)
else:
cache_layer_idx = str(layer_idx)
output_tensor, cache[cache_layer_idx] = self.layers[layer_idx](
transformer_inputs,
cache=cache[cache_layer_idx],
decode_loop_step=decode_loop_step)
return output_tensor, cache
def get_attention_bias(input_tensor,
bias_type,
padding_value=0,
max_length=None):
"""A helper function to get various attention bias tensors."""
if bias_type not in ("single_cross", "multi_cross", "decoder_self"):
raise ValueError("Invalid attention bias type: %s" % bias_type)
if bias_type == "single_cross":
length = tf_utils.get_shape_list(input_tensor, expected_rank=2)[1]
bias = transformer_utils.get_padding_bias(
input_tensor, padding_value=padding_value)
elif bias_type == "multi_cross":
length = tf_utils.get_shape_list(input_tensor, expected_rank=3)[2]
padding = transformer_utils.get_padding(
input_tensor, padding_value=padding_value)
bias = padding * -1e9
else:
if max_length is not None:
length = max_length
else:
length = tf_utils.get_shape_list(input_tensor, expected_rank=2)[1]
bias = transformer_utils.get_decoder_self_attention_bias(length)
return tf.where(bias < 0, tf.zeros_like(bias), tf.ones_like(bias))
View on GitHub (pinned to e006f5f0d5)