# Speech2Text transformer to ONNX conversion

**URL:** <https://discuss.huggingface.co/t/speech2text-transformer-to-onnx-conversion/7018>\
**Category:** 🤗Transformers\
**Created:** [June 20, 2021, 8:18pm UTC](https://discuss.huggingface.co/t/speech2text-transformer-to-onnx-conversion/7018 "2021-06-20T20:18:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gondiss](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gondiss](https://discuss.huggingface.co/u/gondiss)\
**Post date:** [June 20, 2021, 8:18pm UTC](https://discuss.huggingface.co/t/speech2text-transformer-to-onnx-conversion/7018/1 "2021-06-20T20:18:29Z")

</div>

Hi,  
While converting Speech2Text transformer type to onnx format I am running into this error:

RuntimeError: Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

Since onnx requires `forward` method to be defined , I defined forward method and calling model.generate in that method to make it use generate instead. May be this is not the right way to convert. I am not sure. Can some one shed the light on how to go about converting Speech2Text transformer model into ONNX format. I tried setting grad to false. But that didn’t help.
