Inference/prediction ValueError using BART
Author: PrijsDF
Pull request: no
Labels: name: bug

### System Info

```shell
- `transformers` version: 4.18.0
- Platform: Linux-4.19.0-19-cloud-amd64-x86_64-with-debian-10.12
- Python version: 3.7.12
- Huggingface_hub version: 0.5.1
- PyTorch version (GPU?): 1.11.0 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No
```


### Who can help?

@patil-suraj

### 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

```python
from transformers import BartForConditionalGeneration, BartTokenizerFast
from transformers import Seq2SeqTrainer, Seq2SeqTrainingArguments
from datasets import load_dataset

raw_dataset = load_dataset(path='parquet', data_files={
    'train': ['2021_1.parquet', '2021_2.parquet', '2021_3.parquet'], 
    'test': ['2021_4.parquet'
]})

model = BartForConditionalGeneration.from_pretrained("bart_nl_sum_17-04_15-50-23/checkpoints/checkpoint-10000")
tokenizer = BartTokenizerFast.from_pretrained("bart_nl_tiny_tz")

model_inputs = tokenizer(raw_dataset['train'][2]['description'], max_length=1024, return_tensors='pt', truncation=True) # padding=max_length

model_outputs = model.generate(
    inputs=model_inputs["input_ids"], 
    max_length=150, 
    min_length=40, 
    length_penalty=2.0, 
    num_beams=4, 
    early_stopping=True
)

print(tokenizer.decode(model_outputs[0]))
```

```python
Traceback (most recent call last):
  File "legalsum_inf.py", line 22, in <module>
    early_stopping=True
  File "/opt/conda/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/generation_utils.py", line 1325, in generate
    **model_kwargs,
  File "/opt/conda/lib/python3.7/site-packages/transformers/generation_utils.py", line 2162, in beam_search
    output_hidden_states=output_hidden_states,
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/models/bart/modeling_bart.py", line 1363, in forward
    return_dict=return_dict,
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/models/bart/modeling_bart.py", line 1224, in forward
    return_dict=return_dict,
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/models/bart/modeling_bart.py", line 793, in forward
    raise ValueError("You have to specify either input_ids or inputs_embeds")
ValueError: You have to specify either input_ids or inputs_embeds
```

### Expected behavior

```shell
I tried to summarize a text from my dataset using a custom fine-tuned BART model. To this end I followed the pytorch example listed at https://huggingface.co/docs/transformers/task_summary#summarization

This is the code that was used and the error that was shown. Any ideas what could be the problem here?
```


Comments:
What is the error here ?


> What is the error here ?

I actually forgot to include the error. I just added it :)

This just looks like a typo, the argument to `generate` is `input_ids` and `inputs`.

Hey @patil-suraj, thank you for your response.

I'm not entirely sure what you mean; I followed the exact implementation as shown here https://huggingface.co/docs/transformers/task_summary#summarization .

However, I just found out that I made a mistake during pretraining... Instead of pretraining for conditional generation, I trained on the CausalLM model. This lead to a model that was not an ecoder-decoder. I just re-pretrained a small model to see whether everything works fine and indeed it does!

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.