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
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_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 48
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6 % 4
    x2 = xindex // 24
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 6 * x2 + 12 * x1), xmask)
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_mul_1(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
    x4 = xindex // 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (6 * x4 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp9 = tl.load(in_ptr1 + (6 * x4 + (-2 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tmp11 = 0.5
    tmp12 = tmp10 * tmp11
    tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp12, xmask)


@triton.jit
def triton_poi_fused_cat_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
    x4 = xindex // 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (2 + 6 * x4 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp9 = tl.load(in_ptr1 + (2 + 6 * x4 + (-2 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp10, xmask)


@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_cat_5(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
    x4 = xindex // 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 + 6 * x4 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp9 = tl.load(in_ptr1 + (4 + 6 * x4 + (-2 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp10, xmask)


@triton.jit
def triton_poi_fused_clone_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 32
    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
    x3 = xindex
    y0 = yindex % 2
    y1 = yindex // 2 % 4
    y2 = yindex // 8
    y4 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * y1 + 16 * x3 + 64 * y2), xmask &
        ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x3 + 4 * y4), tmp0, xmask & ymask)


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


@triton.jit
def triton_poi_fused_clone_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 32
    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
    x3 = xindex
    y0 = yindex % 2
    y1 = yindex // 2 % 4
    y2 = yindex // 8
    y4 = yindex
    tmp0 = tl.load(in_ptr0 + (2 + y0 + 4 * y1 + 16 * x3 + 64 * y2), xmask &
        ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x3 + 4 * y4), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_add_cat_9(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
    x2 = xindex
    x0 = xindex % 4
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = x0
    tl.full([1], 0, tl.int64)
    tmp4 = tl.full([1], 2, tl.int64)
    tmp5 = tmp1 < tmp4
    tmp6 = tl.load(in_ptr1 + (2 * x1 + x0), tmp5 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tmp1 >= tmp4
    tl.full([1], 4, tl.int64)
    tmp10 = tl.load(in_ptr2 + (2 * x1 + (-2 + x0)), tmp7 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp11 = tl.where(tmp5, tmp6, tmp10)
    tmp12 = tmp0 + tmp11
    tl.store(out_ptr0 + x2, tmp12, xmask)


@triton.jit
def triton_poi_fused_native_layer_norm_10(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_11(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_add_relu_threshold_backward_12(in_out_ptr0, in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 2
    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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 2, 3, 2), (12, 6, 2, 1))
    assert_size_stride(primals_3, (4, 2, 3, 2), (12, 6, 2, 1))
    assert_size_stride(primals_4, (4, 2, 2), (4, 2, 1))
    assert_size_stride(primals_5, (4, 2, 2), (4, 2, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (2, 2), (2, 1))
    assert_size_stride(primals_9, (2,), (1,))
    assert_size_stride(primals_10, (2, 2), (2, 1))
    assert_size_stride(primals_11, (2,), (1,))
    assert_size_stride(primals_12, (2, 2), (2, 1))
    assert_size_stride(primals_13, (2,), (1,))
    assert_size_stride(primals_14, (2, 2), (2, 1))
    assert_size_stride(primals_15, (2,), (1,))
    assert_size_stride(primals_16, (4,), (1,))
    assert_size_stride(primals_17, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((2, 4, 3, 2, 1, 1), (24, 6, 2, 1, 1, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clone_0[grid(48)](primals_2, buf0, 48, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((1, 16, 24), (384, 24, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_1, (1, 16, 2), (0, 4,
            1), 0), reinterpret_tensor(buf0, (1, 2, 24), (0, 24, 1), 0),
            out=buf1)
        buf2 = buf0
        del buf0
        triton_poi_fused_clone_0[grid(48)](primals_3, buf2, 48, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_3
        buf3 = empty_strided_cuda((1, 16, 24), (384, 24, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_1, (1, 16, 2), (0, 4,
            1), 2), reinterpret_tensor(buf2, (1, 2, 24), (0, 24, 1), 0),
            out=buf3)
        del buf2
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_cat_mul_1[grid(256)](buf1, buf3, buf4, 256, XBLOCK
            =256, num_warps=4, num_stages=1)
        buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_cat_2[grid(256)](buf1, buf3, buf5, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf5, (16, 4, 4), (16, 1, 4), 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=256,
            num_warps=4, num_stages=1)
        buf9 = buf7
        del buf7
        triton_poi_fused_cat_5[grid(256)](buf1, buf3, buf9, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf1
        del buf3
        buf10 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1), 0), out=buf10)
        buf11 = empty_strided_cuda((4, 4, 2, 4, 1), (32, 8, 4, 1, 1), torch
            .float32)
        triton_poi_fused_clone_6[grid(32, 4)](buf10, buf11, 32, 4, XBLOCK=4,
            YBLOCK=32, num_warps=4, num_stages=1)
        buf12 = empty_strided_cuda((2, 4, 2, 1, 1), (8, 2, 1, 1, 1), torch.
            float32)
        triton_poi_fused_clone_7[grid(16)](primals_4, buf12, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del primals_4
        buf13 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf11, (1, 16, 8), (0, 8, 1),
            0), reinterpret_tensor(buf12, (1, 8, 2), (0, 2, 1), 0), out=buf13)
        buf14 = empty_strided_cuda((4, 4, 2, 4, 1), (32, 8, 4, 1, 1), torch
            .float32)
        triton_poi_fused_clone_8[grid(32, 4)](buf10, buf14, 32, 4, XBLOCK=4,
            YBLOCK=32, num_warps=4, num_stages=1)
        del buf10
        buf15 = empty_strided_cuda((2, 4, 2, 1, 1), (8, 2, 1, 1, 1), torch.
            float32)
        triton_poi_fused_clone_7[grid(16)](primals_5, buf15, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del primals_5
        buf16 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf14, (1, 16, 8), (0, 8, 1),
            0), reinterpret_tensor(buf15, (1, 8, 2), (0, 2, 1), 0), out=buf16)
        buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_cat_9[grid(64)](primals_1, buf13, buf16, buf17,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf18 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf19 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        triton_poi_fused_native_layer_norm_10[grid(16)](buf17, buf18, buf19,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf20 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_native_layer_norm_11[grid(64)](buf17, buf18, buf19,
            primals_6, primals_7, buf20, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del primals_7
        buf21 = reinterpret_tensor(buf16, (16, 2), (2, 1), 0)
        del buf16
        extern_kernels.mm(reinterpret_tensor(buf20, (16, 2), (4, 1), 0),
            reinterpret_tensor(primals_8, (2, 2), (1, 2), 0), out=buf21)
        buf22 = reinterpret_tensor(buf13, (16, 2), (2, 1), 0)
        del buf13
        extern_kernels.mm(reinterpret_tensor(buf20, (16, 2), (4, 1), 2),
            reinterpret_tensor(primals_10, (2, 2), (1, 2), 0), out=buf22)
        buf23 = reinterpret_tensor(buf21, (4, 4, 2), (8, 2, 1), 0)
        del buf21
        buf32 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.bool)
        triton_poi_fused_add_relu_threshold_backward_12[grid(32)](buf23,
            primals_9, buf32, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_9
        buf24 = empty_strided_cuda((16, 2), (2, 1), torch.float32)
        extern_kernels.addmm(primals_13, reinterpret_tensor(buf23, (16, 2),
            (2, 1), 0), reinterpret_tensor(primals_12, (2, 2), (1, 2), 0),
            alpha=1, beta=1, out=buf24)
        del primals_13
        buf25 = reinterpret_tensor(buf22, (4, 4, 2), (8, 2, 1), 0)
        del buf22
        buf31 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.bool)
        triton_poi_fused_add_relu_threshold_backward_12[grid(32)](buf25,
            primals_11, buf31, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_11
        buf26 = empty_strided_cuda((16, 2), (2, 1), torch.float32)
        extern_kernels.addmm(primals_15, reinterpret_tensor(buf25, (16, 2),
            (2, 1), 0), reinterpret_tensor(primals_14, (2, 2), (1, 2), 0),
            alpha=1, beta=1, out=buf26)
        del primals_15
        buf27 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_cat_9[grid(64)](buf20, buf24, buf26, buf27, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del buf24
        del buf26
        buf28 = buf19
        del buf19
        buf29 = buf18
        del buf18
        triton_poi_fused_native_layer_norm_10[grid(16)](buf27, buf28, buf29,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf30 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_native_layer_norm_11[grid(64)](buf27, buf28, buf29,
            primals_16, primals_17, buf30, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del buf28
        del buf29
        del primals_17
    return (buf30, primals_6, primals_16, buf8, buf17, reinterpret_tensor(
        buf20, (16, 2), (4, 1), 0), reinterpret_tensor(buf20, (16, 2), (4, 
        1), 2), reinterpret_tensor(buf23, (16, 2), (2, 1), 0),
        reinterpret_tensor(buf25, (16, 2), (2, 1), 0), buf27, primals_14,
        primals_12, buf31, buf32, primals_10, primals_8, reinterpret_tensor
        (buf14, (1, 8, 16), (128, 1, 8), 0), reinterpret_tensor(buf15, (1, 
        2, 8), (16, 1, 2), 0), reinterpret_tensor(buf11, (1, 8, 16), (128, 
        1, 8), 0), reinterpret_tensor(buf12, (1, 2, 8), (16, 1, 2), 0),
        reinterpret_tensor(buf9, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf4, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0),
        reinterpret_tensor(primals_1, (1, 2, 16), (64, 1, 4), 2),
        reinterpret_tensor(primals_1, (1, 2, 16), (64, 1, 4), 0))


class FeatureDropoutFunction(torch.autograd.function.InplaceFunction):

    @staticmethod
    def forward(ctx, input, p=0.5, train=False, inplace=False):
        if p < 0 or p > 1:
            raise ValueError(
                'dropout probability has to be between 0 and 1, but got {}'
                .format(p))
        ctx.p = p
        ctx.train = train
        ctx.inplace = inplace
        if ctx.inplace:
            ctx.mark_dirty(input)
            output = input
        else:
            output = input.clone()
        if ctx.p > 0 and ctx.train:
            ctx.noise = torch.empty((input.size(0), input.size(-1)), dtype=
                input.dtype, layout=input.layout, device=input.device)
            if ctx.p == 1:
                ctx.noise.fill_(0)
            else:
                ctx.noise.bernoulli_(1 - ctx.p).div_(1 - ctx.p)
            ctx.noise = ctx.noise[:, None, :]
            output.mul_(ctx.noise)
        return output

    @staticmethod
    def backward(ctx, grad_output):
        if ctx.p > 0 and ctx.train:
            return grad_output.mul(ctx.noise), None, None, None
        else:
            return grad_output, None, None, None


class FeatureDropout(nn.Dropout):
    """
    Feature-level dropout: takes an input of size len x num_features and drops
    each feature with probabibility p. A feature is dropped across the full
    portion of the input that corresponds to a single batch element.
    """

    def forward(self, x):
        if isinstance(x, tuple):
            x_c, x_p = x
            x_c = FeatureDropoutFunction.apply(x_c, self.p, self.training,
                self.inplace)
            x_p = FeatureDropoutFunction.apply(x_p, self.p, self.training,
                self.inplace)
            return x_c, x_p
        else:
            return FeatureDropoutFunction.apply(x, self.p, self.training,
                self.inplace)


class PartitionedLinear(nn.Module):

    def __init__(self, in_features, out_features, bias=True):
        super().__init__()
        self.linear_c = nn.Linear(in_features // 2, out_features // 2, bias)
        self.linear_p = nn.Linear(in_features // 2, out_features // 2, bias)

    def forward(self, x):
        if isinstance(x, tuple):
            x_c, x_p = x
        else:
            x_c, x_p = torch.chunk(x, 2, dim=-1)
        out_c = self.linear_c(x_c)
        out_p = self.linear_p(x_p)
        return out_c, out_p


class PartitionedMultiHeadAttention(nn.Module):

    def __init__(self, d_model, n_head, d_qkv, attention_dropout=0.1,
        initializer_range=0.02):
        super().__init__()
        self.w_qkv_c = nn.Parameter(torch.Tensor(n_head, d_model // 2, 3, 
            d_qkv // 2))
        self.w_qkv_p = nn.Parameter(torch.Tensor(n_head, d_model // 2, 3, 
            d_qkv // 2))
        self.w_o_c = nn.Parameter(torch.Tensor(n_head, d_qkv // 2, d_model //
            2))
        self.w_o_p = nn.Parameter(torch.Tensor(n_head, d_qkv // 2, d_model //
            2))
        bound = math.sqrt(3.0) * initializer_range
        for param in [self.w_qkv_c, self.w_qkv_p, self.w_o_c, self.w_o_p]:
            nn.init.uniform_(param, -bound, bound)
        self.scaling_factor = 1 / d_qkv ** 0.5
        self.dropout = nn.Dropout(attention_dropout)

    def forward(self, x, mask=None):
        if isinstance(x, tuple):
            x_c, x_p = x
        else:
            x_c, x_p = torch.chunk(x, 2, dim=-1)
        qkv_c = torch.einsum('btf,hfca->bhtca', x_c, self.w_qkv_c)
        qkv_p = torch.einsum('btf,hfca->bhtca', x_p, self.w_qkv_p)
        q_c, k_c, v_c = [c.squeeze(dim=3) for c in torch.chunk(qkv_c, 3, dim=3)
            ]
        q_p, k_p, v_p = [c.squeeze(dim=3) for c in torch.chunk(qkv_p, 3, dim=3)
            ]
        q = torch.cat([q_c, q_p], dim=-1) * self.scaling_factor
        k = torch.cat([k_c, k_p], dim=-1)
        v = torch.cat([v_c, v_p], dim=-1)
        dots = torch.einsum('bhqa,bhka->bhqk', q, k)
        if mask is not None:
            dots.data.masked_fill_(~mask[:, None, None, :], -float('inf'))
        probs = F.softmax(dots, dim=-1)
        probs = self.dropout(probs)
        o = torch.einsum('bhqk,bhka->bhqa', probs, v)
        o_c, o_p = torch.chunk(o, 2, dim=-1)
        out_c = torch.einsum('bhta,haf->btf', o_c, self.w_o_c)
        out_p = torch.einsum('bhta,haf->btf', o_p, self.w_o_p)
        return out_c, out_p


class PartitionedReLU(nn.ReLU):

    def forward(self, x):
        if isinstance(x, tuple):
            x_c, x_p = x
        else:
            x_c, x_p = torch.chunk(x, 2, dim=-1)
        return super().forward(x_c), super().forward(x_p)


class PartitionedTransformerEncoderLayerNew(nn.Module):

    def __init__(self, d_model, n_head, d_qkv, d_ff, ff_dropout=0.1,
        residual_dropout=0.1, attention_dropout=0.1, activation=
        PartitionedReLU()):
        super().__init__()
        self.self_attn = PartitionedMultiHeadAttention(d_model, n_head,
            d_qkv, attention_dropout=attention_dropout)
        self.linear1 = PartitionedLinear(d_model, d_ff)
        self.ff_dropout = FeatureDropout(ff_dropout)
        self.linear2 = PartitionedLinear(d_ff, d_model)
        self.norm_attn = nn.LayerNorm(d_model)
        self.norm_ff = nn.LayerNorm(d_model)
        self.residual_dropout_attn = FeatureDropout(residual_dropout)
        self.residual_dropout_ff = FeatureDropout(residual_dropout)
        self.activation = activation

    def forward(self, input_0):
        primals_2 = self.self_attn.w_qkv_c
        primals_3 = self.self_attn.w_qkv_p
        primals_4 = self.self_attn.w_o_c
        primals_5 = self.self_attn.w_o_p
        primals_8 = self.linear1.linear_c.weight
        primals_9 = self.linear1.linear_c.bias
        primals_10 = self.linear1.linear_p.weight
        primals_11 = self.linear1.linear_p.bias
        primals_12 = self.linear2.linear_c.weight
        primals_13 = self.linear2.linear_c.bias
        primals_14 = self.linear2.linear_p.weight
        primals_15 = self.linear2.linear_p.bias
        primals_6 = self.norm_attn.weight
        primals_7 = self.norm_attn.bias
        primals_16 = self.norm_ff.weight
        primals_17 = self.norm_ff.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17])
        return output[0]


Measured latency_ms: 0.021734