import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.autograd
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 5
    x1 = xindex // 5
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = 0.5
    tmp7 = tmp5 * tmp6
    tmp8 = 0.7071067811865476
    tmp9 = tmp5 * tmp8
    tmp10 = libdevice.erf(tmp9)
    tmp11 = 1.0
    tmp12 = tmp10 + tmp11
    tmp13 = tmp7 * tmp12
    tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
    tmp15 = tl.where(tmp4, tmp13, tmp14)
    tmp16 = tmp0 >= tmp3
    tl.full([1], 5, tl.int64)
    tmp19 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp20 = tl.where(tmp16, tmp11, tmp19)
    tmp21 = tl.where(tmp4, tmp15, tmp20)
    tl.store(out_ptr0 + x2, tmp21, xmask)


@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 100
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 5
    x1 = xindex // 5 % 4
    x2 = xindex // 20
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 5 * x2 + 25 * x1), xmask)
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 20
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex % 4
    x3 = xindex // 4
    y0 = yindex % 5
    y1 = yindex // 5
    x5 = xindex
    y4 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 5 * x3 + 20 * x2 + 80 * y1), xmask &
        ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x5 + 16 * y4), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_gelu_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 0.5
    tmp2 = tmp0 * tmp1
    tmp3 = 0.7071067811865476
    tmp4 = tmp0 * tmp3
    tmp5 = libdevice.erf(tmp4)
    tmp6 = 1.0
    tmp7 = tmp5 + tmp6
    tmp8 = tmp2 * tmp7
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_poi_fused_add_4(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x4 = xindex
    x0 = xindex % 4
    x5 = xindex // 4 % 16
    x1 = xindex // 4 % 4
    tmp0 = tl.load(in_out_ptr0 + x4, xmask)
    tmp1 = tl.load(in_ptr0 + (x5 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 + tmp3
    tl.store(in_out_ptr0 + x4, tmp4, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
        ) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 5, 5), (25, 5, 1))
    assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_9, (4, 4), (4, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf0)
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_6, reinterpret_tensor(primals_4, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf1)
        del primals_5
        del primals_6
        buf2 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(80)](buf0, buf2, 80, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((5, 4, 1, 5, 1, 1), (20, 5, 5, 1, 1, 1),
            torch.float32)
        triton_poi_fused_clone_1[grid(100)](primals_7, buf3, 100, XBLOCK=
            128, num_warps=4, num_stages=1)
        del primals_7
        buf4 = empty_strided_cuda((1, 16, 20), (320, 20, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf2, (1, 16, 5), (0, 5, 1), 
            0), reinterpret_tensor(buf3, (1, 5, 20), (0, 20, 1), 0), out=buf4)
        buf5 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32)
        triton_poi_fused_cat_0[grid(80)](buf1, buf5, 80, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((4, 5, 4, 4, 1, 1), (80, 16, 4, 1, 1, 1),
            torch.float32)
        triton_poi_fused_clone_2[grid(20, 16)](buf4, buf6, 20, 16, XBLOCK=
            16, YBLOCK=32, num_warps=4, num_stages=1)
        del buf4
        buf7 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
        extern_kernels.bmm(buf5, reinterpret_tensor(buf6, (4, 5, 16), (80, 
            16, 1), 0), out=buf7)
        buf8 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_10, reinterpret_tensor(primals_8, (16,
            4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf8)
        del primals_10
        del primals_9
        buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_gelu_3[grid(64)](buf8, buf9, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf9, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf10)
        buf11 = reinterpret_tensor(buf7, (4, 4, 4, 4), (64, 1, 16, 4), 0)
        del buf7
        triton_poi_fused_add_4[grid(256)](buf11, buf10, primals_12, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del buf10
        del primals_12
    return buf11, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
        ), buf0, reinterpret_tensor(primals_4, (16, 4), (4, 1), 0
        ), buf1, reinterpret_tensor(primals_8, (16, 4), (4, 1), 0
        ), buf8, reinterpret_tensor(buf9, (16, 4), (4, 1), 0
        ), primals_11, reinterpret_tensor(buf5, (4, 5, 4), (20, 1, 5), 0
        ), reinterpret_tensor(buf6, (4, 16, 5), (80, 1, 16), 0
        ), reinterpret_tensor(buf2, (1, 5, 16), (80, 1, 5), 0
        ), reinterpret_tensor(buf3, (1, 20, 5), (100, 1, 20), 0)


class Biaffine(nn.Module):

    def __init__(self, n_in, n_out=1, bias_x=True, bias_y=True):
        super(Biaffine, self).__init__()
        self.n_in = n_in
        self.n_out = n_out
        self.bias_x = bias_x
        self.bias_y = bias_y
        weight = torch.zeros((n_out, n_in + int(bias_x), n_in + int(bias_y)))
        nn.init.xavier_normal_(weight)
        self.weight = nn.Parameter(weight, requires_grad=True)

    def extra_repr(self):
        s = f'n_in={self.n_in}, n_out={self.n_out}'
        if self.bias_x:
            s += f', bias_x={self.bias_x}'
        if self.bias_y:
            s += f', bias_y={self.bias_y}'
        return s

    def forward(self, x, y):
        if self.bias_x:
            x = torch.cat((x, torch.ones_like(x[..., :1])), -1)
        if self.bias_y:
            y = torch.cat((y, torch.ones_like(y[..., :1])), -1)
        s = torch.einsum('bxi,oij,byj->boxy', x, self.weight, y)
        s = s.permute(0, 2, 3, 1)
        return s


class MLP(nn.Module):

    def __init__(self, n_in, n_out, dropout=0):
        super().__init__()
        self.linear = nn.Linear(n_in, n_out)
        self.activation = nn.GELU()
        self.dropout = nn.Dropout(dropout)

    def forward(self, x):
        x = self.dropout(x)
        x = self.linear(x)
        x = self.activation(x)
        return x


class CoPredictorNew(nn.Module):

    def __init__(self, cls_num, hid_size, biaffine_size, channels,
        ffnn_hid_size, dropout=0):
        super().__init__()
        self.mlp1 = MLP(n_in=hid_size, n_out=biaffine_size, dropout=dropout)
        self.mlp2 = MLP(n_in=hid_size, n_out=biaffine_size, dropout=dropout)
        self.biaffine = Biaffine(n_in=biaffine_size, n_out=cls_num, bias_x=
            True, bias_y=True)
        self.mlp_rel = MLP(channels, ffnn_hid_size, dropout=dropout)
        self.linear = nn.Linear(ffnn_hid_size, cls_num)
        self.dropout = nn.Dropout(dropout)

    def forward(self, input_0, input_1, input_2):
        primals_2 = self.mlp1.linear.weight
        primals_3 = self.mlp1.linear.bias
        primals_5 = self.mlp2.linear.weight
        primals_6 = self.mlp2.linear.bias
        primals_7 = self.biaffine.weight
        primals_9 = self.mlp_rel.linear.weight
        primals_10 = self.mlp_rel.linear.bias
        primals_11 = self.linear.weight
        primals_12 = self.linear.bias
        primals_1 = input_0
        primals_4 = input_1
        primals_8 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12])
        return output[0]


Measured latency_ms: 0.023662