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 import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
from torch import 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, in_ptr1, 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 % 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_per_fused_elu_native_layer_norm_1(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    rnumel = 400
    RBLOCK: tl.constexpr = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 400 * x0), rmask, other=0.0)
    tmp31 = tl.load(in_ptr1 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp33 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = 1.0
    tmp4 = tmp0 * tmp3
    tmp5 = libdevice.expm1(tmp4)
    tmp6 = tmp5 * tmp3
    tmp7 = tl.where(tmp2, tmp4, tmp6)
    tmp8 = tl.broadcast_to(tmp7, [RBLOCK])
    tl.where(rmask, tmp8, 0)
    tmp11 = tl.broadcast_to(tmp8, [RBLOCK])
    tmp13 = tl.where(rmask, tmp11, 0)
    tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tmp15 = tl.full([1], 400, tl.int32)
    tmp16 = tmp15.to(tl.float32)
    tmp17 = tmp14 / tmp16
    tmp18 = tmp8 - tmp17
    tmp19 = tmp18 * tmp18
    tmp20 = tl.broadcast_to(tmp19, [RBLOCK])
    tmp22 = tl.where(rmask, tmp20, 0)
    tmp23 = triton_helpers.promote_to_tensor(tl.sum(tmp22, 0))
    tmp24 = 400.0
    tmp25 = tmp23 / tmp24
    tmp26 = 1e-05
    tmp27 = tmp25 + tmp26
    tmp28 = libdevice.rsqrt(tmp27)
    tmp29 = tmp7 - tmp17
    tmp30 = tmp29 * tmp28
    tmp32 = tmp30 * tmp31
    tmp34 = tmp32 + tmp33
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp28, None)
    tl.store(out_ptr1 + (r1 + 400 * x0), tmp34, rmask)
    tl.store(out_ptr0 + x0, tmp17, None)


@triton.jit
def triton_per_fused_elu_native_layer_norm_2(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    rnumel = 300
    RBLOCK: tl.constexpr = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 300 * x0), rmask, other=0.0)
    tmp31 = tl.load(in_ptr1 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp33 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = 1.0
    tmp4 = tmp0 * tmp3
    tmp5 = libdevice.expm1(tmp4)
    tmp6 = tmp5 * tmp3
    tmp7 = tl.where(tmp2, tmp4, tmp6)
    tmp8 = tl.broadcast_to(tmp7, [RBLOCK])
    tl.where(rmask, tmp8, 0)
    tmp11 = tl.broadcast_to(tmp8, [RBLOCK])
    tmp13 = tl.where(rmask, tmp11, 0)
    tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tmp15 = tl.full([1], 300, tl.int32)
    tmp16 = tmp15.to(tl.float32)
    tmp17 = tmp14 / tmp16
    tmp18 = tmp8 - tmp17
    tmp19 = tmp18 * tmp18
    tmp20 = tl.broadcast_to(tmp19, [RBLOCK])
    tmp22 = tl.where(rmask, tmp20, 0)
    tmp23 = triton_helpers.promote_to_tensor(tl.sum(tmp22, 0))
    tmp24 = 300.0
    tmp25 = tmp23 / tmp24
    tmp26 = 1e-05
    tmp27 = tmp25 + tmp26
    tmp28 = libdevice.rsqrt(tmp27)
    tmp29 = tmp7 - tmp17
    tmp30 = tmp29 * tmp28
    tmp32 = tmp30 * tmp31
    tmp34 = tmp32 + tmp33
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp28, None)
    tl.store(out_ptr1 + (r1 + 300 * x0), tmp34, rmask)
    tl.store(out_ptr0 + x0, tmp17, None)


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, primals_26, primals_27,
        primals_28, primals_29, primals_30, primals_31, primals_32) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (400, 8), (8, 1))
    assert_size_stride(primals_4, (400,), (1,))
    assert_size_stride(primals_5, (400,), (1,))
    assert_size_stride(primals_6, (400,), (1,))
    assert_size_stride(primals_7, (300, 400), (400, 1))
    assert_size_stride(primals_8, (300,), (1,))
    assert_size_stride(primals_9, (300,), (1,))
    assert_size_stride(primals_10, (300,), (1,))
    assert_size_stride(primals_11, (1, 300), (300, 1))
    assert_size_stride(primals_12, (1,), (1,))
    assert_size_stride(primals_13, (400, 8), (8, 1))
    assert_size_stride(primals_14, (400,), (1,))
    assert_size_stride(primals_15, (400,), (1,))
    assert_size_stride(primals_16, (400,), (1,))
    assert_size_stride(primals_17, (300, 400), (400, 1))
    assert_size_stride(primals_18, (300,), (1,))
    assert_size_stride(primals_19, (300,), (1,))
    assert_size_stride(primals_20, (300,), (1,))
    assert_size_stride(primals_21, (1, 300), (300, 1))
    assert_size_stride(primals_22, (1,), (1,))
    assert_size_stride(primals_23, (400, 4), (4, 1))
    assert_size_stride(primals_24, (400,), (1,))
    assert_size_stride(primals_25, (400,), (1,))
    assert_size_stride(primals_26, (400,), (1,))
    assert_size_stride(primals_27, (300, 400), (400, 1))
    assert_size_stride(primals_28, (300,), (1,))
    assert_size_stride(primals_29, (300,), (1,))
    assert_size_stride(primals_30, (300,), (1,))
    assert_size_stride(primals_31, (1, 300), (300, 1))
    assert_size_stride(primals_32, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_4, buf0, reinterpret_tensor(primals_3,
            (8, 400), (1, 8), 0), alpha=1, beta=1, out=buf1)
        del primals_3
        del primals_4
        buf2 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf5 = reinterpret_tensor(buf3, (4, 1), (1, 1), 0)
        del buf3
        buf6 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_1[grid(4)](buf5, buf1,
            primals_5, primals_6, buf2, buf6, 4, 400, num_warps=4, num_stages=1
            )
        del primals_6
        buf7 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        extern_kernels.addmm(primals_8, buf6, reinterpret_tensor(primals_7,
            (400, 300), (1, 400), 0), alpha=1, beta=1, out=buf7)
        del primals_8
        buf8 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf9 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf11 = reinterpret_tensor(buf9, (4, 1), (1, 1), 0)
        del buf9
        buf12 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_2[grid(4)](buf11, buf7,
            primals_9, primals_10, buf8, buf12, 4, 300, num_warps=4,
            num_stages=1)
        del primals_10
        buf14 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.addmm(primals_12, buf12, reinterpret_tensor(
            primals_11, (300, 1), (1, 300), 0), alpha=1, beta=1, out=buf14)
        del primals_12
        buf15 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_14, buf0, reinterpret_tensor(
            primals_13, (8, 400), (1, 8), 0), alpha=1, beta=1, out=buf15)
        del primals_13
        del primals_14
        buf16 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf17 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf19 = reinterpret_tensor(buf17, (4, 1), (1, 1), 0)
        del buf17
        buf20 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_1[grid(4)](buf19, buf15,
            primals_15, primals_16, buf16, buf20, 4, 400, num_warps=4,
            num_stages=1)
        del primals_16
        buf21 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        extern_kernels.addmm(primals_18, buf20, reinterpret_tensor(
            primals_17, (400, 300), (1, 400), 0), alpha=1, beta=1, out=buf21)
        del primals_18
        buf22 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf23 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf25 = reinterpret_tensor(buf23, (4, 1), (1, 1), 0)
        del buf23
        buf26 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_2[grid(4)](buf25, buf21,
            primals_19, primals_20, buf22, buf26, 4, 300, num_warps=4,
            num_stages=1)
        del primals_20
        buf28 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.addmm(primals_22, buf26, reinterpret_tensor(
            primals_21, (300, 1), (1, 300), 0), alpha=1, beta=1, out=buf28)
        del primals_22
        buf29 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_24, primals_1, reinterpret_tensor(
            primals_23, (4, 400), (1, 4), 0), alpha=1, beta=1, out=buf29)
        del primals_23
        del primals_24
        buf30 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf31 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf33 = reinterpret_tensor(buf31, (4, 1), (1, 1), 0)
        del buf31
        buf34 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_1[grid(4)](buf33, buf29,
            primals_25, primals_26, buf30, buf34, 4, 400, num_warps=4,
            num_stages=1)
        del primals_26
        buf35 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        extern_kernels.addmm(primals_28, buf34, reinterpret_tensor(
            primals_27, (400, 300), (1, 400), 0), alpha=1, beta=1, out=buf35)
        del primals_28
        buf36 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        buf37 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf39 = reinterpret_tensor(buf37, (4, 1), (1, 1), 0)
        del buf37
        buf40 = empty_strided_cuda((4, 300), (300, 1), torch.float32)
        triton_per_fused_elu_native_layer_norm_2[grid(4)](buf39, buf35,
            primals_29, primals_30, buf36, buf40, 4, 300, num_warps=4,
            num_stages=1)
        del primals_30
        buf42 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.addmm(primals_32, buf40, reinterpret_tensor(
            primals_31, (300, 1), (1, 300), 0), alpha=1, beta=1, out=buf42)
        del primals_32
    return (buf14, buf28, buf42, primals_1, primals_5, primals_9,
        primals_15, primals_19, primals_25, primals_29, buf0, buf1, buf2,
        buf5, buf6, buf7, buf8, buf11, buf12, buf15, buf16, buf19, buf20,
        buf21, buf22, buf25, buf26, buf29, buf30, buf33, buf34, buf35,
        buf36, buf39, buf40, primals_31, primals_27, primals_21, primals_17,
        primals_11, primals_7)


class CriticNew(nn.Module):
    """Critic model

        Parameters:
              args (object): Parameter class

    """

    def __init__(self, state_dim, action_dim):
        super(CriticNew, self).__init__()
        l1 = 400
        l2 = 300
        self.q1f1 = nn.Linear(state_dim + action_dim, l1)
        self.q1ln1 = nn.LayerNorm(l1)
        self.q1f2 = nn.Linear(l1, l2)
        self.q1ln2 = nn.LayerNorm(l2)
        self.q1out = nn.Linear(l2, 1)
        self.q2f1 = nn.Linear(state_dim + action_dim, l1)
        self.q2ln1 = nn.LayerNorm(l1)
        self.q2f2 = nn.Linear(l1, l2)
        self.q2ln2 = nn.LayerNorm(l2)
        self.q2out = nn.Linear(l2, 1)
        self.vf1 = nn.Linear(state_dim, l1)
        self.vln1 = nn.LayerNorm(l1)
        self.vf2 = nn.Linear(l1, l2)
        self.vln2 = nn.LayerNorm(l2)
        self.vout = nn.Linear(l2, 1)

    def forward(self, input_0, input_1):
        primals_3 = self.q1f1.weight
        primals_4 = self.q1f1.bias
        primals_5 = self.q1ln1.weight
        primals_6 = self.q1ln1.bias
        primals_7 = self.q1f2.weight
        primals_8 = self.q1f2.bias
        primals_9 = self.q1ln2.weight
        primals_10 = self.q1ln2.bias
        primals_11 = self.q1out.weight
        primals_12 = self.q1out.bias
        primals_13 = self.q2f1.weight
        primals_14 = self.q2f1.bias
        primals_15 = self.q2ln1.weight
        primals_16 = self.q2ln1.bias
        primals_17 = self.q2f2.weight
        primals_18 = self.q2f2.bias
        primals_19 = self.q2ln2.weight
        primals_20 = self.q2ln2.bias
        primals_21 = self.q2out.weight
        primals_22 = self.q2out.bias
        primals_23 = self.vf1.weight
        primals_24 = self.vf1.bias
        primals_25 = self.vln1.weight
        primals_26 = self.vln1.bias
        primals_27 = self.vf2.weight
        primals_28 = self.vf2.bias
        primals_29 = self.vln2.weight
        primals_30 = self.vln2.bias
        primals_31 = self.vout.weight
        primals_32 = self.vout.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, primals_23, primals_24,
            primals_25, primals_26, primals_27, primals_28, primals_29,
            primals_30, primals_31, primals_32])
        return output[0], output[1], output[2]


Measured latency_ms: 0.218141