# Export a BetterTransformer to ONNX

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578%3E%5C
**Category:** 🤗Optimum\
**Created:** [May 3, 2023, 5:51pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578 "2023-05-03T17:51:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfangish](https://avatars.discourse-cdn.com/v4/letter/d/d6d6ee/32.png) [@dfangish](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdfangish)%5C
**Post date:** [May 3, 2023, 5:51pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578%2F1 "2023-05-03T17:51:24Z")

</div>

Hi,

I wonder if it’s possible to export a BetterTransformer to ONNX in order to take advantage of the optimizations done by both. I gave it a shot and I encountered the below error:

`UnsupportedOperatorError: Exporting the operator 'aten::_nested_tensor_from_mask' to ONNX opset version 13 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues`

seems that there aren’t a lot of discussions on the internet and thus I wanted to post a question here. Thanks!

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [May 15, 2023, 12:13pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578%2F2 "2023-05-15T12:13:13Z")

</div>

Hi @dfangish, here is the list of ONNX-supported ATen operators: [ONNX supported TorchScript operators — PyTorch 2.0 documentation](https://pytorch.org/docs/stable/onnx_supported_aten_ops.html)

Searching this page for `_nested_tensor_from_mask` shows that it is not supported yet (same for `_transformer_encoder_layer_fwd` which would also be needed).

They provide a small guide if you would like to add support for these operators: [torch.onnx — PyTorch 2.0 documentation](https://pytorch.org/docs/stable/onnx.html#adding-support-for-an-aten-or-quantized-operator)

---

<div class="post-metadata">

**Author:** ![EmreOzkose](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/emreozkose/32/18399_2.png) [@EmreOzkose](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FEmreOzkose)%5C
**Post date:** [August 9, 2023, 11:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578%2F3 "2023-08-09T11:40:11Z")

</div>

Hi @dfangish , I am facing the same. Did you solve this issue (writing custom op, etc…) ?

---

<div class="post-metadata">

**Author:** ![fxmarty](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/fxmarty/32/23782_2.png) [@fxmarty](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffxmarty)%5C
**Post date:** [August 11, 2023, 3:15pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexport-a-bettertransformer-to-onnx%2F38578%2F4 "2023-08-11T15:15:57Z")

</div>

Hi @dfangish @EmreOzkose , this is unfortunately not possible. BetterTransformer relies on optimizations from PyTorch through custom CUDA kernels, which can not be exported to ONNX.
