tensorflow/models · error

You are reloading a model that was saved with a potentially-

Error message

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.

What it means

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.

Source

Thrown at official/projects/token_dropping/encoder.py:398

  def transformer_layers(self):
    """List of Transformer layers in the encoder."""
    return self._transformer_layers

  @property
  def pooler_layer(self):
    """The pooler dense layer after the transformer layers."""
    return self._pooler_layer

  @classmethod
  def from_config(cls, config, custom_objects=None):
    if 'embedding_layer' in config and config['embedding_layer'] is not None:
      warn_string = (
          '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.')
      print('WARNING: ' + warn_string)
      logging.warn(warn_string)

    return cls(**config)

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. 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.
  2. If no further training is planned, the warning can be ignored; the reloaded model is fine for inference.
  3. Do not pass embedding_layer through the serialized config; construct the encoder with the shared embedding layer object directly.

Example fix

# Instead of tf_keras.models.load_model(...) (which triggers from_config),
# rebuild the encoder and restore weights:
encoder = TokenDroppingEncoder(vocab_size=vocab_size, embedding_layer=shared_embedding, ...)
model = build_model(encoder)
model.load_weights(checkpoint_path)

When it happens

Trigger: Thrown at official/projects/token_dropping/encoder.py:398 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/7b45a458c8d41d66. Report an issue: GitHub.