{
  "id": 420825,
  "title": "ONNX can't convert sum of tensors",
  "url": "/competitions/asl-fingerspelling/discussion/420825",
  "author_name": "Vadim Irtlach",
  "post_date": "2023-07-02T18:49:24.491000",
  "votes": 1,
  "comment_count": 1,
  "views": 0,
  "content": "<p>I am trying to convert <code>nn.TransformerEncoderLayer</code> into ONNX format, however, I am getting exception after applying the sum operation.</p>\n<p>Code:</p>\n<pre><code>normed_x = self.norm1(x)\nsa_x = self._sa_block(normed_x, src_mask, src_key_padding_mask, is_causal=is_causal)\nx = x + sa_x \n</code></pre>\n<p>Traceback:</p>\n<pre><code> Exporting the  \n</code></pre>\n<p>Paradox is that my other model can be easily converted using almost the same order of operations. Did anyone succeed in converting such operations? Thank you! </p>\n<p>P.S. I am not a big fan of such discussions, but I hadn't found any working solutions, so I will be very grateful for the help from the Kaggle Community! </p>",
  "messages": [
    {
      "id": 2327241,
      "postDate": "2023-07-02T18:49:24.490Z",
      "content": "<p>I am trying to convert <code>nn.TransformerEncoderLayer</code> into ONNX format, however, I am getting exception after applying the sum operation.</p>\n<p>Code:</p>\n<pre><code>normed_x = self.norm1(x)\nsa_x = self._sa_block(normed_x, src_mask, src_key_padding_mask, is_causal=is_causal)\nx = x + sa_x \n</code></pre>\n<p>Traceback:</p>\n<pre><code> Exporting the  \n</code></pre>\n<p>Paradox is that my other model can be easily converted using almost the same order of operations. Did anyone succeed in converting such operations? Thank you! </p>\n<p>P.S. I am not a big fan of such discussions, but I hadn't found any working solutions, so I will be very grateful for the help from the Kaggle Community! </p>",
      "rawMarkdown": "I am trying to convert `nn.TransformerEncoderLayer` into ONNX format, however, I am getting exception after applying the sum operation.\n\nCode:\n```py\nnormed_x = self.norm1(x)\nsa_x = self._sa_block(normed_x, src_mask, src_key_padding_mask, is_causal=is_causal)\nx = x + sa_x # Here is the exception\n```\nTraceback:\n```\nUnsupportedOperatorError: Exporting the operator 'aten::unflatten' to ONNX opset version 15 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues.\n```\n\nParadox is that my other model can be easily converted using almost the same order of operations. Did anyone succeed in converting such operations? Thank you! \n\nP.S. I am not a big fan of such discussions, but I hadn't found any working solutions, so I will be very grateful for the help from the Kaggle Community! ",
      "votes": 1
    },
    {
      "id": 2333085,
      "postDate": "2023-07-06T16:30:12.373Z",
      "content": "<p>You might want to change the flattening to simple reshaping. It might work..</p>",
      "rawMarkdown": "You might want to change the flattening to simple reshaping. It might work.."
    }
  ],
  "comments": [
    {
      "id": 2333085,
      "author_name": "The Devastator",
      "author_url": "",
      "post_date": "2023-07-06T16:30:12.373000",
      "content": "<p>You might want to change the flattening to simple reshaping. It might work..</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2327241": "I am trying to convert `nn.TransformerEncoderLayer` into ONNX format, however, I am getting exception after applying the sum operation.\n\nCode:\n```py\nnormed_x = self.norm1(x)\nsa_x = self._sa_block(normed_x, src_mask, src_key_padding_mask, is_causal=is_causal)\nx = x + sa_x # Here is the exception\n```\nTraceback:\n```\nUnsupportedOperatorError: Exporting the operator 'aten::unflatten' to ONNX opset version 15 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues.\n```\n\nParadox is that my other model can be easily converted using almost the same order of operations. Did anyone succeed in converting such operations? Thank you! \n\nP.S. I am not a big fan of such discussions, but I hadn't found any working solutions, so I will be very grateful for the help from the Kaggle Community! ",
    "2333085": "You might want to change the flattening to simple reshaping. It might work.."
  }
}