Some Whisper beam search output (sequences_scores, etc.) is lost in _stack_split_outputs
Author: drewhouston
Pull request: no
Labels: name: bug

name: Audio

### System Info

- `transformers` version: 4.43.3
- Platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.23.2
- Safetensors version: 0.4.3
- Accelerate version: 0.30.1
- Accelerate config:    not found
- PyTorch version (GPU?): 2.3.1+cu121 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: no
- Using GPU in script?: yes
- GPU type: NVIDIA GeForce RTX 4090 Laptop GPU


### Who can help?

@sanchit-gandhi @kamilakesbi 

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

In generating short form output (<30 sec):

```python
# inputs is from the processor
gen_kwargs = {
            "max_new_tokens": 400,
            "num_beams": 5,
            "temperature": None,
            "return_timestamps": False,
            "return_dict_in_generate": True,
            "num_return_sequences": 1,
            "output_scores": True,
            "language": "english"
        }
pred_ids = self.model.generate(inputs, **gen_kwargs)
print(pred_ids.__class__)
print(dict((k,type(v)) for k, v in vars(pred_ids).items()))
```



### Expected behavior

`GenerateBeamEncoderDecoderOutput` seems to lose some fields in a recent version. (Maybe other output forms are also affected, haven't checked.)

Bisecting transformers versions, in 4.42.4 the output looked like:       

> <class 'transformers.generation.utils.GenerateBeamEncoderDecoderOutput'>
> {'sequences': <class 'torch.Tensor'>, **'sequences_scores': <class 'torch.Tensor'>**, 'scores': <class 'tuple'>, 'logits': <class 'NoneType'>, **'beam_indices': <class 'torch.Tensor'>**, 'encoder_attentions': <class 'NoneType'>, 'encoder_hidden_states': <class 'NoneType'>, 'decoder_attentions': <class 'NoneType'>, 'cross_attentions': <class 'NoneType'>, 'decoder_hidden_states': <class 'NoneType'>, 'past_key_values': <class 'tuple'>}
> 


In 4.43.0 and after `sequences_scores` and `beam_indices` became `None`:

> <class 'transformers.generation.utils.GenerateBeamEncoderDecoderOutput'>
> {'sequences': <class 'torch.Tensor'>, **'sequences_scores': <class 'NoneType'>**, 'scores': <class 'tuple'>, 'logits': <class 'NoneType'>, **'beam_indices': <class 'NoneType'>**, 'encoder_attentions': <class 'NoneType'>, 'encoder_hidden_states': <class 'NoneType'>, 'decoder_attentions': <class 'NoneType'>, 'cross_attentions': <class 'NoneType'>, 'decoder_hidden_states': <class 'NoneType'>, 'past_key_values': <class 'tuple'>}


It looks like these get removed in postprocessing, potential culprit in `_stack_split_outputs` at https://github.com/huggingface/transformers/blob/9451a385261b30e7319a2c93285ab76161e8c003/src/transformers/models/whisper/generation_whisper.py#L946

Which looks like it changed in https://github.com/huggingface/transformers/pull/30984.

Hacking in `if key in ["sequences", "beam_indices", "sequences_scores"]:`, for example, fixes it, although I'm not sure what's intended to be handled as tensors vs. tuples, so will defer as to the best way to fix.


Comments:
(cc @sanchit-gandhi / @kamilakesbi , as this is a Whisper-specific question -- I've double-checked that the core `generate` is returning these additional outputs :) )

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.

cc @eustlb, another issue for your Whisper fixes 🙏 

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.

Hey @eustlb , saw your constant struggle to keep this issue open and from going stale . I felt like it was about time we closed this issue so worked on it a little bit and came up with #35921  . feel free to review it when you get the time . I'll eagerly await any comments that you might point out to me to resolve them as soon as possible . 

Also huge thanks to @drewhouston for opening this issue 🤗 

Hey, indeed this has been stagnating my TODOs. Thanks for tackling it, I'll review it ASAP!

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.