{"record":{"id":"7b45a458c8d41d66","repo":"tensorflow/models","slug":"you-are-reloading-a-model-that-was-saved-with-a-po-7b45a4","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/token_dropping/encoder.py","lineNumber":398,"sourceCode":"  def transformer_layers(self):\n    \"\"\"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      print('WARNING: ' + warn_string)\n      logging.warn(warn_string)\n\n    return cls(**config)\n","sourceCodeStart":380,"sourceCodeEnd":401,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/token_dropping/encoder.py#L380-L401","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/token_dropping/encoder.py:398 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Load the saved model outside of the Keras serialization API: reconstruct the token-dropping encoder in code and restore weights with model.load_weights() or a tf.train.Checkpoint, so the shared embedding layer object is preserved.","If no further training is planned, the warning can be ignored; the reloaded model is fine for inference.","Do not pass embedding_layer through the serialized config; construct the encoder with the shared embedding layer object directly."],"exampleFix":"# Instead of tf_keras.models.load_model(...) (which triggers from_config),\n# rebuild the encoder and restore weights:\nencoder = TokenDroppingEncoder(vocab_size=vocab_size, embedding_layer=shared_embedding, ...)\nmodel = build_model(encoder)\nmodel.load_weights(checkpoint_path)","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"}