# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_7/inductor_cache/cc/cccjs22xobelgxtqlsn2fibmbazwulpl6qiesp7clmtct5t76w6i.py
# Topologically Sorted Source Nodes: [qkv_c], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   qkv_c => clone
# Graph fragment:
#   %clone : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%permute_3,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_0 = async_compile.triton('triton_poi_fused_clone_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/va/cva5gwn5lddb4hdqcni22rre3lrnt4hodmwd6zzu7u23zcobkg5i.py
# Topologically Sorted Source Nodes: [cat, q], Original ATen: [aten.cat, aten.mul]
# Source node to ATen node mapping:
#   cat => cat
#   q => mul
# Graph fragment:
#   %cat : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%squeeze, %squeeze_3], -1), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%cat, 0.5), kwargs = {})
triton_poi_fused_cat_mul_1 = async_compile.triton('triton_poi_fused_cat_mul_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_cat_mul_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    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
    tmp7 = tl.full([1], 4, tl.int64)
    tmp8 = tmp0 < tmp7
    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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/q4/cq4j3evfcbzbqvsc5o6spd3cwbk5ruwxtlfpvyrijy74rzhdizzf.py
# Topologically Sorted Source Nodes: [k], Original ATen: [aten.cat]
# Source node to ATen node mapping:
#   k => cat_1
# Graph fragment:
#   %cat_1 : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%squeeze_1, %squeeze_4], -1), kwargs = {})
triton_poi_fused_cat_2 = async_compile.triton('triton_poi_fused_cat_2', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_cat_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    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
    tmp7 = tl.full([1], 4, tl.int64)
    tmp8 = tmp0 < tmp7
    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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/s4/cs472yivvl3yzse325afzknsz7ua5dqrqzmwls3lwujk3hte6xkl.py
# Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   probs => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%view_11, [-1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_11, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_3 = async_compile.triton('triton_poi_fused__softmax_3', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/zh/czh6tw7ngffcygnivwvcjex5edxy3ms4t27ymyn2hemxlpspxzq7.py
# Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   probs => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [-1], True), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_4 = async_compile.triton('triton_poi_fused__softmax_4', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/wy/cwyd2c5eqe6dmcriegfsxxijhdetgyb5fhlqse4jkwrdzjzz4yra.py
# Topologically Sorted Source Nodes: [v], Original ATen: [aten.cat]
# Source node to ATen node mapping:
#   v => cat_2
# Graph fragment:
#   %cat_2 : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%squeeze_2, %squeeze_5], -1), kwargs = {})
triton_poi_fused_cat_5 = async_compile.triton('triton_poi_fused_cat_5', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_cat_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    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
    tmp7 = tl.full([1], 4, tl.int64)
    tmp8 = tmp0 < tmp7
    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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/rb/crbo7mnyz6jhctfcs6irltofws4absfehq57gbubuwmkgqremvir.py
# Topologically Sorted Source Nodes: [out_c], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   out_c => clone_3
# Graph fragment:
#   %clone_3 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%permute_22,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_6 = async_compile.triton('triton_poi_fused_clone_6', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[32, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/uf/cufwzthblw5bpxm6to23u5x5pyxdqityp5l4pgpwkcw24uzkh5ok.py
# Topologically Sorted Source Nodes: [out_c], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   out_c => clone_4
# Graph fragment:
#   %clone_4 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%permute_23,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_7 = async_compile.triton('triton_poi_fused_clone_7', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/in/cinchtemkwlurwioe377jflj2qj5ijghnp4kjugwuldc3qsv4n6b.py
# Topologically Sorted Source Nodes: [out_p], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   out_p => clone_5
# Graph fragment:
#   %clone_5 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%permute_27,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_8 = async_compile.triton('triton_poi_fused_clone_8', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[32, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_8', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/pw/cpwq2dftl7mquhip6p5ogkguqiqaywd2dfdf3vppi43r3xnef24d.py
# Topologically Sorted Source Nodes: [residual, add], Original ATen: [aten.cat, aten.add]
# Source node to ATen node mapping:
#   add => add
#   residual => cat_3
# Graph fragment:
#   %cat_3 : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%view_19, %view_23], -1), kwargs = {})
#   %add : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_1, %cat_3), kwargs = {})
triton_poi_fused_add_cat_9 = async_compile.triton('triton_poi_fused_add_cat_9', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_cat_9', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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
    tmp2 = tl.full([1], 0, tl.int64)
    tmp3 = tmp1 >= tmp2
    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
    tmp8 = tl.full([1], 4, tl.int64)
    tmp9 = tmp1 < tmp8
    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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/nn/cnnxhu2nhctulajy3rzg5wf2f3gd62kwlmtnwu5433qpihin4y26.py
# Topologically Sorted Source Nodes: [x], Original ATen: [aten.native_layer_norm]
# Source node to ATen node mapping:
#   x => add_1, rsqrt, var_mean
# Graph fragment:
#   %var_mean : [num_users=2] = call_function[target=torch.ops.aten.var_mean.correction](args = (%add, [2]), kwargs = {correction: 0, keepdim: True})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%getitem_10, 1e-05), kwargs = {})
#   %rsqrt : [num_users=1] = call_function[target=torch.ops.aten.rsqrt.default](args = (%add_1,), kwargs = {})
triton_poi_fused_native_layer_norm_10 = async_compile.triton('triton_poi_fused_native_layer_norm_10', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_native_layer_norm_10', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/73/c73z2hfes5izl473wn57vaku4rt2ae7swkdamlriywh5x5xt7g3z.py
# Topologically Sorted Source Nodes: [x], Original ATen: [aten.native_layer_norm]
# Source node to ATen node mapping:
#   x => add_1, add_2, mul_1, mul_2, rsqrt, sub_1, var_mean
# Graph fragment:
#   %var_mean : [num_users=2] = call_function[target=torch.ops.aten.var_mean.correction](args = (%add, [2]), kwargs = {correction: 0, keepdim: True})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%getitem_10, 1e-05), kwargs = {})
#   %rsqrt : [num_users=1] = call_function[target=torch.ops.aten.rsqrt.default](args = (%add_1,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add, %getitem_11), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, %rsqrt), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_1, %primals_6), kwargs = {})
#   %add_2 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_2, %primals_7), kwargs = {})
triton_poi_fused_native_layer_norm_11 = async_compile.triton('triton_poi_fused_native_layer_norm_11', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_native_layer_norm_11', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/fh/cfhr5stscm2juerq4j7icwweho5x7pvy3hrm3un3lpvqdfbvvwdg.py
# Topologically Sorted Source Nodes: [out_c_1, x_c_2], Original ATen: [aten.add, aten.relu, aten.threshold_backward]
# Source node to ATen node mapping:
#   out_c_1 => add_3
#   x_c_2 => relu
# Graph fragment:
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_25, %primals_9), kwargs = {})
#   %relu : [num_users=2] = call_function[target=torch.ops.aten.relu.default](args = (%add_3,), kwargs = {})
#   %le_1 : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%relu, 0), kwargs = {})
triton_poi_fused_add_relu_threshold_backward_12 = async_compile.triton('triton_poi_fused_add_relu_threshold_backward_12', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[32], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*i1', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_relu_threshold_backward_12', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@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)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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)
        # Topologically Sorted Source Nodes: [qkv_c], Original ATen: [aten.clone]
        stream0 = get_raw_stream(0)
        triton_poi_fused_clone_0.run(primals_2, buf0, 48, grid=grid(48), stream=stream0)
        del primals_2
        buf1 = empty_strided_cuda((1, 16, 24), (384, 24, 1), torch.float32)
        # Topologically Sorted Source Nodes: [qkv_c], Original ATen: [aten.bmm]
        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  # reuse
        # Topologically Sorted Source Nodes: [qkv_p], Original ATen: [aten.clone]
        triton_poi_fused_clone_0.run(primals_3, buf2, 48, grid=grid(48), stream=stream0)
        del primals_3
        buf3 = empty_strided_cuda((1, 16, 24), (384, 24, 1), torch.float32)
        # Topologically Sorted Source Nodes: [qkv_p], Original ATen: [aten.bmm]
        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)
        # Topologically Sorted Source Nodes: [cat, q], Original ATen: [aten.cat, aten.mul]
        triton_poi_fused_cat_mul_1.run(buf1, buf3, buf4, 256, grid=grid(256), stream=stream0)
        buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [k], Original ATen: [aten.cat]
        triton_poi_fused_cat_2.run(buf1, buf3, buf5, 256, grid=grid(256), stream=stream0)
        buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [dots], Original ATen: [aten.bmm]
        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)
        # Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_3.run(buf6, buf7, 256, grid=grid(256), stream=stream0)
        buf8 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0); del buf6  # reuse
        # Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_4.run(buf7, buf8, 256, grid=grid(256), stream=stream0)
        buf9 = buf7; del buf7  # reuse
        # Topologically Sorted Source Nodes: [v], Original ATen: [aten.cat]
        triton_poi_fused_cat_5.run(buf1, buf3, buf9, 256, grid=grid(256), stream=stream0)
        del buf1
        del buf3
        buf10 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [o], Original ATen: [aten.bmm]
        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)
        # Topologically Sorted Source Nodes: [out_c], Original ATen: [aten.clone]
        triton_poi_fused_clone_6.run(buf10, buf11, 32, 4, grid=grid(32, 4), stream=stream0)
        buf12 = empty_strided_cuda((2, 4, 2, 1, 1), (8, 2, 1, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_c], Original ATen: [aten.clone]
        triton_poi_fused_clone_7.run(primals_4, buf12, 16, grid=grid(16), stream=stream0)
        del primals_4
        buf13 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_c], Original ATen: [aten.bmm]
        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)
        # Topologically Sorted Source Nodes: [out_p], Original ATen: [aten.clone]
        triton_poi_fused_clone_8.run(buf10, buf14, 32, 4, grid=grid(32, 4), stream=stream0)
        del buf10
        buf15 = empty_strided_cuda((2, 4, 2, 1, 1), (8, 2, 1, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_p], Original ATen: [aten.clone]
        triton_poi_fused_clone_7.run(primals_5, buf15, 16, grid=grid(16), stream=stream0)
        del primals_5
        buf16 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_p], Original ATen: [aten.bmm]
        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)
        # Topologically Sorted Source Nodes: [residual, add], Original ATen: [aten.cat, aten.add]
        triton_poi_fused_add_cat_9.run(primals_1, buf13, buf16, buf17, 64, grid=grid(64), stream=stream0)
        buf18 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf19 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        # Topologically Sorted Source Nodes: [x], Original ATen: [aten.native_layer_norm]
        triton_poi_fused_native_layer_norm_10.run(buf17, buf18, buf19, 16, grid=grid(16), stream=stream0)
        buf20 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x], Original ATen: [aten.native_layer_norm]
        triton_poi_fused_native_layer_norm_11.run(buf17, buf18, buf19, primals_6, primals_7, buf20, 64, grid=grid(64), stream=stream0)
        del primals_7
        buf21 = reinterpret_tensor(buf16, (16, 2), (2, 1), 0); del buf16  # reuse
        # Topologically Sorted Source Nodes: [out_c_1], Original ATen: [aten.mm]
        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  # reuse
        # Topologically Sorted Source Nodes: [out_p_1], Original ATen: [aten.mm]
        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  # reuse
        buf32 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.bool)
        # Topologically Sorted Source Nodes: [out_c_1, x_c_2], Original ATen: [aten.add, aten.relu, aten.threshold_backward]
        triton_poi_fused_add_relu_threshold_backward_12.run(buf23, primals_9, buf32, 32, grid=grid(32), stream=stream0)
        del primals_9
        buf24 = empty_strided_cuda((16, 2), (2, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_c_2], Original ATen: [aten.addmm]
        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  # reuse
        buf31 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.bool)
        # Topologically Sorted Source Nodes: [out_p_1, x_p_2], Original ATen: [aten.add, aten.relu, aten.threshold_backward]
        triton_poi_fused_add_relu_threshold_backward_12.run(buf25, primals_11, buf31, 32, grid=grid(32), stream=stream0)
        del primals_11
        buf26 = empty_strided_cuda((16, 2), (2, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out_p_2], Original ATen: [aten.addmm]
        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)
        # Topologically Sorted Source Nodes: [residual_2, add_1], Original ATen: [aten.cat, aten.add]
        triton_poi_fused_add_cat_9.run(buf20, buf24, buf26, buf27, 64, grid=grid(64), stream=stream0)
        del buf24
        del buf26
        buf28 = buf19; del buf19  # reuse
        buf29 = buf18; del buf18  # reuse
        # Topologically Sorted Source Nodes: [x_1], Original ATen: [aten.native_layer_norm]
        triton_poi_fused_native_layer_norm_10.run(buf27, buf28, buf29, 16, grid=grid(16), stream=stream0)
        buf30 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x_1], Original ATen: [aten.native_layer_norm]
        triton_poi_fused_native_layer_norm_11.run(buf27, buf28, buf29, primals_16, primals_17, buf30, 64, grid=grid(64), stream=stream0)
        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), )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 2, 3, 2), (12, 6, 2, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 2, 3, 2), (12, 6, 2, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 2, 2), (4, 2, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 2, 2), (4, 2, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((2, 2), (2, 1), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((2, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((2, 2), (2, 1), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((2, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_12 = rand_strided((2, 2), (2, 1), device='cuda:0', dtype=torch.float32)
    primals_13 = rand_strided((2, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_14 = rand_strided((2, 2), (2, 1), device='cuda:0', dtype=torch.float32)
    primals_15 = rand_strided((2, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_16 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_17 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    fn = lambda: 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 print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import math
import torch
import torch.nn as nn
import torch.nn.functional as F


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 PartitionedTransformerEncoderLayer(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, x, mask=None):
        residual = self.self_attn(x, mask=mask)
        residual = torch.cat(residual, dim=-1)
        residual = self.residual_dropout_attn(residual)
        x = self.norm_attn(x + residual)
        residual = self.linear2(self.ff_dropout(self.activation(self.
            linear1(x))))
        residual = torch.cat(residual, dim=-1)
        residual = self.residual_dropout_ff(residual)
        x = self.norm_ff(x + residual)
        return x


def get_inputs():
    return [torch.rand([4, 4, 4])]


def get_init_inputs():
    return [[], {'d_model': 4, 'n_head': 4, 'd_qkv': 4, 'd_ff': 4}]

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]
