# ValueError: Model requires 4 inputs. Input Feed contains 2 ONNX

**URL:** <https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497>\
**Category:** Beginners\
**Created:** [May 4, 2022, 4:48am UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497 "2022-05-04T04:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slcreator](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Slcreator](https://discuss.huggingface.co/u/Slcreator)\
**Post date:** [May 4, 2022, 4:48am UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497/1 "2022-05-04T04:48:50Z")

</div>

i try to export T5 model to ONNX but when a try to predict something it show a error:  
sess = ort.InferenceSession(‘onnx\model.onnx’)  
inputs = tokenizer(“something in here”, return\_tensors=“np”)  
outputs = sess.run( None,inputs )

> > ValueError: Model requires 4 inputs. Input Feed contains 2

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [May 4, 2022, 12:11pm UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497/2 "2022-05-04T12:11:54Z")

</div>

Maybe @lewtun will have an idea?

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](https://discuss.huggingface.co/u/lewtun)\
**Post date:** [May 4, 2022, 12:31pm UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497/3 "2022-05-04T12:31:50Z")

</div>

Hey @Slcreator the number of inputs you need for inference depends on the type of head you chose to export the model with (i.e. the `feature` arg in the `transformers.onnx` package).

For example, here’s how you can figure out which inputs are needed for say the `default` feature of a T5 checkpoint:

```python
from transformers.models.t5 import T5Config, T5OnnxConfig

config = T5Config.from_pretrained("t5-small")
onnx_config = T5OnnxConfig(config=config, task="default")
# returns
# {'input_ids': {0: 'batch', 1: 'encoder_sequence'},
# 'attention_mask': {0: 'batch', 1: 'encoder_sequence'},
# 'decoder_input_ids': {0: 'batch', 1: 'decoder_sequence'},
# 'decoder_attention_mask': {0: 'batch', 1: 'decoder_sequence'}}
onnx_config.inputs

```

You can change the `task` arg to match the type of head you’re exporting and that will tell you what the model expects as inputs.

Btw we’ve recently added a `pipeline()` function to the `optimum` library, which makes it quite simple to run inference on ONNX Runtime. There’s a guide here if you’re interested: [Optimum pipelines for inference](https://huggingface.co/docs/optimum/main/en/pipelines)

---

<div class="post-metadata">

**Author:** ![Slcreator](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Slcreator](https://discuss.huggingface.co/u/Slcreator)\
**Post date:** [May 5, 2022, 2:22am UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497/4 "2022-05-05T02:22:40Z")

</div>

thanks very much, i’m going to check it again

---

<div class="post-metadata">

**Author:** ![harinderncnvrg](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/harinderncnvrg/32/13752_2.png) [@harinderncnvrg](https://discuss.huggingface.co/u/harinderncnvrg)\
**Post date:** [January 24, 2023, 12:13pm UTC](https://discuss.huggingface.co/t/valueerror-model-requires-4-inputs-input-feed-contains-2-onnx/17497/5 "2023-01-24T12:13:04Z")

</div>

Hello, I am trying to use Bigbirdpegasus and getting the same error. Model requires 4 inputs but how can we provide decoder attention and mask beforehand? isn’t that supposed to be generated after we get output from the model?  
Can you please share the code to export bigbird for summarization?  
Here is the code I am using:

> _from pathlib import Path_  
> _from transformers.onnx import export_  
> _from transformers import AutoTokenizer, AutoModel_
> 
> _onnx\_path = Path(“model.onnx”)_  
> _model\_ckpt = “google/bigbird-pegasus-large-pubmed”_  
> _base\_model = AutoModel.from\_pretrained(model\_ckpt)_  
> _tokenizer = AutoTokenizer.from\_pretrained(model\_ckpt)_  
> _onnx\_inputs, onnx\_outputs = export(tokenizer, base\_model, onnx\_config, onnx\_config.default\_onnx\_opset, onnx\_path)_  
> _tokenizer = AutoTokenizer.from\_pretrained(“google/bigbird-pegasus-large-pubmed”)_  
> _session = InferenceSession(“model.onnx”)_  
> _inputs = tokenizer(“Summarize this text”, return\_tensors=“np”)_  
> _inputs = {k: v.astype(np.int64) for k, v in inputs.items()}_  
> _outputs = session.run(output\_names=[“last\_hidden\_state”], input\_feed=inputs)_
