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 math as tl_math
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 8
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tl.store(in_out_ptr0 + x0, tmp3, xmask)


@triton.jit
def triton_poi_fused__softmax_2(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tmp0 - tmp0
    tmp2 = tl_math.exp(tmp1)
    tmp3 = tmp2 / tmp2
    tl.store(in_out_ptr0 + x0, tmp3, xmask)


@triton.jit
def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 8
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_mul_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + x0, xmask)
    tmp4 = tl.load(in_ptr2 + x0, xmask)
    tmp3 = tmp1 * tmp2
    tmp5 = tmp3 + tmp4
    tl.store(out_ptr0 + x0, tmp5, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, 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,
        primals_13, primals_14, primals_15, primals_16, primals_17,
        primals_18, primals_19, primals_20, primals_21, primals_22,
        primals_23, primals_24, primals_25) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (8, 4), (4, 1))
    assert_size_stride(primals_3, (8,), (1,))
    assert_size_stride(primals_4, (1, 8, 1), (8, 1, 1))
    assert_size_stride(primals_5, (1,), (1,))
    assert_size_stride(primals_6, (1, 8, 1), (8, 1, 1))
    assert_size_stride(primals_7, (1,), (1,))
    assert_size_stride(primals_8, (8, 8, 1), (8, 1, 1))
    assert_size_stride(primals_9, (8,), (1,))
    assert_size_stride(primals_10, (1,), (1,))
    assert_size_stride(primals_11, (8, 8), (8, 1))
    assert_size_stride(primals_12, (8,), (1,))
    assert_size_stride(primals_13, (1, 8, 1), (8, 1, 1))
    assert_size_stride(primals_14, (1,), (1,))
    assert_size_stride(primals_15, (1, 8, 1), (8, 1, 1))
    assert_size_stride(primals_16, (1,), (1,))
    assert_size_stride(primals_17, (8, 8, 1), (8, 1, 1))
    assert_size_stride(primals_18, (8,), (1,))
    assert_size_stride(primals_19, (1,), (1,))
    assert_size_stride(primals_20, (8, 8), (8, 1))
    assert_size_stride(primals_21, (8,), (1,))
    assert_size_stride(primals_22, (8, 8), (8, 1))
    assert_size_stride(primals_23, (8,), (1,))
    assert_size_stride(primals_24, (4, 8), (8, 1))
    assert_size_stride(primals_25, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 8),
            (1, 4), 0), out=buf0)
        del primals_2
        buf1 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_leaky_relu_0[grid(32)](buf0, primals_3, buf1, buf2,
            32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_3
        buf3 = extern_kernels.convolution(reinterpret_tensor(buf2, (4, 8, 1
            ), (8, 1, 0), 0), primals_4, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf3, (4, 1, 1), (1, 1, 1))
        buf4 = extern_kernels.convolution(reinterpret_tensor(buf2, (4, 8, 1
            ), (8, 1, 0), 0), primals_6, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf4, (4, 1, 1), (1, 1, 1))
        buf5 = buf3
        del buf3
        triton_poi_fused_convolution_1[grid(4)](buf5, primals_5, 4, XBLOCK=
            4, num_warps=1, num_stages=1)
        del primals_5
        buf6 = reinterpret_tensor(buf4, (4, 1, 1), (1, 4, 4), 0)
        del buf4
        triton_poi_fused_convolution_1[grid(4)](buf6, primals_7, 4, XBLOCK=
            4, num_warps=1, num_stages=1)
        del primals_7
        buf7 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf5, (4, 1, 1), (1, 0, 0), 0
            ), buf6, out=buf7)
        buf8 = buf7
        del buf7
        triton_poi_fused__softmax_2[grid(4)](buf8, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf9 = extern_kernels.convolution(reinterpret_tensor(buf2, (4, 8, 1
            ), (8, 1, 0), 0), primals_8, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf9, (4, 8, 1), (8, 1, 1))
        buf10 = reinterpret_tensor(buf9, (4, 8, 1), (8, 1, 32), 0)
        del buf9
        triton_poi_fused_convolution_3[grid(32)](buf10, primals_9, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        del primals_9
        buf11 = reinterpret_tensor(buf0, (4, 8, 1), (8, 1, 1), 0)
        del buf0
        extern_kernels.bmm(buf10, buf8, out=buf11)
        buf12 = empty_strided_cuda((4, 8, 1), (8, 1, 1), torch.float32)
        triton_poi_fused_add_mul_4[grid(32)](primals_10, buf11, buf2, buf12,
            32, XBLOCK=32, num_warps=1, num_stages=1)
        buf13 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf12, (4, 8), (8, 1), 0),
            reinterpret_tensor(primals_11, (8, 8), (1, 8), 0), out=buf13)
        buf14 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        buf15 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_leaky_relu_0[grid(32)](buf13, primals_12, buf14,
            buf15, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_12
        buf16 = extern_kernels.convolution(reinterpret_tensor(buf15, (4, 8,
            1), (8, 1, 0), 0), primals_13, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf16, (4, 1, 1), (1, 1, 1))
        buf17 = extern_kernels.convolution(reinterpret_tensor(buf15, (4, 8,
            1), (8, 1, 0), 0), primals_15, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf17, (4, 1, 1), (1, 1, 1))
        buf18 = buf16
        del buf16
        triton_poi_fused_convolution_1[grid(4)](buf18, primals_14, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        del primals_14
        buf19 = reinterpret_tensor(buf17, (4, 1, 1), (1, 4, 4), 0)
        del buf17
        triton_poi_fused_convolution_1[grid(4)](buf19, primals_16, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        del primals_16
        buf20 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf18, (4, 1, 1), (1, 0, 0), 
            0), buf19, out=buf20)
        buf21 = buf20
        del buf20
        triton_poi_fused__softmax_2[grid(4)](buf21, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf22 = extern_kernels.convolution(reinterpret_tensor(buf15, (4, 8,
            1), (8, 1, 0), 0), primals_17, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf22, (4, 8, 1), (8, 1, 1))
        buf23 = reinterpret_tensor(buf22, (4, 8, 1), (8, 1, 32), 0)
        del buf22
        triton_poi_fused_convolution_3[grid(32)](buf23, primals_18, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        del primals_18
        buf24 = reinterpret_tensor(buf13, (4, 8, 1), (8, 1, 1), 0)
        del buf13
        extern_kernels.bmm(buf23, buf21, out=buf24)
        buf25 = empty_strided_cuda((4, 8, 1), (8, 1, 1), torch.float32)
        triton_poi_fused_add_mul_4[grid(32)](primals_19, buf24, buf15,
            buf25, 32, XBLOCK=32, num_warps=1, num_stages=1)
        buf26 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf25, (4, 8), (8, 1), 0),
            reinterpret_tensor(primals_20, (8, 8), (1, 8), 0), out=buf26)
        buf27 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        buf28 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_leaky_relu_0[grid(32)](buf26, primals_21, buf27,
            buf28, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_21
        buf29 = buf26
        del buf26
        extern_kernels.mm(buf28, reinterpret_tensor(primals_22, (8, 8), (1,
            8), 0), out=buf29)
        buf30 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        buf31 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_leaky_relu_0[grid(32)](buf29, primals_23, buf30,
            buf31, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del buf29
        del primals_23
        buf32 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf31, reinterpret_tensor(primals_24, (8, 4), (1,
            8), 0), out=buf32)
        buf33 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf34 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_5[grid(16)](buf32, primals_25, buf33,
            buf34, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf32
        del primals_25
    return (buf34, primals_1, primals_4, primals_6, primals_8, primals_10,
        primals_13, primals_15, primals_17, primals_19, buf1,
        reinterpret_tensor(buf2, (4, 8, 1), (8, 1, 1), 0), buf8, buf11,
        reinterpret_tensor(buf12, (4, 8), (8, 1), 0), buf14,
        reinterpret_tensor(buf15, (4, 8, 1), (8, 1, 1), 0), buf21, buf24,
        reinterpret_tensor(buf25, (4, 8), (8, 1), 0), buf27, buf28, buf30,
        buf31, buf33, primals_24, primals_22, primals_20,
        reinterpret_tensor(buf23, (4, 1, 8), (8, 1, 1), 0), buf18,
        reinterpret_tensor(buf19, (4, 1, 1), (1, 1, 1), 0), primals_11,
        reinterpret_tensor(buf10, (4, 1, 8), (8, 1, 1), 0), buf5,
        reinterpret_tensor(buf6, (4, 1, 1), (1, 1, 1), 0))


class Self_Attn1D(nn.Module):
    """ Self attention Layer """

    def __init__(self, in_dim, activation, k=8):
        super(Self_Attn1D, self).__init__()
        self.chanel_in = in_dim
        self.activation = activation
        self.query_conv = nn.Conv1d(in_channels=in_dim, out_channels=in_dim //
            k, kernel_size=1)
        self.key_conv = nn.Conv1d(in_channels=in_dim, out_channels=in_dim //
            k, kernel_size=1)
        self.value_conv = nn.Conv1d(in_channels=in_dim, out_channels=in_dim,
            kernel_size=1)
        self.gamma = nn.Parameter(torch.zeros(1))
        self.softmax = nn.Softmax(dim=-1)

    def forward(self, x, return_attn=False):
        """
            inputs :
                x : input feature maps(B X C X T)
            returns :
                out : self attention value + input feature
                attention: B X N X N (N is Width*T)
        """
        B, C = x.size()
        T = 1
        x = x.view(B, C, T)
        proj_query = self.query_conv(x).view(B, -1, T).permute(0, 2, 1)
        proj_key = self.key_conv(x).view(B, -1, T)
        energy = torch.bmm(proj_query, proj_key)
        attention = self.softmax(energy)
        proj_value = self.value_conv(x).view(B, -1, T)
        out = torch.bmm(proj_value, attention.permute(0, 2, 1))
        out = out.view(B, C, T)
        out = self.gamma * out + x
        out = out.squeeze(2)
        return out, attention


class MlpWithAttentionNew(nn.Module):

    def __init__(self, in_dim, out_dim):
        super(MlpWithAttentionNew, self).__init__()
        out = max(8, in_dim * 2)
        self.input = nn.Linear(in_dim, out)
        self.output = nn.Linear(out, out_dim)
        self.fc = nn.Linear(out, out)
        self.fc2 = nn.Linear(out, out)
        self.fc3 = nn.Linear(out, out)
        self.attention = Self_Attn1D(out, nn.LeakyReLU)
        self.attention2 = Self_Attn1D(out, nn.LeakyReLU)
        self.relu = nn.LeakyReLU()

    def forward(self, input_0):
        primals_2 = self.input.weight
        primals_3 = self.input.bias
        primals_24 = self.output.weight
        primals_25 = self.output.bias
        primals_11 = self.fc.weight
        primals_9 = self.fc.bias
        primals_20 = self.fc2.weight
        primals_12 = self.fc2.bias
        primals_22 = self.fc3.weight
        primals_18 = self.fc3.bias
        primals_5 = self.attention.gamma
        primals_4 = self.attention.query_conv.weight
        primals_7 = self.attention.query_conv.bias
        primals_6 = self.attention.key_conv.weight
        primals_10 = self.attention.key_conv.bias
        primals_8 = self.attention.value_conv.weight
        primals_21 = self.attention.value_conv.bias
        primals_14 = self.attention2.gamma
        primals_13 = self.attention2.query_conv.weight
        primals_16 = self.attention2.query_conv.bias
        primals_15 = self.attention2.key_conv.weight
        primals_19 = self.attention2.key_conv.bias
        primals_17 = self.attention2.value_conv.weight
        primals_23 = self.attention2.value_conv.bias
        primals_1 = input_0
        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, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19,
            primals_20, primals_21, primals_22, primals_23, primals_24,
            primals_25])
        return output[0]


Measured latency_ms: 0.093681