tensorflow/models · error · NotImplementedError

MaskedLM cannot be directly serialized because it has variab

Error message

MaskedLM cannot be directly serialized because it has variable sharing logic.

What it means

Error "MaskedLM cannot be directly serialized because it has variable sharing logic." thrown in tensorflow/models.

Source

Thrown at official/nlp/modeling/layers/masked_lm.py:99

    lm_data = self.layer_norm(lm_data)
    lm_data = tf.matmul(lm_data, self.embedding_table, transpose_b=True)
    logits = tf.nn.bias_add(lm_data, self.bias)
    masked_positions_length = (
        masked_positions.shape.as_list()[1] or tf.shape(masked_positions)[1]
    )
    batch_size = (
        masked_positions.shape.as_list()[0] or tf.shape(masked_positions)[0]
    )
    logits = tf.reshape(
        logits,
        [batch_size, masked_positions_length, self._vocab_size],
    )
    if self._output_type == 'logits':
      return logits
    return tf.nn.log_softmax(logits)

  def get_config(self):
    raise NotImplementedError('MaskedLM cannot be directly serialized because '
                              'it has variable sharing logic.')

  def _gather_indexes(self, sequence_tensor, positions):
    """Gathers the vectors at the specific positions, for performance.

    Args:
        sequence_tensor: Sequence output of shape
          (`batch_size`, `seq_length`, num_hidden) where num_hidden is number of
          hidden units.
        positions: Positions ids of tokens in sequence to mask for pretraining
          of with dimension (batch_size, num_predictions) where
          `num_predictions` is maximum number of tokens to mask out and predict
          per each sequence.

    Returns:
        Masked out sequence tensor of shape (batch_size * num_predictions,
        num_hidden).
    """

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/nlp/modeling/layers/masked_lm.py:99 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/2700abb51a0701d7. Report an issue: GitHub.