{"record":{"id":"5d3ded825f6f21ca","repo":"tensorflow/models","slug":"positionembedding-must-have-use-dynamic-slicing","errorCode":null,"errorMessage":"PositionEmbedding must have `use_dynamic_slicing` set to True (and max_sequence_length set) when the sequence (1st) dimension of the input is None.","messagePattern":"PositionEmbedding must have `use_dynamic_slicing` set to True \\(and max_sequence_length set\\) when the sequence \\(1st\\) dimension of the input is None\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/networks/packed_sequence_embedding.py","lineNumber":256,"sourceCode":"    }\n    base_config = super().get_config()\n    return dict(list(base_config.items()) + list(config.items()))\n\n  def build(self, input_shape):\n    \"\"\"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)","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/networks/packed_sequence_embedding.py#L238-L274","documentation":"Error \"PositionEmbedding must have `use_dynamic_slicing` set to True (and max_sequence_length set) when the sequence (1st) dimension of the input is None.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/networks/packed_sequence_embedding.py:256 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"}