tensorflow/models · error · ValueError
`max_distance` must not be negative.
Error message
`max_distance` must not be negative.
What it means
Error "`max_distance` must not be negative." thrown in tensorflow/models.
Source
Thrown at official/projects/triviaqa/inputs.py:229
output from this generator.
left_pad_value: Integer id for all positions at or beyond max_distance to
the left.
right_pad_value: Integer id for all positions at or beyond max_distance to
the right.
"""
def __init__(self, max_distance: int, ignore_direction: bool = False):
"""Init.
Args:
max_distance: The maximum distance to represent. Must not be negative. All
larger distances will be clipped to this value.
ignore_direction: If True, both left and right position representations
will have the same ids based on absolute distance (resulting in
symmetric ids around the center token).
"""
if max_distance < 0:
raise ValueError('`max_distance` must not be negative.')
self.max_distance = max_distance
self.ignore_direction = ignore_direction
self.right_pad_value = max_distance
self.left_pad_value = max_distance if ignore_direction else 2 * max_distance
# 0 is the first id, so vocab size is 1 + the largest id (left pad value).
self.relative_vocab_size = self.left_pad_value + 1
def make_relative_att_ids(self,
seq_len: Union[int, tf.Tensor],
batch_size: Optional[Union[int, tf.Tensor]] = 1,
name: Optional[Text] = None) -> tf.Tensor:
"""Makes relative position ids for full self-attention.
For example, if `max_distance` is 3, `ignore_direction` is False, `seq_len`
is 6, and `batch_size` is 1, the result is the following:
[[View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/triviaqa/inputs.py:229 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/fc09ec22d8ddf477.
Report an issue: GitHub.