{"record":{"id":"1b10a4ba7af53de9","repo":"tensorflow/models","slug":"when-use-dynamic-slicing-is-false-max-sequence","errorCode":null,"errorMessage":"When `use_dynamic_slicing` is False, max_sequence_length should not be specified and we ought to use seq_length to get the variable shape.","messagePattern":"When `use_dynamic_slicing` is False, max_sequence_length should not be specified and we ought to use seq_length to get the variable shape\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/networks/packed_sequence_embedding.py","lineNumber":261,"sourceCode":"    \"\"\"Implements build() for the layer.\"\"\"\n    dimension_list = input_shape.as_list()\n\n    if len(dimension_list) != 3:\n      raise ValueError('PositionEmbedding expects a 3-dimensional input tensor '\n                       'of shape [batch, sequence, width]')\n    seq_length = dimension_list[1]\n    width = dimension_list[2]\n\n    # If we are not using dynamic slicing, we must assume that the sequence\n    # length is fixed and max_sequence_length should not be specified.\n    if not self._use_dynamic_slicing:\n      if seq_length is None:\n        raise ValueError(\n            'PositionEmbedding must have `use_dynamic_slicing` set '\n            'to True (and max_sequence_length set) when the '\n            'sequence (1st) dimension of the input is None.')\n      if self._max_sequence_length is not None:\n        raise ValueError(\n            'When `use_dynamic_slicing` is False, max_sequence_length should '\n            'not be specified and we ought to use seq_length to get the '\n            'variable shape.')\n\n    if self._max_sequence_length is not None:\n      weight_sequence_length = self._max_sequence_length\n    else:\n      weight_sequence_length = seq_length\n\n    self._position_embeddings = self.add_weight(\n        'embeddings',\n        shape=[weight_sequence_length, width],\n        initializer=self._initializer)\n\n    super().build(input_shape)\n\n  def call(self, inputs, position_ids=None, sub_sequence_mask=None):\n    \"\"\"Implements call() for the layer.","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/networks/packed_sequence_embedding.py#L243-L279","documentation":"Error \"When `use_dynamic_slicing` is False, max_sequence_length should not be specified and we ought to use seq_length to get the variable shape.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/networks/packed_sequence_embedding.py:261 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"}