<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>

<p dir="auto">RuntimeError: Exporting the operator triu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<ol dir="auto">
<li>highly depended on my code, so difficult to show reproduce</li>
</ol>

<h2 dir="auto">Expected behavior</h2>

<h2 dir="auto">Environment</h2>
<p dir="auto">Please copy and paste the output from our<br>
<a href="https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py" rel="nofollow">environment collection script</a><br>
(or fill out the checklist below manually).</p>
<p dir="auto">You can get the script and run it with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py"><pre class="notranslate"><code class="notranslate">wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
</code></pre></div>
<ul dir="auto">
<li>PyTorch Version (e.g., 1.6):</li>
<li>OS (e.g., Linux ubuntu.18.0.4):</li>
<li>How you installed PyTorch (pip):</li>
<li>Build command you used (if compiling from source):</li>
<li>Python version:3.7.8</li>
<li>CUDA/cuDNN version: cuda-10.1 cudnn-7</li>
<li>GPU models and configuration: GTX1050</li>
<li>Any other relevant information:</li>
</ul>
<h2 dir="auto">Additional context</h2>
<p dir="auto">Models that contain torch.triu can not be converted to ONNX.</p>
<p dir="auto">Error message:</p>
<blockquote>
<p dir="auto">UserWarning: ONNX export failed on ATen operator triu because torch.onnx.symbolic_opset9.triu does not exist</p>
</blockquote>
<p dir="auto">Simple reproducer is here.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
import torch.nn as nn

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(10, 10, 3, padding=1, bias=False)

    def forward(self, x):
        x = self.conv(x)
        mask = torch.triu(torch.ones_like(x))
        x = x * mask
        return x

model = SimpleModel()
var = torch.ones(1, 10, 120, 120)

torch.onnx.export(
    model,
    (var,),
    &quot;simple_model.onnx&quot;,
    input_names=[&quot;x&quot;],
    output_names=[&quot;out&quot;]
)"><pre class="notranslate"><code class="notranslate">import torch
import torch.nn as nn

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(10, 10, 3, padding=1, bias=False)

    def forward(self, x):
        x = self.conv(x)
        mask = torch.triu(torch.ones_like(x))
        x = x * mask
        return x

model = SimpleModel()
var = torch.ones(1, 10, 120, 120)

torch.onnx.export(
    model,
    (var,),
    "simple_model.onnx",
    input_names=["x"],
    output_names=["out"]
)
</code></pre></div>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/houseroad/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/houseroad">@houseroad</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/spandantiwari/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/spandantiwari">@spandantiwari</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/lara-hdr/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/lara-hdr">@lara-hdr</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/BowenBao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/BowenBao">@BowenBao</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/neginraoof/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/neginraoof">@neginraoof</a></p>