tensorflow/models · error · ValueError

Unexpected inputs to %s with length at %d

Error message

Unexpected inputs to %s with length at %d

What it means

Error "Unexpected inputs to %s with length at %d" thrown in tensorflow/models.

Source

Thrown at official/nlp/modeling/layers/transformer_encoder_block.py:606

        streams for the query, and key/value to the multi-head attention. If
        dictionary is provided, it must contain the following keys:
        `input_tensor`, `attention_mask`, `key_value_tensor`.
      output_range: the sequence output range, [0, output_range) for slicing the
        target sequence. `None` means the target sequence is not sliced. If you
        would like to have no change to the model training, it is better to only
        set the `output_range` for serving.

    Returns:
      An output tensor with the same dimensions as input/query tensor.
    """
    if isinstance(inputs, (list, tuple)):
      if len(inputs) == 2:
        input_tensor, attention_mask = inputs
        key_value = None
      elif len(inputs) == 3:
        input_tensor, key_value, attention_mask = inputs
      else:
        raise ValueError("Unexpected inputs to %s with length at %d" %
                         (self.__class__, len(inputs)))
    elif isinstance(inputs, dict):
      if not set(inputs.keys()).issubset(
          set(["input_tensor", "key_value_tensor", "attention_mask"])
      ):
        raise ValueError(
            f"Unexpected keys in input dictionary to: {inputs.keys()}"
        )
      try:
        input_tensor = inputs["input_tensor"]
      except KeyError as e:
        raise ValueError(
            "Missing required key `input_tensor` in input dictionary."
        ) from e
      key_value = inputs.get("key_value_tensor", None)
      attention_mask = inputs.get("attention_mask", None)
    else:
      input_tensor, key_value, attention_mask = (inputs, None, None)

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/nlp/modeling/layers/transformer_encoder_block.py:606 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/793f1dbba3b14b18. Report an issue: GitHub.