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, math as tl_math
import math
from torch.autograd import Variable
import torch.nn as nn
import torch.optim
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_add_div_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2,
    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 % 4
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x2, xmask)
    tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp30 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp8 = tmp6 + tmp7
    tmp9 = 4.0
    tmp10 = tmp8 / tmp9
    tmp11 = tmp1 - tmp10
    tmp12 = tmp0 * tmp11
    tmp13 = tmp2 - tmp10
    tmp14 = tmp13 * tmp13
    tmp15 = tmp3 - tmp10
    tmp16 = tmp15 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = tmp5 - tmp10
    tmp19 = tmp18 * tmp18
    tmp20 = tmp17 + tmp19
    tmp21 = tmp7 - tmp10
    tmp22 = tmp21 * tmp21
    tmp23 = tmp20 + tmp22
    tmp24 = 3.0
    tmp25 = tmp23 / tmp24
    tmp26 = libdevice.sqrt(tmp25)
    tmp27 = 1e-06
    tmp28 = tmp26 + tmp27
    tmp29 = tmp12 / tmp28
    tmp31 = tmp29 + tmp30
    tl.store(out_ptr0 + x2, tmp31, xmask)


@triton.jit
def triton_poi_fused_clone_div_1(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp4, xmask & ymask)


@triton.jit
def triton_poi_fused_clone_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask)


@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


@triton.jit
def triton_poi_fused_clone_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_add_mean_std_6(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 + tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 + tmp12
    tmp14 = tmp10 + tmp13
    tmp15 = 4.0
    tmp16 = tmp14 / tmp15
    tmp17 = tmp2 - tmp16
    tmp18 = tmp17 * tmp17
    tmp19 = tmp5 - tmp16
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp22 = tmp9 - tmp16
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp25 = tmp13 - tmp16
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp28 = 3.0
    tmp29 = tmp27 / tmp28
    tl.store(in_out_ptr0 + x0, tmp29, xmask)
    tl.store(out_ptr0 + x0, tmp16, xmask)


@triton.jit
def triton_poi_fused_add_div_mean_mul_std_sub_7(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, in_ptr5, 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 % 4
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x2, xmask)
    tmp2 = tl.load(in_ptr2 + x2, xmask)
    tmp4 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 - tmp4
    tmp6 = tmp0 * tmp5
    tmp8 = libdevice.sqrt(tmp7)
    tmp9 = 1e-06
    tmp10 = tmp8 + tmp9
    tmp11 = tmp6 / tmp10
    tmp13 = tmp11 + tmp12
    tl.store(out_ptr0 + x2, tmp13, xmask)


@triton.jit
def triton_poi_fused_clone_8(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 % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_9(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x2, xmask)
    tmp4 = tl.load(in_ptr2 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tmp2 + tmp5
    tl.store(in_out_ptr0 + x2, tmp6, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_10(in_out_ptr0, 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
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)


@triton.jit
def triton_poi_fused_view_11(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 % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * (x1 % 4 // 4)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_12(in_out_ptr0, in_ptr0, in_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
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(in_out_ptr0 + x2, 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,
        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
        ) = 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,), (1,))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 4), (4, 1))
    assert_size_stride(primals_8, (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,))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (4,), (1,))
    assert_size_stride(primals_15, (4, 4), (4, 1))
    assert_size_stride(primals_16, (4,), (1,))
    assert_size_stride(primals_17, (4, 4), (4, 1))
    assert_size_stride(primals_18, (4,), (1,))
    assert_size_stride(primals_19, (4, 4), (4, 1))
    assert_size_stride(primals_20, (4,), (1,))
    assert_size_stride(primals_21, (4, 4), (4, 1))
    assert_size_stride(primals_22, (4,), (1,))
    assert_size_stride(primals_23, (4,), (1,))
    assert_size_stride(primals_24, (4,), (1,))
    assert_size_stride(primals_25, (4, 4), (4, 1))
    assert_size_stride(primals_26, (4,), (1,))
    assert_size_stride(primals_27, (4, 4), (4, 1))
    assert_size_stride(primals_28, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_div_mean_mul_std_sub_0[grid(64)](primals_3,
            primals_1, primals_4, buf0, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del primals_3
        del primals_4
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf1)
        buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
        buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_div_1[grid(16, 4)](buf3, primals_10, buf4, 
            16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_10
        buf5 = reinterpret_tensor(buf3, (4, 4, 1, 4), (16, 4, 4, 1), 0)
        del buf3
        triton_poi_fused_clone_2[grid(16, 4)](buf1, primals_6, buf5, 16, 4,
            XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_6
        buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 0), 
            0), reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 0), out=buf6)
        buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_3[grid(256)](buf6, buf7, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf8 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf6
        triton_poi_fused__softmax_4[grid(256)](buf7, buf8, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf9 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 1), 0)
        del buf1
        triton_poi_fused_clone_2[grid(16, 4)](buf2, primals_8, buf9, 16, 4,
            XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_8
        buf10 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0)
        del buf2
        extern_kernels.bmm(reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 0), out=buf10)
        buf11 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_5[grid(16, 4)](buf10, buf11, 16, 4, XBLOCK=4,
            YBLOCK=16, num_warps=1, num_stages=1)
        buf12 = reinterpret_tensor(buf10, (16, 4), (4, 1), 0)
        del buf10
        extern_kernels.addmm(primals_12, reinterpret_tensor(buf11, (16, 4),
            (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0),
            alpha=1, beta=1, out=buf12)
        del primals_12
        buf13 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf14 = buf13
        del buf13
        buf15 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        triton_poi_fused_add_mean_std_6[grid(16)](buf14, buf12, primals_1,
            buf15, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf16 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_2, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf16)
        del primals_15
        buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_2, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_17, (4, 4), (1, 4), 0), out=buf17)
        del primals_17
        buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mean_mul_std_sub_7[grid(64)](primals_13,
            buf12, primals_1, buf15, buf14, primals_14, buf18, 64, XBLOCK=
            64, num_warps=1, num_stages=1)
        del buf14
        del buf15
        del primals_14
        buf19 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf18, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_19, (4, 4), (1, 4), 0), out=buf19)
        buf20 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_div_1[grid(16, 4)](buf19, primals_20, buf20,
            16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_20
        buf21 = reinterpret_tensor(buf19, (4, 4, 1, 4), (16, 4, 4, 1), 0)
        del buf19
        triton_poi_fused_clone_2[grid(16, 4)](buf16, primals_16, buf21, 16,
            4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_16
        buf22 = reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1), 0)
        del buf7
        extern_kernels.bmm(reinterpret_tensor(buf20, (16, 4, 1), (4, 1, 0),
            0), reinterpret_tensor(buf21, (16, 1, 4), (4, 0, 1), 0), out=buf22)
        buf23 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_3[grid(256)](buf22, buf23, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf24 = reinterpret_tensor(buf22, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf22
        triton_poi_fused__softmax_4[grid(256)](buf23, buf24, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        del buf23
        buf25 = reinterpret_tensor(buf16, (4, 4, 4, 1), (16, 4, 1, 1), 0)
        del buf16
        triton_poi_fused_clone_2[grid(16, 4)](buf17, primals_18, buf25, 16,
            4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
        del primals_18
        buf26 = reinterpret_tensor(buf17, (16, 4, 1), (4, 1, 1), 0)
        del buf17
        extern_kernels.bmm(reinterpret_tensor(buf24, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf25, (16, 4, 1), (4, 1, 0), 0), out=buf26)
        buf27 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_5[grid(16, 4)](buf26, buf27, 16, 4, XBLOCK=4,
            YBLOCK=16, num_warps=1, num_stages=1)
        buf28 = reinterpret_tensor(buf26, (16, 4), (4, 1), 0)
        del buf26
        extern_kernels.mm(reinterpret_tensor(buf27, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_21, (4, 4), (1, 4), 0), out=buf28)
        buf29 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_clone_8[grid(64)](buf24, buf29, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf30 = reinterpret_tensor(buf28, (4, 4, 4), (16, 4, 1), 0)
        del buf28
        triton_poi_fused_add_9[grid(64)](buf30, primals_22, buf12,
            primals_1, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_22
        buf31 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mean_mul_std_sub_0[grid(64)](primals_23,
            buf30, primals_24, buf31, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_24
        buf32 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf31, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), out=buf32)
        buf33 = reinterpret_tensor(buf32, (4, 4, 4), (16, 4, 1), 0)
        del buf32
        buf37 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_10[grid(64)](buf33,
            primals_26, buf37, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_26
        buf34 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        triton_poi_fused_view_11[grid(64)](buf33, buf34, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf35 = reinterpret_tensor(buf33, (16, 4), (4, 1), 0)
        del buf33
        extern_kernels.mm(buf34, reinterpret_tensor(primals_27, (4, 4), (1,
            4), 0), out=buf35)
        buf36 = reinterpret_tensor(buf35, (4, 4, 4), (16, 4, 1), 0)
        del buf35
        triton_poi_fused_add_12[grid(64)](buf36, primals_28, buf30, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_28
    return (buf36, buf29, buf0, primals_1, primals_13, primals_23, buf0,
        buf8, reinterpret_tensor(buf11, (16, 4), (4, 1), 0), buf12,
        reinterpret_tensor(primals_2, (16, 4), (4, 1), 0),
        reinterpret_tensor(buf18, (16, 4), (4, 1), 0), buf24,
        reinterpret_tensor(buf27, (16, 4), (4, 1), 0), buf30,
        reinterpret_tensor(buf31, (16, 4), (4, 1), 0), buf34, primals_27,
        buf37, primals_25, primals_21, reinterpret_tensor(buf25, (16, 1, 4),
        (4, 1, 1), 0), reinterpret_tensor(buf20, (16, 1, 4), (4, 1, 1), 0),
        reinterpret_tensor(buf21, (16, 4, 1), (4, 1, 4), 0), primals_19,
        primals_11, reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0),
        reinterpret_tensor(buf4, (16, 1, 4), (4, 1, 1), 0),
        reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0), primals_9,
        primals_7, primals_5)


class LayerNorm(nn.Module):

    def __init__(self, features, eps=1e-06):
        super(LayerNorm, self).__init__()
        self.a_2 = nn.Parameter(torch.ones(features))
        self.b_2 = nn.Parameter(torch.zeros(features))
        self.eps = eps

    def forward(self, x):
        mean = x.mean(-1, keepdim=True)
        std = x.std(-1, keepdim=True)
        return self.a_2 * (x - mean) / (std + self.eps) + self.b_2


class MultiHeadedAttention(nn.Module):
    """
    Multi-Head Attention module from
    "Attention is All You Need"
    :cite:`DBLP:journals/corr/VaswaniSPUJGKP17`.

    Similar to standard `dot` attention but uses
    multiple attention distributions simulataneously
    to select relevant items.

    .. mermaid::

       graph BT
          A[key]
          B[value]
          C[query]
          O[output]
          subgraph Attn
            D[Attn 1]
            E[Attn 2]
            F[Attn N]
          end
          A --> D
          C --> D
          A --> E
          C --> E
          A --> F
          C --> F
          D --> O
          E --> O
          F --> O
          B --> O

    Also includes several additional tricks.

    Args:
       head_count (int): number of parallel heads
       model_dim (int): the dimension of keys/values/queries,
           must be divisible by head_count
       dropout (float): dropout parameter
    """

    def __init__(self, head_count, model_dim, dropout=0.1):
        assert model_dim % head_count == 0
        self.dim_per_head = model_dim // head_count
        self.model_dim = model_dim
        super(MultiHeadedAttention, self).__init__()
        self.head_count = head_count
        self.linear_keys = nn.Linear(model_dim, head_count * self.dim_per_head)
        self.linear_values = nn.Linear(model_dim, head_count * self.
            dim_per_head)
        self.linear_query = nn.Linear(model_dim, head_count * self.dim_per_head
            )
        self.sm = nn.Softmax(dim=-1)
        self.dropout = nn.Dropout(dropout)
        self.final_linear = nn.Linear(model_dim, model_dim)

    def _split_heads(self, x):
        batch_size = x.size(0)
        return x.view(batch_size, -1, self.head_count, self.dim_per_head
            ).transpose(1, 2)

    def _combine_heads(self, x):
        """:param x: [batch_size * head_count, seq_len, dim_per_head]"""
        seq_len = x.size(2)
        return x.transpose(1, 2).contiguous().view(-1, seq_len, self.
            head_count * self.dim_per_head)

    def compute_cache(self, key, value):
        key_up = self._split_heads(self.linear_keys(key))
        value_up = self._split_heads(self.linear_values(value))
        return [key_up, value_up]

    def forward(self, key, value, query, mask=None, cache=None):
        """
        Compute the context vector and the attention vectors.

        Args:
           key (`FloatTensor`): set of `key_len`
                key vectors `[batch, key_len, dim]`
           value (`FloatTensor`): set of `key_len`
                value vectors `[batch, key_len, dim]`
           query (`FloatTensor`): set of `query_len`
                 query vectors  `[batch, query_len, dim]`
           mask: binary mask indicating which keys have
                 non-zero attention `[batch, query_len, key_len]`
        Returns:
           (`FloatTensor`, `FloatTensor`) :

           * output context vectors `[batch, query_len, dim]`
           * one of the attention vectors `[batch, query_len, key_len]`
        """
        batch_size = key.size(0)
        dim_per_head = self.dim_per_head
        head_count = self.head_count
        key_len = key.size(1)
        query_len = query.size(1)
        if cache is not None:
            key_up, value_up = cache
        else:
            key_up = self._split_heads(self.linear_keys(key))
            value_up = self._split_heads(self.linear_values(value))
        query_up = self._split_heads(self.linear_query(query))
        query_up = query_up / math.sqrt(dim_per_head)
        scores = torch.matmul(query_up, key_up.transpose(2, 3))
        if mask is not None:
            mask = mask.unsqueeze(1).expand_as(scores)
            scores = scores.masked_fill(Variable(mask), -1e+18)
        attn = self.sm(scores)
        drop_attn = self.dropout(attn)
        context = self._combine_heads(torch.matmul(drop_attn, value_up))
        output = self.final_linear(context)
        top_attn = attn.view(batch_size, head_count, query_len, key_len)[:,
            0, :, :].contiguous()
        return output, top_attn


class PositionwiseFeedForward(nn.Module):
    """ A two-layer Feed-Forward-Network with residual layer norm.

        Args:
            size (int): the size of input for the first-layer of the FFN.
            hidden_size (int): the hidden layer size of the second-layer
                              of the FNN.
            dropout (float): dropout probability(0-1.0).
    """

    def __init__(self, size, hidden_size, dropout=0.1):
        super(PositionwiseFeedForward, self).__init__()
        self.w_1 = nn.Linear(size, hidden_size)
        self.w_2 = nn.Linear(hidden_size, size)
        self.layer_norm = LayerNorm(size)
        self.dropout_1 = nn.Dropout(dropout, inplace=True)
        self.relu = nn.ReLU(inplace=True)
        self.dropout_2 = nn.Dropout(dropout)

    def forward(self, x):
        inter = self.dropout_1(self.relu(self.w_1(self.layer_norm(x))))
        output = self.dropout_2(self.w_2(inter))
        return output + x


class DecoderBlockNew(nn.Module):
    """ Compose with three layers """

    def __init__(self, d_model, d_inner_hid, n_head, dropout=0.1):
        super(DecoderBlockNew, self).__init__()
        self.slf_attn = MultiHeadedAttention(head_count=n_head, model_dim=
            d_model, dropout=dropout)
        self.ctx_attn = MultiHeadedAttention(head_count=n_head, model_dim=
            d_model, dropout=dropout)
        self.pos_ffn = PositionwiseFeedForward(size=d_model, hidden_size=
            d_inner_hid)
        self.layer_norm_1 = LayerNorm(d_model)
        self.layer_norm_2 = LayerNorm(d_model)
        self.dropout = nn.Dropout(dropout)

    def compute_cache(self, enc_output):
        return self.ctx_attn.compute_cache(enc_output, enc_output)

    def forward(self, input_0, input_1):
        primals_5 = self.slf_attn.linear_keys.weight
        primals_3 = self.slf_attn.linear_keys.bias
        primals_7 = self.slf_attn.linear_values.weight
        primals_4 = self.slf_attn.linear_values.bias
        primals_9 = self.slf_attn.linear_query.weight
        primals_6 = self.slf_attn.linear_query.bias
        primals_11 = self.slf_attn.final_linear.weight
        primals_8 = self.slf_attn.final_linear.bias
        primals_15 = self.ctx_attn.linear_keys.weight
        primals_10 = self.ctx_attn.linear_keys.bias
        primals_17 = self.ctx_attn.linear_values.weight
        primals_12 = self.ctx_attn.linear_values.bias
        primals_19 = self.ctx_attn.linear_query.weight
        primals_13 = self.ctx_attn.linear_query.bias
        primals_21 = self.ctx_attn.final_linear.weight
        primals_14 = self.ctx_attn.final_linear.bias
        primals_25 = self.pos_ffn.w_1.weight
        primals_16 = self.pos_ffn.w_1.bias
        primals_27 = self.pos_ffn.w_2.weight
        primals_18 = self.pos_ffn.w_2.bias
        primals_20 = self.pos_ffn.layer_norm.a_2
        primals_22 = self.pos_ffn.layer_norm.b_2
        primals_23 = self.layer_norm_1.a_2
        primals_24 = self.layer_norm_1.b_2
        primals_26 = self.layer_norm_2.a_2
        primals_28 = self.layer_norm_2.b_2
        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])
        return output[0], output[1], output[2]


Measured latency_ms: 0.040216