tensorflow/models · error · ValueError

At most one of `hub_module_url` and `init_checkpoint` can be

Error message

At most one of `hub_module_url` and `init_checkpoint` can be specified.

What it means

Error "At most one of `hub_module_url` and `init_checkpoint` can be specified." thrown in tensorflow/models.

Source

Thrown at official/projects/text_classification_example/classification_example.py:67

  hub_module_url: str = ''
  model: ModelConfig = dataclasses.field(default_factory=ModelConfig)

  num_classes = 2
  class_names = ['A', 'B']
  train_data: cfg.DataConfig = dataclasses.field(
      default_factory=classification_data_loader.ClassificationExampleDataConfig
  )
  validation_data: cfg.DataConfig = dataclasses.field(
      default_factory=classification_data_loader.ClassificationExampleDataConfig
  )


class ClassificationExampleTask(base_task.Task):
  """Task object for classification."""

  def build_model(self) -> tf_keras.Model:
    if self.task_config.hub_module_url and self.task_config.init_checkpoint:
      raise ValueError('At most one of `hub_module_url` and '
                       '`init_checkpoint` can be specified.')
    if self.task_config.hub_module_url:
      encoder_network = utils.get_encoder_from_hub(
          self.task_config.hub_module_url)
    else:
      encoder_network = encoders.build_encoder(self.task_config.model.encoder)

    return models.BertClassifier(
        network=encoder_network,
        num_classes=len(self.task_config.class_names),
        initializer=tf_keras.initializers.TruncatedNormal(
            stddev=self.task_config.model.head_initializer_range),
        dropout_rate=self.task_config.model.head_dropout)

  def build_losses(self, labels, model_outputs, aux_losses=None) -> tf.Tensor:
    loss = tf_keras.losses.sparse_categorical_crossentropy(
        labels, tf.cast(model_outputs, tf.float32), from_logits=True)
    return tf_utils.safe_mean(loss)

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/text_classification_example/classification_example.py:67 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/a0150294a3f38791. Report an issue: GitHub.