{"record":{"id":"96a241eb70f5cc30","repo":"tensorflow/models","slug":"if-inputs-is-none-length-must-be-set-in-relativ","errorCode":null,"errorMessage":"If inputs is None, `length` must be set in RelativePositionEmbedding().","messagePattern":"If inputs is None, `length` must be set in RelativePositionEmbedding\\(\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/position_embedding.py","lineNumber":153,"sourceCode":"    }\n    base_config = super(RelativePositionEmbedding, self).get_config()\n    return dict(list(base_config.items()) + list(config.items()))\n\n  def call(self, inputs, length=None):\n    \"\"\"Implements call() for the layer.\n\n    Args:\n      inputs: An tensor whose second dimension will be used as `length`. If\n        `None`, the other `length` argument must be specified.\n      length: An optional integer specifying the number of positions. If both\n        `inputs` and `length` are spcified, `length` must be equal to the second\n        dimension of `inputs`.\n\n    Returns:\n      A tensor in shape of `(length, hidden_size)`.\n    \"\"\"\n    if inputs is None and length is None:\n      raise ValueError(\"If inputs is None, `length` must be set in \"\n                       \"RelativePositionEmbedding().\")\n    if inputs is not None:\n      input_shape = tf_utils.get_shape_list(inputs)\n      if length is not None and length != input_shape[1]:\n        raise ValueError(\n            \"If inputs is not None, `length` must equal to input_shape[1].\")\n      length = input_shape[1]\n    position = tf.cast(tf.range(length), tf.float32)\n    num_timescales = self._hidden_size // 2\n    min_timescale, max_timescale = self._min_timescale, self._max_timescale\n    log_timescale_increment = (\n        math.log(float(max_timescale) / float(min_timescale)) /\n        (tf.cast(num_timescales, tf.float32) - 1))\n    inv_timescales = min_timescale * tf.exp(\n        tf.cast(tf.range(num_timescales), tf.float32) *\n        -log_timescale_increment)\n    scaled_time = tf.expand_dims(position, 1) * tf.expand_dims(\n        inv_timescales, 0)","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/position_embedding.py#L135-L171","documentation":"Error \"If inputs is None, `length` must be set in RelativePositionEmbedding().\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/position_embedding.py:153 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"}