{"record":{"id":"29c3e9d7671d7150","repo":"tensorflow/models","slug":"you-are-reloading-a-model-that-was-saved-with-a-po","errorCode":null,"errorMessage":"You are reloading a model that was saved with a potentially-shared embedding layer object. If you contine to train this model, the embedding layer will no longer be shared. To work around this, load the model outside of the Keras API.","messagePattern":"You are reloading a model that was saved with a potentially-shared embedding layer object\\. If you contine to train this model, the embedding layer will no longer be shared\\. To work around this, load the model outside of the Keras API\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"official/projects/lra/transformer_encoder.py","lineNumber":286,"sourceCode":"    \"\"\"List of Transformer layers in the encoder.\"\"\"\n    return self._transformer_layers\n\n  @property\n  def pooler_layer(self):\n    \"\"\"The pooler dense layer after the transformer layers.\"\"\"\n    return self._pooler_layer\n\n  @classmethod\n  def from_config(cls, config, custom_objects=None):\n    if 'embedding_layer' in config and config['embedding_layer'] is not None:\n      warn_string = (\n          'You are reloading a model that was saved with a '\n          'potentially-shared embedding layer object. If you contine to '\n          'train this model, the embedding layer will no longer be shared. '\n          'To work around this, load the model outside of the Keras API.'\n      )\n      print('WARNING: ' + warn_string)\n      logging.warn(warn_string)\n\n    return cls(**config)\n\n  def _get_embeddings(\n      self,\n      word_ids: tf.Tensor,\n      type_ids: tf.Tensor,\n      word_embeddings: Optional[tf.Tensor],\n      dense_inputs: Optional[tf.Tensor],\n      dense_type_ids: Optional[tf.Tensor],\n  ) -> tf.Tensor:\n    if word_embeddings is None:\n      word_embeddings = self._embedding_layer(word_ids)\n\n    if dense_inputs is not None:\n      # Concat the dense embeddings at sequence end.\n      word_embeddings = tf.concat([word_embeddings, dense_inputs], axis=1)\n      type_ids = tf.concat([type_ids, dense_type_ids], axis=1)","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/lra/transformer_encoder.py#L268-L304","documentation":"Error \"You are reloading a model that was saved with a potentially-shared embedding layer object. If you contine to train this model, the embedding layer will no longer be shared. To work around this, load the model outside of the Keras API.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/lra/transformer_encoder.py:286 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Load the model outside the Keras API (e.g. via tf.train.Checkpoint) to preserve the shared embedding layer.","Rebuild and re-share the embedding layer explicitly after loading if you keep using the Keras API."],"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"}