{"record":{"id":"fc09ec22d8ddf477","repo":"tensorflow/models","slug":"max-distance-must-not-be-negative","errorCode":null,"errorMessage":"`max_distance` must not be negative.","messagePattern":"`max_distance` must not be negative\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/triviaqa/inputs.py","lineNumber":229,"sourceCode":"      output from this generator.\n    left_pad_value: Integer id for all positions at or beyond max_distance to\n      the left.\n    right_pad_value: Integer id for all positions at or beyond max_distance to\n      the right.\n  \"\"\"\n\n  def __init__(self, max_distance: int, ignore_direction: bool = False):\n    \"\"\"Init.\n\n    Args:\n      max_distance: The maximum distance to represent. Must not be negative. All\n        larger distances will be clipped to this value.\n      ignore_direction: If True, both left and right position representations\n        will have the same ids based on absolute distance (resulting in\n        symmetric ids around the center token).\n    \"\"\"\n    if max_distance < 0:\n      raise ValueError('`max_distance` must not be negative.')\n    self.max_distance = max_distance\n    self.ignore_direction = ignore_direction\n\n    self.right_pad_value = max_distance\n    self.left_pad_value = max_distance if ignore_direction else 2 * max_distance\n\n    # 0 is the first id, so vocab size is 1 + the largest id (left pad value).\n    self.relative_vocab_size = self.left_pad_value + 1\n\n  def make_relative_att_ids(self,\n                            seq_len: Union[int, tf.Tensor],\n                            batch_size: Optional[Union[int, tf.Tensor]] = 1,\n                            name: Optional[Text] = None) -> tf.Tensor:\n    \"\"\"Makes relative position ids for full self-attention.\n\n    For example, if `max_distance` is 3, `ignore_direction` is False, `seq_len`\n    is 6, and `batch_size` is 1, the result is the following:\n      [[","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/triviaqa/inputs.py#L211-L247","documentation":"Error \"`max_distance` must not be negative.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/triviaqa/inputs.py:229 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"}