Generate: add SequenceBiasLogitsProcessor
Author: gante
Pull request: yes

# What does this PR do?

Closes #22168 

As per [popular demand](https://github.com/huggingface/transformers/issues/22168#issuecomment-1477998997), adds a logits processor that applies a bias to certain sequences -- `SequenceBiasLogitsProcessor`

This manipulation is a more general case of forbidding certain sequences --`NoBadWordsLogitsProcessor` corresponds to applying an infinite negative bias. As such, this PR makes `NoBadWordsLogitsProcessor` a subclass of the new processor. In the refactoring process, I've rewritten this class to a) be more readable (clear variable naming, comments, docstrings); and b) be faster (though some vectorization).


Comments:
_The documentation is not available anymore as the PR was closed or merged._

@sgugger @amyeroberts 

A further request for approval, as I've introduced a pattern that I'd like to repeat (assuming you're okay with it).

In the latest commit, you'll see:
1. An example in the logit processor class;
2. The new generation config field's docstring redirecting to the corresponding logit processor docs;

This allows me to write a clear explanation and example (or examples) for each configuration option, without creating a monster in the generation config docstring. The user gets high-level info in the generation config docstring, and details in each processor.

The examples are more useful if they are relative to common use cases, in this case different `.generate()` parameterization. However, the example is sitting in the logit processor class, and does not make **direct** reference to the class. The alternative, to create an example using the class directly, is not very desirable either -- very few people use the logit processor classes directly. 

LMK if you have suggestions and/or if you agree 🤗 


@gante, the m4 eval code broke after this PR was merged:

```
stderr:   File "/mnt/nvme0/code/huggingface/m4-master-3/m4/evaluation/launch.py", line 143, in <module>
stderr:     main(args)
stderr:   File "/mnt/nvme0/code/huggingface/m4-master-3/m4/evaluation/launch.py", line 97, in main
stderr:     score = evaluator(task, accelerator, model, args)
stderr:   File "/mnt/nvme0/code/huggingface/m4-master-3/m4/evaluation/evaluators/in_contexter.py", line 262, in in_contexter
stderr:     metric = task.add_batch_metric(metric, **kwargs)
stderr:   File "/mnt/nvme0/code/huggingface/m4-master-3/m4/models/vgpt2/evaluation_open_ended_vqa_in_context_vgpt2.py", line 338, in add_batch_metric
stderr:     generated_tokens = self.generate_tokens(**kwargs)
stderr:   File "/mnt/nvme0/code/huggingface/m4-master-3/m4/models/vgpt2/evaluation_open_ended_vqa_in_context_vgpt2.py", line 314, in generate_tokens
stderr:     generated_tokens = unwrapped_model.generate(
stderr:   File "/home/stas/anaconda3/envs/py38-pt20/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
stderr:     return func(*args, **kwargs)
stderr:   File "/mnt/nvme0/code/huggingface/transformers-master/src/transformers/generation/utils.py", line 1627, in generate
stderr:     return self.beam_search(
stderr:   File "/mnt/nvme0/code/huggingface/transformers-master/src/transformers/generation/utils.py", line 2951, in beam_search
stderr:     next_token_scores_processed = logits_processor(input_ids, next_token_scores)
stderr:   File "/mnt/nvme0/code/huggingface/transformers-master/src/transformers/generation/logits_process.py", line 92, in __call__
stderr:     scores = processor(input_ids, scores)
stderr:   File "/mnt/nvme0/code/huggingface/transformers-master/src/transformers/generation/logits_process.py", line 618, in __call__
stderr:     self._prepare_bias_variables(scores)
stderr:   File "/mnt/nvme0/code/huggingface/transformers-master/src/transformers/generation/logits_process.py", line 678, in _prepare_bias_variables
stderr:     raise ValueError(
stderr: ValueError: Setting a bias on sequences that share a common token termination is not yet supported. Please open an issue if you see this error message (after checking that it doesn't already exist).
```

what should we change?

@stas00 interesting, I thought no relevant use case would hit this issue. I will open a PR with a fix!

(meanwhile, the solutions are either to a) downgrade transformers; or b) remove this exception if you're using the `bad_words_ids` generate argument, which should be fine)

Thank you, Joao

We are going to port the m4-pretrained model into `transformers` shortly, so neither of these proposals is an option in the long run.  But a PR with a fix is - it's not urgent urgent as we meanwhile can use the older transformers.