huggingface/transformers · error · ValueError

Each element in `sequence_bias` has to be a non-empty list o

Error message

Each element in `sequence_bias` has to be a non-empty list of lists of positive integers and float, but is {sequence_bias}.

What it means

Error "Each element in `sequence_bias` has to be a non-empty list of lists of positive integers and float, but is {sequence_bias}." thrown in huggingface/transformers.

Source

Thrown at src/transformers/generation/logits_process.py:1381

            or len(sequence_ids) == 0
            for sequence_ids in sequence_bias
        ):
            raise ValueError(
                f"Each key in `sequence_bias` has to be a non-empty tuple of positive integers, but is "
                f"{sequence_bias}."
            )

        def all_token_bias_pairs_are_valid(sequence):
            return (
                isinstance(sequence[0], list)
                and all(isinstance(token_id, (int, np.integer)) and token_id > 0 for token_id in sequence[0])
                and isinstance(sequence[1], float)
            )

        if isinstance(sequence_bias, list) and any(
            (not all_token_bias_pairs_are_valid(sequence)) or len(sequence) == 0 for sequence in sequence_bias
        ):
            raise ValueError(
                f"Each element in `sequence_bias` has to be a non-empty list of lists of positive integers and float, but is "
                f"{sequence_bias}."
            )
        if isinstance(sequence_bias, dict) and any(not isinstance(bias, float) for bias in sequence_bias.values()):
            raise ValueError(f"`sequence_bias` has to be a dict with floats as values, but is {sequence_bias}.")

    def _convert_list_arguments_into_dict(self):
        """BC: we used to accept `dict{tuple of tokens: float}` directly, now we expect a list"""
        if isinstance(self.sequence_bias, list):
            temp_sequence = self.sequence_bias
            self.sequence_bias = {tuple(sublist[0]): sublist[1] for sublist in temp_sequence}


class NoBadWordsLogitsProcessor(SequenceBiasLogitsProcessor):
    """
    [`LogitsProcessor`] that enforces that specified sequences will never be selected.

    <Tip>

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass `sequence_bias` as a non-empty list of [token_ids, bias] pairs where token_ids is a list of positive integers and bias is a float.
  2. Alternatively use the dict form: {(token_id, ...): float_bias}.

When it happens

Trigger: Raised in SequenceBiasLogitsProcessor.__init__ when the list-of-lists form of sequence_bias contains entries that are not a [token_ids_list, bias] pair of valid types.

Common situations: Using the list form of sequence_bias with malformed inner lists, non-integer token ids, or a non-float bias value.


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/47031dfa9cc69558. Report an issue: GitHub.