<p>Pegasus is a <a href="https://arxiv.org/abs/1409.3215" rel="noreferrer"><code>seq2seq</code></a> model, you can't directly convert a <code>seq2seq</code> model (encoder-decoder model) using this method. The <a href="https://colab.research.google.com/github/huggingface/transformers/blob/master/notebooks/04-onnx-export.ipynb#scrollTo=foYlXrSksR_v" rel="noreferrer"><code>guide</code></a> is for BERT which is an encoder model. Any only encoder or only decoder transformer model can be converted using this method.</p>
<p>To convert a <code>seq2seq</code> model (encoder-decoder) you have to split them and convert them separately, an encoder to onnx and a decoder to onnx. you can follow <a href="https://github.com/Ki6an/fastT5/blob/8dda859086af631a10ad210a5f1afdec64d49616/fastT5/onnx_exporter.py#L45" rel="noreferrer">this guide</a> (it was done for T5 which is also a <code>seq2seq</code> model)</p>
<p><strong>Why are you getting this error?</strong></p>
<p>while converting <a href="https://pytorch.org/docs/stable/onnx.html?highlight=onnx%20export#functions" rel="noreferrer">PyTorch to onnx</a></p>
<pre><code>_ = torch.onnx._export(
                        model,
                        dummy_input,
                        ...
                       )
</code></pre>
<p>you need to provide a dummy variable to both encoder and to the decoder <a href="https://github.com/huggingface/transformers/issues/8923#issuecomment-738811521" rel="noreferrer">separately</a>. by default when converting using this method it provides the encoder the dummy variable. Since this method of conversion didn't accept decoder of this seq2seq model, it won't give a dummy variable to the decoder and you get the above error.
<code>ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds</code></p>
how to convert HuggingFace's Seq2seq models to onnx format
<p>I am trying to convert the Pegasus newsroom in HuggingFace's transformers model to the ONNX format. I followed <a href="https://colab.research.google.com/github/huggingface/transformers/blob/master/notebooks/04-onnx-export.ipynb#scrollTo=foYlXrSksR_v" rel="nofollow noreferrer">this</a> guide published by Huggingface. After installing the prereqs, I ran this code:</p>
<pre><code>!rm -rf onnx/
from pathlib import Path
from transformers.convert_graph_to_onnx import convert

convert(framework=&quot;pt&quot;, model=&quot;google/pegasus-newsroom&quot;, output=Path(&quot;onnx/google/pegasus-newsroom.onnx&quot;), opset=11)

</code></pre>
<p>and got these errors:</p>
<pre><code>ValueError                                Traceback (most recent call last)
&lt;ipython-input-9-3b37ed1ceda5&gt; in &lt;module&gt;()
      3 from transformers.convert_graph_to_onnx import convert
      4 
----&gt; 5 convert(framework=&quot;pt&quot;, model=&quot;google/pegasus-newsroom&quot;, output=Path(&quot;onnx/google/pegasus-newsroom.onnx&quot;), opset=11)
      6 
      7 

6 frames
/usr/local/lib/python3.6/dist-packages/transformers/models/pegasus/modeling_pegasus.py in forward(self, input_ids, attention_mask, encoder_hidden_states, encoder_attention_mask, head_mask, encoder_head_mask, past_key_values, inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict)
    938             input_shape = inputs_embeds.size()[:-1]
    939         else:
--&gt; 940             raise ValueError(&quot;You have to specify either decoder_input_ids or decoder_inputs_embeds&quot;)
    941 
    942         # past_key_values_length

ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds

</code></pre>
<p>I have never seen this error before. Any ideas?</p>