{"record":{"id":"3baf6312314414ec","repo":"huggingface/transformers","slug":"sequence-bias-has-to-be-a-dict-with-tuples-as-ke","errorCode":null,"errorMessage":"`sequence_bias` has to be a dict with tuples as keys, but is {sequence_bias}.","messagePattern":"`sequence_bias` has to be a dict with tuples as keys, but is (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":1360,"sourceCode":"        for sequence_ids, bias in self.sequence_bias.items():\n            if len(sequence_ids) == 1:\n                single_token_ids.append(sequence_ids[0])\n                single_token_biases.append(bias)\n\n        if single_token_ids:  # Only if we have any single-token sequences\n            self.length_1_bias[single_token_ids] = torch.tensor(single_token_biases, device=scores.device)\n        self.prepared_bias_variables = True\n\n    def _validate_arguments(self):\n        sequence_bias = self.sequence_bias\n        if not isinstance(sequence_bias, dict) and not isinstance(sequence_bias, list) or len(sequence_bias) == 0:\n            raise ValueError(\n                f\"`sequence_bias` has to be a non-empty dictionary, or non-empty list of lists but is {sequence_bias}.\"\n            )\n        if isinstance(sequence_bias, dict) and any(\n            not isinstance(sequence_ids, tuple) for sequence_ids in sequence_bias\n        ):\n            raise ValueError(f\"`sequence_bias` has to be a dict with tuples as keys, but is {sequence_bias}.\")\n        if isinstance(sequence_bias, dict) and any(\n            any((not isinstance(token_id, (int, np.integer)) or token_id < 0) for token_id in sequence_ids)\n            or len(sequence_ids) == 0\n            for sequence_ids in sequence_bias\n        ):\n            raise ValueError(\n                f\"Each key in `sequence_bias` has to be a non-empty tuple of positive integers, but is \"\n                f\"{sequence_bias}.\"\n            )\n\n        def all_token_bias_pairs_are_valid(sequence):\n            return (\n                isinstance(sequence[0], list)\n                and all(isinstance(token_id, (int, np.integer)) and token_id > 0 for token_id in sequence[0])\n                and isinstance(sequence[1], float)\n            )\n\n        if isinstance(sequence_bias, list) and any(","sourceCodeStart":1342,"sourceCodeEnd":1378,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L1342-L1378","documentation":"Error \"`sequence_bias` has to be a dict with tuples as keys, but is {sequence_bias}.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in SequenceBiasLogitsProcessor.__init__ when sequence_bias is passed as a non-dict type (e.g. a list or string) instead of a dict keyed by token-id tuples.","commonSituations":"Calling generate() with sequence_bias not shaped as {(token_id, ...): bias_float}; migrating from the older list-of-lists API without updating the argument type.","solutions":["Pass `sequence_bias` as a dict mapping token-id tuples to float biases, e.g. `{(token_id,): -10.0}`.","Convert lists of token ids to tuples before building the dict."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}