tensorflow/models · error · ValueError

The length of encoded_feature_dropout_rates must be equal…

Error message

The length of encoded_feature_dropout_rates must be equal to the number of backbones.

What it means

Raised in Pix2SeqModel.__init__ when encoded_feature_dropout_rates has a different length than the backbones list; one dropout rate per backbone is required.

Solutions

  1. Provide one dropout rate per backbone (often all zeros)
  2. Or omit the list to use defaults matching the backbone count
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/pix2seq/modeling/pix2seq_model.py:250 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/5b5521018aeb91e8. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/pix2seq/modeling/pix2seq_model.py:250

      early_stopping_token: int | None = None,
      **kwargs,
  ):
    super().__init__(**kwargs)
    self._backbones = backbones
    self._backbone_endpoint_names = backbone_endpoint_names
    self._max_seq_len = max_seq_len
    self._vocab_size = vocab_size
    self._hidden_size = hidden_size
    self._num_heads = num_heads
    self._num_encoder_layers = num_encoder_layers
    self._num_decoder_layers = num_decoder_layers
    self._drop_path = drop_path
    self._drop_units = drop_units
    self._drop_att = drop_att
    if hidden_size % 2 != 0:
      raise ValueError("hidden_size must be a multiple of 2.")
    if len(encoded_feature_dropout_rates) != len(self._backbones):
      raise ValueError(
          "The length of encoded_feature_dropout_rates must be equal to the "
          "number of backbones."
      )

    self._encoder_dropouts = [
        tf_keras.layers.Dropout(r) for r in encoded_feature_dropout_rates
    ]
    # Separate projections and learned layer normalization for each image.
    num_backbones = len(self._backbones)
    self._stem_projections = [
        tf_keras.layers.Dense(self._hidden_size, name="stem_projection")
        for _ in range(num_backbones)
    ]
    self._stem_lns = [
        tf_keras.layers.LayerNormalization(epsilon=1e-6, name="stem_ln")
        for _ in range(num_backbones)
    ]

View on GitHub (pinned to e006f5f0d5)