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 import nn
import torch.distributed
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, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    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 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x2, tmp10, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    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
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    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).to(tl.int1)
    tmp6 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp8 = tmp6 + tmp7
    tmp9 = 0.01
    tmp10 = tmp8 * tmp9
    tmp11 = tl.where(tmp5, tmp8, tmp10)
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp17 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp18 = tl.where(tmp4, tmp13, tmp17)
    tl.store(out_ptr0 + x2, tmp18, xmask)


@triton.jit
def triton_poi_fused_add_leaky_relu_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x2, xmask).to(tl.int1)
    tmp4 = tl.load(in_ptr3 + x2, xmask)
    tmp5 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp6 = tmp4 + tmp5
    tmp7 = 0.01
    tmp8 = tmp6 * tmp7
    tmp9 = tl.where(tmp3, tmp6, tmp8)
    tmp10 = tmp2 + tmp9
    tl.store(out_ptr0 + (x0 + 8 * x1), tmp10, xmask)


@triton.jit
def triton_poi_fused_cat_4(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tl.store(out_ptr0 + (x0 + 8 * x1), tmp0, xmask)
    tl.store(out_ptr1 + (x0 + 8 * x1), tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    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 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.load(in_ptr2 + (8 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp9 = tmp7 + tmp8
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp4, tmp9, tmp10)
    tmp12 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp15 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp12 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp16 = tl.where(tmp4, tmp11, tmp15)
    tl.store(out_ptr0 + x2, tmp16, xmask)


@triton.jit
def triton_poi_fused_add_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x2, xmask)
    tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr4 + (x0 + 8 * x1), xmask)
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp2 + tmp7
    tl.store(out_ptr0 + (x0 + 8 * x1), tmp8, 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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4, 8), (8, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 8), (8, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 8), (8, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 8), (8, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 8), (8, 1))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4, 8), (8, 1))
    assert_size_stride(primals_14, (4,), (1,))
    assert_size_stride(primals_15, (4, 8), (8, 1))
    assert_size_stride(primals_16, (4,), (1,))
    assert_size_stride(primals_17, (4, 8), (8, 1))
    assert_size_stride(primals_18, (4,), (1,))
    assert_size_stride(primals_19, (4, 8), (8, 1))
    assert_size_stride(primals_20, (4,), (1,))
    assert_size_stride(primals_21, (4, 8), (8, 1))
    assert_size_stride(primals_22, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(128)](primals_1, primals_2, buf0, 128,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf1)
        del primals_3
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_1[grid(64)](buf1, primals_4, buf2, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(128)](buf2, buf1, primals_4, primals_2,
            buf3, 128, XBLOCK=128, num_warps=4, num_stages=1)
        buf4 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf3, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), out=buf4)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_1[grid(64)](buf4, primals_6, buf5, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(128)](buf5, buf4, primals_6, primals_2,
            buf6, 128, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_6
        buf7 = buf4
        del buf4
        extern_kernels.mm(reinterpret_tensor(buf6, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_7, (8, 4), (1, 8), 0), out=buf7)
        buf10 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        buf8 = reinterpret_tensor(buf10, (4, 4, 4), (32, 8, 1), 0)
        triton_poi_fused_add_leaky_relu_3[grid(64)](buf7, primals_8, buf2,
            buf1, primals_4, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_4
        del primals_8
        buf9 = reinterpret_tensor(buf10, (4, 4, 4), (32, 8, 1), 4)
        buf22 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        buf21 = reinterpret_tensor(buf22, (4, 4, 4), (32, 8, 1), 4)
        triton_poi_fused_cat_4[grid(64)](primals_2, buf9, buf21, 64, XBLOCK
            =64, num_warps=1, num_stages=1)
        buf11 = buf7
        del buf7
        extern_kernels.mm(reinterpret_tensor(buf10, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_9, (8, 4), (1, 8), 0), out=buf11)
        buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_1[grid(64)](buf11, primals_10, buf12, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf13 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(128)](buf12, buf11, primals_10,
            primals_2, buf13, 128, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_10
        buf14 = buf11
        del buf11
        extern_kernels.mm(reinterpret_tensor(buf13, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf14)
        buf15 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_5[grid(128)](buf14, primals_12, buf8,
            primals_2, buf15, 128, XBLOCK=128, num_warps=4, num_stages=1)
        buf16 = buf1
        del buf1
        extern_kernels.mm(reinterpret_tensor(buf15, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf16)
        buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_1[grid(64)](buf16, primals_14, buf17, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf18 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(128)](buf17, buf16, primals_14,
            primals_2, buf18, 128, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_14
        buf19 = buf16
        del buf16
        extern_kernels.mm(reinterpret_tensor(buf18, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf19)
        buf20 = reinterpret_tensor(buf22, (4, 4, 4), (32, 8, 1), 0)
        triton_poi_fused_add_6[grid(64)](buf19, primals_16, buf14,
            primals_12, buf8, buf20, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf14
        del primals_12
        del primals_16
        buf23 = buf19
        del buf19
        extern_kernels.mm(reinterpret_tensor(buf22, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf23)
        buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_1[grid(64)](buf23, primals_18, buf24, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf25 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(128)](buf24, buf23, primals_18,
            primals_2, buf25, 128, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_18
        buf26 = buf23
        del buf23
        extern_kernels.mm(reinterpret_tensor(buf25, (16, 8), (8, 1), 0),
            reinterpret_tensor(primals_19, (8, 4), (1, 8), 0), out=buf26)
        buf27 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_5[grid(128)](buf26, primals_20, buf20,
            primals_2, buf27, 128, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_2
        del primals_20
        buf28 = buf26
        del buf26
        extern_kernels.addmm(primals_22, reinterpret_tensor(buf27, (16, 8),
            (8, 1), 0), reinterpret_tensor(primals_21, (8, 4), (1, 8), 0),
            alpha=1, beta=1, out=buf28)
        del primals_22
    return (reinterpret_tensor(buf28, (4, 4, 4), (16, 4, 1), 0),
        reinterpret_tensor(buf0, (16, 8), (8, 1), 0), buf2,
        reinterpret_tensor(buf3, (16, 8), (8, 1), 0), buf5,
        reinterpret_tensor(buf6, (16, 8), (8, 1), 0), reinterpret_tensor(
        buf10, (16, 8), (8, 1), 0), buf12, reinterpret_tensor(buf13, (16, 8
        ), (8, 1), 0), reinterpret_tensor(buf15, (16, 8), (8, 1), 0), buf17,
        reinterpret_tensor(buf18, (16, 8), (8, 1), 0), reinterpret_tensor(
        buf22, (16, 8), (8, 1), 0), buf24, reinterpret_tensor(buf25, (16, 8
        ), (8, 1), 0), reinterpret_tensor(buf27, (16, 8), (8, 1), 0),
        primals_21, primals_19, primals_17, primals_15, primals_13,
        primals_11, primals_9, primals_7, primals_5)


class ResBlock(nn.Module):

    def __init__(self, feature_size, action_size):
        super(ResBlock, self).__init__()
        self.lin_1 = nn.Linear(feature_size + action_size, feature_size)
        self.lin_2 = nn.Linear(feature_size + action_size, feature_size)

    def forward(self, x, action):
        res = nn.functional.leaky_relu(self.lin_1(torch.cat([x, action], 2)))
        res = self.lin_2(torch.cat([res, action], 2))
        return res + x


class ResForwardNew(nn.Module):

    def __init__(self, feature_size, action_size):
        super(ResForwardNew, self).__init__()
        self.lin_1 = nn.Linear(feature_size + action_size, feature_size)
        self.res_block_1 = ResBlock(feature_size, action_size)
        self.res_block_2 = ResBlock(feature_size, action_size)
        self.res_block_3 = ResBlock(feature_size, action_size)
        self.res_block_4 = ResBlock(feature_size, action_size)
        self.lin_last = nn.Linear(feature_size + action_size, feature_size)

    def forward(self, input_0, input_1):
        primals_3 = self.lin_1.weight
        primals_4 = self.lin_1.bias
        primals_5 = self.res_block_1.lin_1.weight
        primals_6 = self.res_block_1.lin_1.bias
        primals_7 = self.res_block_1.lin_2.weight
        primals_8 = self.res_block_1.lin_2.bias
        primals_9 = self.res_block_2.lin_1.weight
        primals_10 = self.res_block_2.lin_1.bias
        primals_11 = self.res_block_2.lin_2.weight
        primals_12 = self.res_block_2.lin_2.bias
        primals_13 = self.res_block_3.lin_1.weight
        primals_14 = self.res_block_3.lin_1.bias
        primals_15 = self.res_block_3.lin_2.weight
        primals_16 = self.res_block_3.lin_2.bias
        primals_17 = self.res_block_4.lin_1.weight
        primals_18 = self.res_block_4.lin_1.bias
        primals_19 = self.res_block_4.lin_2.weight
        primals_20 = self.res_block_4.lin_2.bias
        primals_21 = self.lin_last.weight
        primals_22 = self.lin_last.bias
        primals_1 = input_0
        primals_2 = input_1
        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])
        return output[0]


Measured latency_ms: 0.311842