huggingface/transformers · error · ValueError
Each key in `sequence_bias` has to be a non-empty tuple of p
Error message
Each key in `sequence_bias` has to be a non-empty tuple of positive integers, but is {sequence_bias}. What it means
Error "Each key in `sequence_bias` has to be a non-empty tuple of positive integers, but is {sequence_bias}." thrown in huggingface/transformers.
Source
Thrown at src/transformers/generation/logits_process.py:1366
self.length_1_bias[single_token_ids] = torch.tensor(single_token_biases, device=scores.device)
self.prepared_bias_variables = True
def _validate_arguments(self):
sequence_bias = self.sequence_bias
if not isinstance(sequence_bias, dict) and not isinstance(sequence_bias, list) or len(sequence_bias) == 0:
raise ValueError(
f"`sequence_bias` has to be a non-empty dictionary, or non-empty list of lists but is {sequence_bias}."
)
if isinstance(sequence_bias, dict) and any(
not isinstance(sequence_ids, tuple) for sequence_ids in sequence_bias
):
raise ValueError(f"`sequence_bias` has to be a dict with tuples as keys, but is {sequence_bias}.")
if isinstance(sequence_bias, dict) and any(
any((not isinstance(token_id, (int, np.integer)) or token_id < 0) for token_id in sequence_ids)
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}."
)View on GitHub (pinned to a597f97485)
Solutions
- Ensure every key in `sequence_bias` is a non-empty tuple of positive integer token ids.
- Remove empty tuples or non-positive token ids from the keys.
When it happens
Trigger: Raised in SequenceBiasLogitsProcessor.__init__ when a sequence_bias dict key is an empty tuple, a non-tuple, or contains token ids that are not positive integers.
Common situations: Supplying sequence_bias keys with zero/negative token ids or empty tuples, typically from programmatic construction of the bias mapping.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/524e886bb2af38ce.
Report an issue: GitHub.