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/lra/transformer_encoder.py:286

    """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)

  def _get_embeddings(
      self,
      word_ids: tf.Tensor,
      type_ids: tf.Tensor,
      word_embeddings: Optional[tf.Tensor],
      dense_inputs: Optional[tf.Tensor],
      dense_type_ids: Optional[tf.Tensor],
  ) -> tf.Tensor:
    if word_embeddings is None:
      word_embeddings = self._embedding_layer(word_ids)

    if dense_inputs is not None:
      # Concat the dense embeddings at sequence end.
      word_embeddings = tf.concat([word_embeddings, dense_inputs], axis=1)
      type_ids = tf.concat([type_ids, dense_type_ids], axis=1)

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Load the model outside the Keras API (e.g. via tf.train.Checkpoint) to preserve the shared embedding layer.
  2. Rebuild and re-share the embedding layer explicitly after loading if you keep using the Keras API.

When it happens

Trigger: Thrown at official/projects/lra/transformer_encoder.py:286 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/29c3e9d7671d7150. Report an issue: GitHub.