Bark logits_warper(...) 'list' object not calllable while sampling
Author: Colt-Zero
Pull request: no

### System Info

transformers 4.36.2, ubuntu 20.04, python 3.10

### Who can help?

@sanchit-gandhi

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

1. Import transformers pipeline
2. Setup Bark pipeline and processor:
```
isSmall = "" if isV2 else "-small"
synthesiser = pipeline("text-to-speech", f"suno/bark{isSmall}", torch_dtype=torch.float16, framework="pt", device=torch.device(params["mode"]))
if better_transformer:
  synthesiser.model =  synthesiser.model.to_bettertransformer()
if cpu_offload:
  synthesiser.model.enable_cpu_offload()
processor = AutoProcessor.from_pretrained(f"suno/bark{isSmall}")
tts = (synthesiser, processor)
```
3. Inference Bark:
```
synthesiser, processor = tts
inputs = processor(text, voice_preset="v2/en_speaker_6").to(params["mode"])
forward_params = { "history_prompt": inputs["history_prompt"], "num_beams":6, "do_sample":True }
speech_output = synthesiser(turn, forward_params=forward_params)
audio_data = speech_output["audio"]
sampling_rate = speech_output["sampling_rate"]
```

The code seems to work fine up until `speech_output = synthesiser(text, forward_params=forward_params)`
Where it gets the error:
```
  Traceback (most recent call last):
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/routes.py", line 427, in run_predict
    output = await app.get_blocks().process_api(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/blocks.py", line 1067, in call_function
    prediction = await utils.async_iteration(iterator)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/utils.py", line 336, in async_iteration
    return await iterator.__anext__()
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/utils.py", line 329, in __anext__
    return await anyio.to_thread.run_sync(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2106, in run_sync_in_worker_thread
    return await future
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 833, in run
    result = context.run(func, *args)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/gradio/utils.py", line 312, in run_sync_iterator_async
    return next(iterator)
  File "/storage/OngoingWork/Llama-2-13b/text-generation-webui/extensions/history_extension_applier/script.py", line 213, in apply_to_history
    new_lines[line_ind%2] = apply_extensions(settings['ext_mode'], history[processed_history][line_ind//2][line_ind%2], gradio('interface_state'), is_chat=True)
  File "/storage/OngoingWork/Llama-2-13b/text-generation-webui/extensions/history_extension_applier/script.py", line 194, in apply_extensions
    return EXTENSION_MAP[typ](*args, **kwargs)
  File "/storage/OngoingWork/Llama-2-13b/text-generation-webui/extensions/history_extension_applier/script.py", line 47, in _apply_string_extensions
    text = func(*args, **kwargs)
  File "/storage/OngoingWork/Llama-2-13b/text-generation-webui/extensions/text_generation_webui_xtts/script.py", line 502, in output_modifier
    return tts_char(string)
  File "/storage/OngoingWork/Llama-2-13b/text-generation-webui/extensions/text_generation_webui_xtts/script.py", line 358, in tts_char
    speech_output = model(text, forward_params=forward_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/pipelines/text_to_audio.py", line 182, in __call__
    return super().__call__(text_inputs, **forward_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/pipelines/base.py", line 1140, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/pipelines/base.py", line 1147, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/pipelines/base.py", line 1046, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/pipelines/text_to_audio.py", line 143, in _forward
    output = self.model.generate(**model_inputs, **forward_params)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/models/bark/modeling_bark.py", line 1821, in generate
    semantic_output = self.semantic.generate(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/models/bark/modeling_bark.py", line 1008, in generate
    semantic_output = super().generate(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/generation/utils.py", line 1834, in generate
    return self.beam_sample(
  File "/storage/OngoingWork/Llama-2-13b/installer_files/env/lib/python3.10/site-packages/transformers/generation/utils.py", line 3533, in beam_sample
    next_token_scores_processed = logits_warper(input_ids, next_token_scores_processed)
TypeError: 'list' object is not callable
```


### Expected behavior

I'm expecting it to be able to be able to properly perform a sampling inference operation with the bark model, but it fails no matter what I've tried.

And that includes:
No history prompt.
No beam sampling (so just normal sampling).
I've tried the BarkModel/AutoModel class with a manual call to generate, but I run into the same error.

I'm really not sure what's going wrong here.
It's supposed to be treating the logits_warper as a LogitsProcessorList retrieved via GenerationMixin._get_logits_warper(...) but it seems to sometimes regard it as a normal list instead.

Help would be appreciated.

Comments:
I managed to solve my own problem by editing `transformers/generation/utils.py` to reconstruct the logits_warper lists within the function it's called like this:
```
def beam_sample:
...
logits_warper = LogitsProcessorList(logits_warper)
...

def sample:
...
logits_warper = LogitsProcessorList(logits_warper)
...
```
I don't understand why this was necessary. It doesn't make any sense to me.

cc @ylacombe 🙌

Hey @Colt-Zero, thanks for opening this issue, I don't seem to be able to reproduce the bug with the following code:
```python
from transformers import AutoProcessor, pipeline
import torch

processor = AutoProcessor.from_pretrained("suno/bark")
synthesiser = pipeline("text-to-speech", "suno/bark", torch_dtype=torch.float16, device=0)

inputs = processor("hey gen", voice_preset="v2/en_speaker_6").to("cuda")

forward_params = { "history_prompt": inputs["history_prompt"], "num_beams":6, "do_sample":True}


speech_output = synthesiser("hey gen", forward_params=forward_params)
audio_data = speech_output["audio"]
sampling_rate = speech_output["sampling_rate"]
```
Let me know if that's help

Can you send a full end-to-end script to reproduce the issue ?
Many thanks


This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.