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 numpy as np
import torch.nn as nn
import torch.nn.functional as F
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_native_layer_norm_0(in_ptr0, 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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp9 = tmp0 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = tmp1 - tmp8
    tmp12 = tmp11 * tmp11
    tmp13 = tmp10 + tmp12
    tmp14 = tmp3 - tmp8
    tmp15 = tmp14 * tmp14
    tmp16 = tmp13 + tmp15
    tmp17 = tmp5 - tmp8
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp20 = tmp19 / tmp7
    tmp21 = 1e-05
    tmp22 = tmp20 + tmp21
    tmp23 = libdevice.rsqrt(tmp22)
    tl.store(out_ptr0 + x0, tmp8, xmask)
    tl.store(out_ptr1 + x0, tmp23, xmask)


@triton.jit
def triton_poi_fused_native_layer_norm_1(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
    x1 = xindex // 4
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 * tmp3
    tmp6 = tmp4 * tmp5
    tmp8 = tmp6 + tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


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


@triton.jit
def triton_poi_fused_clone_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 64
    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 % 16
    y1 = yindex // 16
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * 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_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 = 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_5(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_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + x4, tmp2, xmask)


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


@triton.jit
def triton_poi_fused_add_native_layer_norm_8(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
    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 = tmp27 / tmp15
    tl.store(out_ptr0 + x0, tmp16, xmask)
    tl.store(out_ptr1 + x0, tmp28, xmask)


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


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


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


@triton.jit
def triton_poi_fused_relu_threshold_backward_12(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)


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,
        primals_33, primals_34, primals_35, primals_36, primals_37,
        primals_38, primals_39) = args
    args.clear()
    assert_size_stride(primals_1, (4,), (1,))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_4, (16, 4), (4, 1))
    assert_size_stride(primals_5, (16,), (1,))
    assert_size_stride(primals_6, (16, 4), (4, 1))
    assert_size_stride(primals_7, (16,), (1,))
    assert_size_stride(primals_8, (16, 4), (4, 1))
    assert_size_stride(primals_9, (16,), (1,))
    assert_size_stride(primals_10, (4, 16), (16, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_15, (16, 4), (4, 1))
    assert_size_stride(primals_16, (16,), (1,))
    assert_size_stride(primals_17, (16, 4), (4, 1))
    assert_size_stride(primals_18, (16,), (1,))
    assert_size_stride(primals_19, (16, 4), (4, 1))
    assert_size_stride(primals_20, (16,), (1,))
    assert_size_stride(primals_21, (4, 16), (16, 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), (16, 4, 1))
    assert_size_stride(primals_26, (16, 4), (4, 1))
    assert_size_stride(primals_27, (16,), (1,))
    assert_size_stride(primals_28, (16, 4), (4, 1))
    assert_size_stride(primals_29, (16,), (1,))
    assert_size_stride(primals_30, (16, 4), (4, 1))
    assert_size_stride(primals_31, (16,), (1,))
    assert_size_stride(primals_32, (4, 16), (16, 1))
    assert_size_stride(primals_33, (4,), (1,))
    assert_size_stride(primals_34, (4,), (1,))
    assert_size_stride(primals_35, (4,), (1,))
    assert_size_stride(primals_36, (4, 4), (4, 1))
    assert_size_stride(primals_37, (4,), (1,))
    assert_size_stride(primals_38, (4, 4), (4, 1))
    assert_size_stride(primals_39, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_native_layer_norm_0[grid(16)](primals_3, buf0,
            buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_native_layer_norm_1[grid(64)](primals_3, buf0,
            buf1, primals_1, primals_2, buf2, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del primals_1
        del primals_2
        buf3 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf3)
        buf4 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_6, (4, 16), (1, 4), 0), out=buf4)
        buf5 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_8, (4, 16), (1, 4), 0), out=buf5)
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_div_sqrt_2[grid(256)](buf3, primals_5, buf6,
            256, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_5
        buf7 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf3
        triton_poi_fused_clone_3[grid(64, 4)](buf4, primals_7, buf7, 64, 4,
            XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_7
        buf8 = reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1), 0)
        del buf4
        extern_kernels.bmm(reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1), 0), out=buf8)
        buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_4[grid(256)](buf8, buf9, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf10 = reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf8
        triton_poi_fused__softmax_5[grid(256)](buf9, buf10, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf11 = buf9
        del buf9
        triton_poi_fused_clone_6[grid(256)](buf5, primals_9, buf11, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_9
        buf12 = reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0)
        del buf5
        extern_kernels.bmm(reinterpret_tensor(buf10, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf11, (16, 4, 4), (16, 4, 1), 0), out=buf12
            )
        buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_7[grid(256)](buf12, buf13, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf14 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf13, (16, 16),
            (16, 1), 0), reinterpret_tensor(primals_10, (16, 4), (1, 16), 0
            ), alpha=1, beta=1, out=buf14)
        del primals_11
        buf15 = buf1
        del buf1
        buf16 = buf0
        del buf0
        triton_poi_fused_add_native_layer_norm_8[grid(16)](primals_3, buf14,
            buf15, buf16, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_native_layer_norm_9[grid(64)](primals_3, buf14,
            buf15, buf16, primals_12, primals_13, buf17, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_13
        buf18 = reinterpret_tensor(buf12, (16, 16), (16, 1), 0)
        del buf12
        extern_kernels.mm(reinterpret_tensor(buf17, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_15, (4, 16), (1, 4), 0), out=buf18)
        buf19 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_14, (16, 4), (4, 1), 0
            ), reinterpret_tensor(primals_17, (4, 16), (1, 4), 0), out=buf19)
        del primals_17
        buf20 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_14, (16, 4), (4, 1), 0
            ), reinterpret_tensor(primals_19, (4, 16), (1, 4), 0), out=buf20)
        del primals_19
        buf21 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_div_sqrt_2[grid(256)](buf18, primals_16,
            buf21, 256, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_16
        buf22 = reinterpret_tensor(buf18, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf18
        triton_poi_fused_clone_3[grid(64, 4)](buf19, primals_18, buf22, 64,
            4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_18
        buf23 = reinterpret_tensor(buf19, (16, 4, 4), (16, 4, 1), 0)
        del buf19
        extern_kernels.bmm(reinterpret_tensor(buf21, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf22, (16, 4, 4), (16, 4, 1), 0), out=buf23
            )
        buf24 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_4[grid(256)](buf23, buf24, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf25 = reinterpret_tensor(buf23, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf23
        triton_poi_fused__softmax_5[grid(256)](buf24, buf25, 256, XBLOCK=
            256, num_warps=4, num_stages=1)
        buf26 = buf24
        del buf24
        triton_poi_fused_clone_6[grid(256)](buf20, primals_20, buf26, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_20
        buf27 = reinterpret_tensor(buf20, (16, 4, 4), (16, 4, 1), 0)
        del buf20
        extern_kernels.bmm(reinterpret_tensor(buf25, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf26, (16, 4, 4), (16, 4, 1), 0), out=buf27
            )
        buf28 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_7[grid(256)](buf27, buf28, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf29 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf28, (16, 16), (16, 1), 0),
            reinterpret_tensor(primals_21, (16, 4), (1, 16), 0), out=buf29)
        buf30 = reinterpret_tensor(buf29, (4, 4, 4), (16, 4, 1), 0)
        del buf29
        triton_poi_fused_add_10[grid(64)](buf30, primals_3, buf14,
            primals_22, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_22
        buf31 = buf16
        del buf16
        buf32 = buf15
        del buf15
        triton_poi_fused_native_layer_norm_0[grid(16)](buf30, buf31, buf32,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf33 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_native_layer_norm_1[grid(64)](buf30, buf31, buf32,
            primals_23, primals_24, buf33, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del primals_24
        buf34 = reinterpret_tensor(buf27, (16, 16), (16, 1), 0)
        del buf27
        extern_kernels.mm(reinterpret_tensor(buf33, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_26, (4, 16), (1, 4), 0), out=buf34)
        buf35 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_25, (16, 4), (4, 1), 0
            ), reinterpret_tensor(primals_28, (4, 16), (1, 4), 0), out=buf35)
        del primals_28
        buf36 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_25, (16, 4), (4, 1), 0
            ), reinterpret_tensor(primals_30, (4, 16), (1, 4), 0), out=buf36)
        del primals_30
        buf37 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_div_sqrt_2[grid(256)](buf34, primals_27,
            buf37, 256, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_27
        buf38 = reinterpret_tensor(buf34, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf34
        triton_poi_fused_clone_3[grid(64, 4)](buf35, primals_29, buf38, 64,
            4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_29
        buf39 = reinterpret_tensor(buf35, (16, 4, 4), (16, 4, 1), 0)
        del buf35
        extern_kernels.bmm(reinterpret_tensor(buf37, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf38, (16, 4, 4), (16, 4, 1), 0), out=buf39
            )
        buf40 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_4[grid(256)](buf39, buf40, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf41 = reinterpret_tensor(buf39, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf39
        triton_poi_fused__softmax_5[grid(256)](buf40, buf41, 256, XBLOCK=
            256, num_warps=4, num_stages=1)
        buf42 = buf40
        del buf40
        triton_poi_fused_clone_6[grid(256)](buf36, primals_31, buf42, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_31
        buf43 = reinterpret_tensor(buf36, (16, 4, 4), (16, 4, 1), 0)
        del buf36
        extern_kernels.bmm(reinterpret_tensor(buf41, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf42, (16, 4, 4), (16, 4, 1), 0), out=buf43
            )
        buf44 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_7[grid(256)](buf43, buf44, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf43
        buf45 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf44, (16, 16), (16, 1), 0),
            reinterpret_tensor(primals_32, (16, 4), (1, 16), 0), out=buf45)
        buf46 = reinterpret_tensor(buf45, (4, 4, 4), (16, 4, 1), 0)
        del buf45
        triton_poi_fused_add_11[grid(64)](buf46, buf30, primals_33, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_33
        buf47 = buf32
        del buf32
        buf48 = buf31
        del buf31
        triton_poi_fused_native_layer_norm_0[grid(16)](buf46, buf47, buf48,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf49 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_native_layer_norm_1[grid(64)](buf46, buf47, buf48,
            primals_34, primals_35, buf49, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del buf47
        del buf48
        del primals_35
        buf50 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf49, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_36, (4, 4), (1, 4), 0), out=buf50)
        buf51 = reinterpret_tensor(buf50, (4, 4, 4), (16, 4, 1), 0)
        del buf50
        buf54 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_12[grid(64)](buf51,
            primals_37, buf54, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_37
        buf52 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf51, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_38, (4, 4), (1, 4), 0), out=buf52)
        buf53 = reinterpret_tensor(buf52, (4, 4, 4), (16, 4, 1), 0)
        del buf52
        triton_poi_fused_add_11[grid(64)](buf53, buf46, primals_39, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_39
    return (buf53, primals_3, primals_12, primals_23, primals_34,
        reinterpret_tensor(buf2, (16, 4), (4, 1), 0), buf10,
        reinterpret_tensor(buf13, (16, 16), (16, 1), 0), buf14,
        reinterpret_tensor(buf17, (16, 4), (4, 1), 0), reinterpret_tensor(
        primals_14, (16, 4), (4, 1), 0), buf25, reinterpret_tensor(buf28, (
        16, 16), (16, 1), 0), buf30, reinterpret_tensor(buf33, (16, 4), (4,
        1), 0), reinterpret_tensor(primals_25, (16, 4), (4, 1), 0), buf41,
        reinterpret_tensor(buf44, (16, 16), (16, 1), 0), buf46,
        reinterpret_tensor(buf49, (16, 4), (4, 1), 0), reinterpret_tensor(
        buf51, (16, 4), (4, 1), 0), primals_38, buf54, primals_36,
        primals_32, reinterpret_tensor(buf42, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf37, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf38, (16, 4, 4), (16, 1, 4), 0), primals_26,
        primals_21, reinterpret_tensor(buf26, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf21, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf22, (16, 4, 4), (16, 1, 4), 0), primals_15,
        primals_10, reinterpret_tensor(buf11, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf6, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf7, (16, 4, 4), (16, 1, 4), 0), primals_8,
        primals_6, primals_4)


class ResidualConnectionLayer(nn.Module):

    def __init__(self, dim_model, prob_dropout=0.1, add_sublayer=True):
        super(ResidualConnectionLayer, self).__init__()
        self.add_sublayer = add_sublayer
        self.norm = nn.LayerNorm(dim_model)
        self.dropout = nn.Dropout(prob_dropout)

    def forward(self, x, sublayer):
        out = self.norm(x)
        out = sublayer(out)
        out = self.dropout(out)
        if self.add_sublayer:
            return x + out
        else:
            return out


class BaseLayer(nn.Module):

    def __init__(self, dim_model, dim_k, dim_v, h, dim_ff, prob_dropout):
        super(BaseLayer, self).__init__()
        self._dim_model = dim_model
        self._dim_k = dim_k
        self._dim_v = dim_v
        self._h = h
        self._dim_ff = dim_ff
        self._prob_dropout = prob_dropout


class MultiHeadedAttentionLayer(nn.Module):

    def __init__(self, dim_model, dim_k, dim_v, h):
        super(MultiHeadedAttentionLayer, self).__init__()
        self.dim_model = dim_model
        self.dim_k = dim_k
        self.dim_v = dim_v
        self.h = h
        self.Q_linear = nn.Linear(dim_model, dim_k * h)
        self.K_linear = nn.Linear(dim_model, dim_k * h)
        self.V_linear = nn.Linear(dim_model, dim_v * h)
        self.out_linear = nn.Linear(self.h * dim_v, dim_model)

    def forward(self, Q, K, V, mask=None):
        b, len_q, len_k, len_v = Q.size(0), Q.size(1), K.size(1), V.size(1)
        Q_ = self.Q_linear(Q).view(b, len_q, self.h, self.dim_k).transpose(1, 2
            )
        K_ = self.K_linear(K).view(b, len_k, self.h, self.dim_k).transpose(1, 2
            )
        V_ = self.V_linear(V).view(b, len_v, self.h, self.dim_v).transpose(1, 2
            )
        if mask is not None:
            mask = mask.unsqueeze(1)
        out = self.__attention(Q_, K_, V_, mask)
        out = out.transpose(1, 2).contiguous().view(b, len_q, -1)
        out = self.out_linear(out)
        return out

    @staticmethod
    def __attention(Q, K, V, mask=None):
        d_k = K.shape[0]
        att = (Q / np.sqrt(d_k)).matmul(K.transpose(-1, -2))
        if mask is not None:
            att = att.masked_fill(mask == 0, -float('inf'))
        att = F.softmax(att, dim=-1)
        out = att.matmul(V)
        return out


class PositionWiseFeedForwardLayer(nn.Module):

    def __init__(self, dim_in, dim_ff, prob_dropout=0.1):
        super(PositionWiseFeedForwardLayer, self).__init__()
        self.fc1 = nn.Linear(dim_in, dim_ff)
        self.fc2 = nn.Linear(dim_ff, dim_in)
        self.dropout = nn.Dropout(prob_dropout)

    def forward(self, x):
        out = self.fc1(x)
        out = F.relu(out)
        out = self.fc2(out)
        return out


class DoubleForwardCrossAttentionLayerNew(BaseLayer):

    def __init__(self, dim_model, dim_k, dim_v, h, dim_ff, prob_dropout):
        super(DoubleForwardCrossAttentionLayerNew, self).__init__(dim_model,
            dim_k, dim_v, h, dim_ff, prob_dropout)
        self.self_att = MultiHeadedAttentionLayer(dim_model, dim_k, dim_v, h)
        self.rc1 = ResidualConnectionLayer(dim_model, prob_dropout)
        self.context_att = MultiHeadedAttentionLayer(dim_model, dim_k, dim_v, h
            )
        self.rc2 = ResidualConnectionLayer(dim_model, prob_dropout)
        self.encoder_att = MultiHeadedAttentionLayer(dim_model, dim_k, dim_v, h
            )
        self.rc3 = ResidualConnectionLayer(dim_model, prob_dropout)
        self.ff = PositionWiseFeedForwardLayer(dim_model, dim_ff)
        self.rc4 = ResidualConnectionLayer(dim_model, prob_dropout)

    def forward(self, input_0, input_1, input_2):
        primals_4 = self.self_att.Q_linear.weight
        primals_5 = self.self_att.Q_linear.bias
        primals_6 = self.self_att.K_linear.weight
        primals_7 = self.self_att.K_linear.bias
        primals_8 = self.self_att.V_linear.weight
        primals_9 = self.self_att.V_linear.bias
        primals_10 = self.self_att.out_linear.weight
        primals_1 = self.self_att.out_linear.bias
        primals_2 = self.rc1.norm.weight
        primals_11 = self.rc1.norm.bias
        primals_15 = self.context_att.Q_linear.weight
        primals_16 = self.context_att.Q_linear.bias
        primals_17 = self.context_att.K_linear.weight
        primals_18 = self.context_att.K_linear.bias
        primals_19 = self.context_att.V_linear.weight
        primals_20 = self.context_att.V_linear.bias
        primals_21 = self.context_att.out_linear.weight
        primals_12 = self.context_att.out_linear.bias
        primals_13 = self.rc2.norm.weight
        primals_22 = self.rc2.norm.bias
        primals_26 = self.encoder_att.Q_linear.weight
        primals_27 = self.encoder_att.Q_linear.bias
        primals_28 = self.encoder_att.K_linear.weight
        primals_29 = self.encoder_att.K_linear.bias
        primals_30 = self.encoder_att.V_linear.weight
        primals_31 = self.encoder_att.V_linear.bias
        primals_32 = self.encoder_att.out_linear.weight
        primals_23 = self.encoder_att.out_linear.bias
        primals_24 = self.rc3.norm.weight
        primals_33 = self.rc3.norm.bias
        primals_36 = self.ff.fc1.weight
        primals_34 = self.ff.fc1.bias
        primals_38 = self.ff.fc2.weight
        primals_35 = self.ff.fc2.bias
        primals_37 = self.rc4.norm.weight
        primals_39 = self.rc4.norm.bias
        primals_3 = input_0
        primals_14 = input_1
        primals_25 = 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, 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, primals_33, primals_34,
            primals_35, primals_36, primals_37, primals_38, primals_39])
        return output[0]


Measured latency_ms: 0.02182