# 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/xg/cxg3op264zx2ec3atkmjwmld6htg2wdbd2inqitp272jkpjbeazc.py
# Topologically Sorted Source Nodes: [mean, sub], Original ATen: [aten.mean, aten.sub]
# Source node to ATen node mapping:
#   mean => mean
#   sub => sub
# Graph fragment:
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%primals_2, [1], True), kwargs = {})
#   %sub : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_2, %mean), kwargs = {})
triton_poi_fused_mean_sub_0 = async_compile.triton('triton_poi_fused_mean_sub_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=[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_mean_sub_0', '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_mean_sub_0(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
    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 = 4.0
    tmp9 = tmp7 / tmp8
    tmp10 = tmp0 - tmp9
    tl.store(out_ptr0 + (x2), tmp10, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/wt/cwtjktk4v5m5ngsotzjrgpjr5lqpe5igmhuag6vyiundx6av66ev.py
# Topologically Sorted Source Nodes: [pow_1, variance, add, rsqrt, x, mul_2, x_1], Original ATen: [aten.pow, aten.mean, aten.add, aten.rsqrt, aten.mul]
# Source node to ATen node mapping:
#   add => add
#   mul_2 => mul_2
#   pow_1 => pow_1
#   rsqrt => rsqrt
#   variance => mean_1
#   x => mul_1
#   x_1 => add_1
# Graph fragment:
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub, 2), kwargs = {})
#   %mean_1 : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%pow_1, [1], True), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mean_1, 1e-05), kwargs = {})
#   %rsqrt : [num_users=1] = call_function[target=torch.ops.aten.rsqrt.default](args = (%add,), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %rsqrt), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_1, %view), kwargs = {})
#   %add_1 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_2, %view_1), kwargs = {})
triton_poi_fused_add_mean_mul_pow_rsqrt_1 = async_compile.triton('triton_poi_fused_add_mean_mul_pow_rsqrt_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=[16], 
    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_mean_mul_pow_rsqrt_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 7, '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_mean_mul_pow_rsqrt_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    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')
    tmp3 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = 4.0
    tmp13 = tmp11 / tmp12
    tmp14 = 1e-05
    tmp15 = tmp13 + tmp14
    tmp16 = libdevice.rsqrt(tmp15)
    tmp17 = tmp0 * tmp16
    tmp19 = tmp17 * tmp18
    tmp21 = tmp19 + tmp20
    tl.store(out_ptr0 + (x2), tmp21, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/oo/coogemgs54co4zzjiz5e42moigwxaaergq27tc3zpfcc5c7qqnck.py
# Topologically Sorted Source Nodes: [add_2], Original ATen: [aten.add]
# Source node to ATen node mapping:
#   add_2 => add_2
# Graph fragment:
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_2, %unsqueeze_4), kwargs = {})
triton_poi_fused_add_2 = async_compile.triton('triton_poi_fused_add_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=[16], 
    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_2', '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_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    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_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(out_ptr0 + (x2), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/x3/cx3gzgdgx6jox7zudrijyyoykp2qgqojqifh2yoedw5bx55f3564.py
# Topologically Sorted Source Nodes: [conv1d_1], Original ATen: [aten.convolution]
# Source node to ATen node mapping:
#   conv1d_1 => convolution_1
# Graph fragment:
#   %convolution_1 : [num_users=1] = call_function[target=torch.ops.aten.convolution.default](args = (%add_1, %primals_7, %primals_8, [1], [0], [1], False, [0], 1), kwargs = {})
triton_poi_fused_convolution_3 = async_compile.triton('triton_poi_fused_convolution_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=[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_convolution_3', '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_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 4)
    tmp0 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + (x2), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/nl/cnlnde635pyu3eqmt5u7wzrv3vysimazdorymdlebg56ag6urzpn.py
# Topologically Sorted Source Nodes: [pos_score], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   pos_score => clone
# Graph fragment:
#   %clone : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%expand_2,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_4 = async_compile.triton('triton_poi_fused_clone_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=[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_clone_4', '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_clone_4(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
    x3 = xindex % 16
    x1 = (xindex // 4) % 4
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(out_ptr0 + (x4), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/pl/cpl2os2baezcuxqem5cyv7oj3x2ys5dgak35b3qnahuoabofjbs4.py
# Topologically Sorted Source Nodes: [attn_mask, eq], Original ATen: [aten.mul, aten.eq]
# Source node to ATen node mapping:
#   attn_mask => mul
#   eq => eq
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze, %unsqueeze_1), kwargs = {})
#   %eq : [num_users=2] = call_function[target=torch.ops.aten.eq.Scalar](args = (%mul, 0), kwargs = {})
triton_poi_fused_eq_mul_5 = async_compile.triton('triton_poi_fused_eq_mul_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=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i1', 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_eq_mul_5', '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_eq_mul_5(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
    tmp0 = tl.load(in_ptr0 + (x0), xmask)
    tmp1 = tmp0 * tmp0
    tmp2 = 0.0
    tmp3 = tmp1 == tmp2
    tl.store(out_ptr0 + (x0), tmp3, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/o6/co6v4qtv32xzb26e7gje5yjfnymszcstfkmngqffy23qe7b4v535.py
# Topologically Sorted Source Nodes: [add_4, score, score_1, attn_map], Original ATen: [aten.add, aten.div, aten.masked_fill, aten._softmax]
# Source node to ATen node mapping:
#   add_4 => add_4
#   attn_map => amax, exp, sub_2, sum_1
#   score => div
#   score_1 => full_default_1, where
# Graph fragment:
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_8, %view_13), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_4, 2.0), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], -10000.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq, %full_default_1, %div), kwargs = {})
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%where, [-1], True), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%where, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [-1], True), kwargs = {})
triton_poi_fused__softmax_add_div_masked_fill_6 = async_compile.triton('triton_poi_fused__softmax_add_div_masked_fill_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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*i1', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_add_div_masked_fill_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 6, '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_add_div_masked_fill_6(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 16
    x5 = xindex
    x0 = xindex % 4
    x1 = (xindex // 4) % 4
    x2 = (xindex // 16)
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last').to(tl.int1)
    tmp1 = tl.load(in_ptr1 + (4*x3), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (1 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr1 + (2 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp30 = tl.load(in_ptr1 + (3 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp2 = x5 % 2
    tmp3 = tl.full([1], 0, tl.int64)
    tmp4 = tmp2 >= tmp3
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp2 < tmp5
    tmp7 = 0.0
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tmp2 >= tmp5
    tmp11 = tl.full([1], 2, tl.int64)
    tmp12 = tmp2 < tmp11
    tmp13 = tl.load(in_ptr2 + (2 + (4*x1) + (4*((4 + x0) // 8)) + (16*x2) + (16*((4 + x0 + (8*x1)) // 32)) + (x0 // 2)), tmp10 & xmask, eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp6, tmp9, tmp13)
    tmp15 = tmp1 + tmp14
    tmp16 = 0.5
    tmp17 = tmp15 * tmp16
    tmp18 = -10000.0
    tmp19 = tl.where(tmp0, tmp18, tmp17)
    tmp21 = tmp20 + tmp14
    tmp22 = tmp21 * tmp16
    tmp23 = tl.where(tmp0, tmp18, tmp22)
    tmp24 = triton_helpers.maximum(tmp19, tmp23)
    tmp26 = tmp25 + tmp14
    tmp27 = tmp26 * tmp16
    tmp28 = tl.where(tmp0, tmp18, tmp27)
    tmp29 = triton_helpers.maximum(tmp24, tmp28)
    tmp31 = tmp30 + tmp14
    tmp32 = tmp31 * tmp16
    tmp33 = tl.where(tmp0, tmp18, tmp32)
    tmp34 = triton_helpers.maximum(tmp29, tmp33)
    tmp35 = tmp19 - tmp34
    tmp36 = tl_math.exp(tmp35)
    tmp37 = tmp23 - tmp34
    tmp38 = tl_math.exp(tmp37)
    tmp39 = tmp36 + tmp38
    tmp40 = tmp28 - tmp34
    tmp41 = tl_math.exp(tmp40)
    tmp42 = tmp39 + tmp41
    tmp43 = tmp33 - tmp34
    tmp44 = tl_math.exp(tmp43)
    tmp45 = tmp42 + tmp44
    tl.store(out_ptr0 + (x5), tmp34, xmask)
    tl.store(out_ptr1 + (x5), tmp45, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/x7/cx732s7r6nozdnf25fzb6ydudqsspp2rkzemtm74ejhie4pmyj5q.py
# Topologically Sorted Source Nodes: [add_4, score, score_1, attn_map], Original ATen: [aten.add, aten.div, aten.masked_fill, aten._softmax]
# Source node to ATen node mapping:
#   add_4 => add_4
#   attn_map => div_1, exp, sub_2
#   score => div
#   score_1 => full_default_1, where
# Graph fragment:
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_8, %view_13), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_4, 2.0), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], -10000.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq, %full_default_1, %div), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%where, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %div_1 : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_add_div_masked_fill_7 = async_compile.triton('triton_poi_fused__softmax_add_div_masked_fill_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=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*i1', 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__softmax_add_div_masked_fill_7', '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_add_div_masked_fill_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x4 = (xindex // 4) % 16
    x5 = xindex % 64
    x7 = xindex
    x1 = (xindex // 4) % 4
    x2 = (xindex // 16) % 4
    x3 = (xindex // 64)
    x8 = (xindex // 4)
    tmp0 = tl.load(in_ptr0 + (x4), xmask, eviction_policy='evict_last').to(tl.int1)
    tmp1 = tl.load(in_ptr1 + (x5), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr3 + (x8), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr4 + (x8), xmask, eviction_policy='evict_last')
    tmp2 = ((x7 // 4) % 4) % 2
    tmp3 = tl.full([1], 0, tl.int64)
    tmp4 = tmp2 >= tmp3
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp2 < tmp5
    tmp7 = 0.0
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tmp2 >= tmp5
    tmp11 = tl.full([1], 2, tl.int64)
    tmp12 = tmp2 < tmp11
    tmp13 = tl.load(in_ptr2 + (2 + (4*x2) + (4*((4 + x1) // 8)) + (16*x3) + (16*((4 + x1 + (8*x2)) // 32)) + (x1 // 2)), tmp10 & xmask, eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp6, tmp9, tmp13)
    tmp15 = tmp1 + tmp14
    tmp16 = 0.5
    tmp17 = tmp15 * tmp16
    tmp18 = -10000.0
    tmp19 = tl.where(tmp0, tmp18, tmp17)
    tmp21 = tmp19 - tmp20
    tmp22 = tl_math.exp(tmp21)
    tmp24 = tmp22 / tmp23
    tl.store(out_ptr0 + (x7), tmp24, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/vh/cvhocte3gy6p757vqvej2eom4vg2n7pm7zhe4kdmxzoii7mc7jtz.py
# Topologically Sorted Source Nodes: [context], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   context => clone_2
# Graph fragment:
#   %clone_2 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%expand_4,), 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=[64], 
    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_clone_8', '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_clone_8(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 16
    x1 = (xindex // 4) % 4
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x4), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/te/cteo6bmhgrla22ee3gyumnmjwqwo4odzuud32mk3w4ci6qajnqqo.py
# Topologically Sorted Source Nodes: [x_3], Original ATen: [aten.convolution]
# Source node to ATen node mapping:
#   x_3 => convolution_4
# Graph fragment:
#   %convolution_4 : [num_users=1] = call_function[target=torch.ops.aten.convolution.default](args = (%view_17, %primals_15, %primals_16, [1], [0], [1], False, [0], 1), kwargs = {})
triton_poi_fused_convolution_9 = async_compile.triton('triton_poi_fused_convolution_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: '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_convolution_9', '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_convolution_9(in_out_ptr0, in_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 // 16)
    tmp0 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + (x2), tmp2, 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 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, ), (1, ))
    assert_size_stride(primals_4, (4, ), (1, ))
    assert_size_stride(primals_5, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_6, (4, ), (1, ))
    assert_size_stride(primals_7, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_8, (4, ), (1, ))
    assert_size_stride(primals_9, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_10, (4, ), (1, ))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_13, (4, 1), (1, 1))
    assert_size_stride(primals_14, (4, 1), (1, 1))
    assert_size_stride(primals_15, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_16, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mean, sub], Original ATen: [aten.mean, aten.sub]
        stream0 = get_raw_stream(0)
        triton_poi_fused_mean_sub_0.run(primals_2, buf0, 16, grid=grid(16), stream=stream0)
        buf1 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pow_1, variance, add, rsqrt, x, mul_2, x_1], Original ATen: [aten.pow, aten.mean, aten.add, aten.rsqrt, aten.mul]
        triton_poi_fused_add_mean_mul_pow_rsqrt_1.run(buf0, primals_3, primals_4, buf1, 16, grid=grid(16), stream=stream0)
        del primals_3
        del primals_4
        # Topologically Sorted Source Nodes: [conv1d], Original ATen: [aten.convolution]
        buf2 = extern_kernels.convolution(buf1, primals_5, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf2, (1, 4, 4), (16, 4, 1))
        # Topologically Sorted Source Nodes: [conv1d_1], Original ATen: [aten.convolution]
        buf3 = extern_kernels.convolution(buf1, primals_7, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf3, (1, 4, 4), (16, 4, 1))
        # Topologically Sorted Source Nodes: [conv1d_2], Original ATen: [aten.convolution]
        buf4 = extern_kernels.convolution(buf1, primals_9, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf4, (1, 4, 4), (16, 4, 1))
        # Topologically Sorted Source Nodes: [conv1d_3], Original ATen: [aten.convolution]
        buf5 = extern_kernels.convolution(reinterpret_tensor(primals_11, (1, 4, 4), (16, 4, 1), 0), primals_12, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf5, (1, 4, 4), (16, 4, 1))
        buf6 = reinterpret_tensor(buf0, (1, 4, 1, 4), (16, 4, 4, 1), 0); del buf0  # reuse
        # Topologically Sorted Source Nodes: [add_2], Original ATen: [aten.add]
        triton_poi_fused_add_2.run(buf2, primals_6, primals_13, buf6, 16, grid=grid(16), stream=stream0)
        del primals_13
        buf7 = buf3; del buf3  # reuse
        # Topologically Sorted Source Nodes: [conv1d_1], Original ATen: [aten.convolution]
        triton_poi_fused_convolution_3.run(buf7, primals_8, 16, grid=grid(16), stream=stream0)
        del primals_8
        buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [content_score], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf6, (4, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf7, (4, 1, 4), (4, 0, 1), 0), out=buf8)
        buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pos_score], Original ATen: [aten.clone]
        triton_poi_fused_clone_4.run(buf2, primals_6, primals_14, buf9, 64, grid=grid(64), stream=stream0)
        del buf2
        del primals_14
        del primals_6
        buf10 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pos_score], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf5, (16, 1, 1), (1, 1, 1), 0), out=buf10)
        buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.bool)
        # Topologically Sorted Source Nodes: [attn_mask, eq], Original ATen: [aten.mul, aten.eq]
        triton_poi_fused_eq_mul_5.run(primals_1, buf11, 16, grid=grid(16), stream=stream0)
        del primals_1
        buf12 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf13 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        # Topologically Sorted Source Nodes: [add_4, score, score_1, attn_map], Original ATen: [aten.add, aten.div, aten.masked_fill, aten._softmax]
        triton_poi_fused__softmax_add_div_masked_fill_6.run(buf11, buf8, buf10, buf12, buf13, 64, grid=grid(64), stream=stream0)
        buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add_4, score, score_1, attn_map], Original ATen: [aten.add, aten.div, aten.masked_fill, aten._softmax]
        triton_poi_fused__softmax_add_div_masked_fill_7.run(buf11, buf8, buf10, buf12, buf13, buf14, 256, grid=grid(256), stream=stream0)
        del buf10
        del buf12
        buf15 = reinterpret_tensor(buf8, (4, 4, 1, 4), (16, 4, 4, 1), 0); del buf8  # reuse
        # Topologically Sorted Source Nodes: [context], Original ATen: [aten.clone]
        triton_poi_fused_clone_8.run(buf4, primals_10, buf15, 64, grid=grid(64), stream=stream0)
        del buf4
        del primals_10
        buf16 = reinterpret_tensor(buf13, (16, 1, 4), (4, 4, 1), 0); del buf13  # reuse
        # Topologically Sorted Source Nodes: [context], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf15, (16, 1, 4), (4, 0, 1), 0), reinterpret_tensor(buf14, (16, 4, 4), (16, 4, 1), 0), out=buf16)
        # Topologically Sorted Source Nodes: [x_3], Original ATen: [aten.convolution]
        buf17 = extern_kernels.convolution(reinterpret_tensor(buf16, (1, 4, 16), (64, 16, 1), 0), primals_15, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf17, (1, 4, 16), (64, 16, 1))
        buf18 = buf17; del buf17  # reuse
        # Topologically Sorted Source Nodes: [x_3], Original ATen: [aten.convolution]
        triton_poi_fused_convolution_9.run(buf18, primals_16, 64, grid=grid(64), stream=stream0)
        del primals_16
    return (buf18, primals_2, primals_5, primals_7, primals_9, primals_12, primals_15, buf1, reinterpret_tensor(primals_11, (1, 4, 4), (16, 4, 1), 0), buf11, buf14, reinterpret_tensor(buf16, (1, 4, 16), (64, 16, 1), 0), reinterpret_tensor(buf15, (16, 4, 1), (4, 1, 4), 0), reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf5, (16, 1, 1), (1, 1, 1), 0), reinterpret_tensor(buf6, (4, 1, 4), (4, 4, 1), 0), reinterpret_tensor(buf7, (4, 4, 1), (4, 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, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 4, 1), (4, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((4, 4, 1), (4, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((4, 4, 1), (4, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_12 = rand_strided((4, 4, 1), (4, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_13 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_14 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_15 = rand_strided((4, 4, 1), (4, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_16 = 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])
    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.functional as F
import torch.nn as nn


class LayerNorm(nn.Module):

    def __init__(self, channels, eps=1e-05):
        super().__init__()
        self.channels = channels
        self.eps = eps
        self.gamma = nn.Parameter(torch.ones(channels))
        self.beta = nn.Parameter(torch.zeros(channels))

    def forward(self, x):
        mean = torch.mean(x, 1, keepdim=True)
        variance = torch.mean((x - mean) ** 2, 1, keepdim=True)
        x = (x - mean) * torch.rsqrt(variance + self.eps)
        x = x * self.gamma.view(1, -1, 1) + self.beta.view(1, -1, 1)
        return x


class RelativeMultiHeadAttention(nn.Module):

    def __init__(self, channels, num_heads, dropout):
        super(RelativeMultiHeadAttention, self).__init__()
        assert channels % num_heads == 0, 'd_model % num_heads should be zero.'
        self.channels = channels
        self.inner_channels = channels // num_heads
        self.num_heads = num_heads
        self.sqrt_dim = math.sqrt(channels)
        self.query_proj = nn.Conv1d(channels, channels, 1)
        self.key_proj = nn.Conv1d(channels, channels, 1)
        self.value_proj = nn.Conv1d(channels, channels, 1)
        self.pos_proj = nn.Conv1d(channels, channels, 1, bias=False)
        self.dropout = nn.Dropout(p=dropout)
        self.u_bias = nn.Parameter(torch.Tensor(self.num_heads, self.
            inner_channels))
        self.v_bias = nn.Parameter(torch.Tensor(self.num_heads, self.
            inner_channels))
        torch.nn.init.xavier_uniform_(self.u_bias)
        torch.nn.init.xavier_uniform_(self.v_bias)
        self.out_proj = nn.Conv1d(channels, channels, 1)

    def forward(self, query, key, value, pos_embedding, mask=None):
        B = value.size(0)
        query = self.query_proj(query).view(B, self.num_heads, self.
            inner_channels, -1)
        key = self.key_proj(key).view(B, self.num_heads, self.
            inner_channels, -1)
        value = self.value_proj(value).view(B, self.num_heads, self.
            inner_channels, -1)
        B_pos = pos_embedding.size(0)
        pos_emb = self.pos_proj(pos_embedding).view(B_pos, self.num_heads,
            self.inner_channels, -1)
        content_score = torch.matmul((query + self.u_bias[None, :, :, None]
            ).transpose(-1, -2), key)
        pos_score = torch.matmul((query + self.v_bias[None, :, :, None]).
            transpose(-1, -2), pos_emb)
        pos_score = self.rel_shift(pos_score)
        score = (content_score + pos_score) / self.sqrt_dim
        if mask is not None:
            score = score.masked_fill(mask == 0, -10000.0)
        attn_map = F.softmax(score, -1)
        attn = self.dropout(attn_map)
        context = torch.matmul(value, attn)
        context = context.contiguous().view(B, self.channels, -1)
        return self.out_proj(context)

    @staticmethod
    def rel_shift(x):
        B, H, T1, T2 = x.size()
        zero_pad = torch.zeros((B, H, T1, 1), device=x.device, dtype=x.dtype)
        x_padded = torch.cat([zero_pad, x], dim=-1)
        x_padded = x_padded.view(B, H, T2 + 1, T1)
        x = x_padded[:, :, 1:].view_as(x)[:, :, :, :T2 // 2 + 1]
        return x


class RelativeSelfAttentionLayer(nn.Module):

    def __init__(self, channels, n_heads, dropout):
        super(RelativeSelfAttentionLayer, self).__init__()
        self.norm = LayerNorm(channels)
        self.mha = RelativeMultiHeadAttention(channels, n_heads, dropout)
        self.dropout = nn.Dropout(dropout)

    def forward(self, x, pos_emb, x_mask):
        attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
        x = self.norm(x)
        x = self.mha(x, x, x, pos_emb, attn_mask)
        x = self.dropout(x)
        return x


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


def get_init_inputs():
    return [[], {'channels': 4, 'n_heads': 4, 'dropout': 0.5}]

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.functional as F
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_mean_sub_0(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
    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 = 4.0
    tmp9 = tmp7 / tmp8
    tmp10 = tmp0 - tmp9
    tl.store(out_ptr0 + x2, tmp10, xmask)


@triton.jit
def triton_poi_fused_add_mean_mul_pow_rsqrt_1(in_ptr0, in_ptr1, in_ptr2,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    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')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = 4.0
    tmp13 = tmp11 / tmp12
    tmp14 = 1e-05
    tmp15 = tmp13 + tmp14
    tmp16 = libdevice.rsqrt(tmp15)
    tmp17 = tmp0 * tmp16
    tmp19 = tmp17 * tmp18
    tmp21 = tmp19 + tmp20
    tl.store(out_ptr0 + x2, tmp21, xmask)


@triton.jit
def triton_poi_fused_add_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    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_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, xmask)


@triton.jit
def triton_poi_fused_clone_4(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
    x3 = xindex % 16
    x1 = xindex // 4 % 4
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(out_ptr0 + x4, tmp4, xmask)


@triton.jit
def triton_poi_fused_eq_mul_5(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
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tmp0 * tmp0
    tmp2 = 0.0
    tmp3 = tmp1 == tmp2
    tl.store(out_ptr0 + x0, tmp3, xmask)


@triton.jit
def triton_poi_fused__softmax_add_div_masked_fill_6(in_ptr0, in_ptr1,
    in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 16
    x5 = xindex
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last').to(tl
        .int1)
    tmp1 = tl.load(in_ptr1 + 4 * x3, xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (1 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr1 + (2 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp30 = tl.load(in_ptr1 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp2 = x5 % 2
    tl.full([1], 0, tl.int64)
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp2 < tmp5
    tmp7 = 0.0
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tmp2 >= tmp5
    tl.full([1], 2, tl.int64)
    tmp13 = tl.load(in_ptr2 + (2 + 4 * x1 + 4 * ((4 + x0) // 8) + 16 * x2 +
        16 * ((4 + x0 + 8 * x1) // 32) + x0 // 2), tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp6, tmp9, tmp13)
    tmp15 = tmp1 + tmp14
    tmp16 = 0.5
    tmp17 = tmp15 * tmp16
    tmp18 = -10000.0
    tmp19 = tl.where(tmp0, tmp18, tmp17)
    tmp21 = tmp20 + tmp14
    tmp22 = tmp21 * tmp16
    tmp23 = tl.where(tmp0, tmp18, tmp22)
    tmp24 = triton_helpers.maximum(tmp19, tmp23)
    tmp26 = tmp25 + tmp14
    tmp27 = tmp26 * tmp16
    tmp28 = tl.where(tmp0, tmp18, tmp27)
    tmp29 = triton_helpers.maximum(tmp24, tmp28)
    tmp31 = tmp30 + tmp14
    tmp32 = tmp31 * tmp16
    tmp33 = tl.where(tmp0, tmp18, tmp32)
    tmp34 = triton_helpers.maximum(tmp29, tmp33)
    tmp35 = tmp19 - tmp34
    tmp36 = tl_math.exp(tmp35)
    tmp37 = tmp23 - tmp34
    tmp38 = tl_math.exp(tmp37)
    tmp39 = tmp36 + tmp38
    tmp40 = tmp28 - tmp34
    tmp41 = tl_math.exp(tmp40)
    tmp42 = tmp39 + tmp41
    tmp43 = tmp33 - tmp34
    tmp44 = tl_math.exp(tmp43)
    tmp45 = tmp42 + tmp44
    tl.store(out_ptr0 + x5, tmp34, xmask)
    tl.store(out_ptr1 + x5, tmp45, xmask)


@triton.jit
def triton_poi_fused__softmax_add_div_masked_fill_7(in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x4 = xindex // 4 % 16
    x5 = xindex % 64
    x7 = xindex
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    x8 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last').to(tl
        .int1)
    tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr3 + x8, xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr4 + x8, xmask, eviction_policy='evict_last')
    tmp2 = x7 // 4 % 4 % 2
    tl.full([1], 0, tl.int64)
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp2 < tmp5
    tmp7 = 0.0
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tmp2 >= tmp5
    tl.full([1], 2, tl.int64)
    tmp13 = tl.load(in_ptr2 + (2 + 4 * x2 + 4 * ((4 + x1) // 8) + 16 * x3 +
        16 * ((4 + x1 + 8 * x2) // 32) + x1 // 2), tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp6, tmp9, tmp13)
    tmp15 = tmp1 + tmp14
    tmp16 = 0.5
    tmp17 = tmp15 * tmp16
    tmp18 = -10000.0
    tmp19 = tl.where(tmp0, tmp18, tmp17)
    tmp21 = tmp19 - tmp20
    tmp22 = tl_math.exp(tmp21)
    tmp24 = tmp22 / tmp23
    tl.store(out_ptr0 + x7, tmp24, xmask)


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


@triton.jit
def triton_poi_fused_convolution_9(in_out_ptr0, in_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 // 16
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, 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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_13, (4, 1), (1, 1))
    assert_size_stride(primals_14, (4, 1), (1, 1))
    assert_size_stride(primals_15, (4, 4, 1), (4, 1, 1))
    assert_size_stride(primals_16, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mean_sub_0[grid(16)](primals_2, buf0, 16, XBLOCK=
            16, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_mean_mul_pow_rsqrt_1[grid(16)](buf0, primals_3,
            primals_4, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_3
        del primals_4
        buf2 = extern_kernels.convolution(buf1, primals_5, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf2, (1, 4, 4), (16, 4, 1))
        buf3 = extern_kernels.convolution(buf1, primals_7, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf3, (1, 4, 4), (16, 4, 1))
        buf4 = extern_kernels.convolution(buf1, primals_9, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf4, (1, 4, 4), (16, 4, 1))
        buf5 = extern_kernels.convolution(reinterpret_tensor(primals_11, (1,
            4, 4), (16, 4, 1), 0), primals_12, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf5, (1, 4, 4), (16, 4, 1))
        buf6 = reinterpret_tensor(buf0, (1, 4, 1, 4), (16, 4, 4, 1), 0)
        del buf0
        triton_poi_fused_add_2[grid(16)](buf2, primals_6, primals_13, buf6,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_13
        buf7 = buf3
        del buf3
        triton_poi_fused_convolution_3[grid(16)](buf7, primals_8, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del primals_8
        buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf6, (4, 4, 1), (4, 1, 0), 0
            ), reinterpret_tensor(buf7, (4, 1, 4), (4, 0, 1), 0), out=buf8)
        buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_4[grid(64)](buf2, primals_6, primals_14,
            buf9, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf2
        del primals_14
        del primals_6
        buf10 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 
            0), reinterpret_tensor(buf5, (16, 1, 1), (1, 1, 1), 0), out=buf10)
        buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.bool)
        triton_poi_fused_eq_mul_5[grid(16)](primals_1, buf11, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del primals_1
        buf12 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf13 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        triton_poi_fused__softmax_add_div_masked_fill_6[grid(64)](buf11,
            buf8, buf10, buf12, buf13, 64, XBLOCK=64, num_warps=1, num_stages=1
            )
        buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_add_div_masked_fill_7[grid(256)](buf11,
            buf8, buf10, buf12, buf13, buf14, 256, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf10
        del buf12
        buf15 = reinterpret_tensor(buf8, (4, 4, 1, 4), (16, 4, 4, 1), 0)
        del buf8
        triton_poi_fused_clone_8[grid(64)](buf4, primals_10, buf15, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del buf4
        del primals_10
        buf16 = reinterpret_tensor(buf13, (16, 1, 4), (4, 4, 1), 0)
        del buf13
        extern_kernels.bmm(reinterpret_tensor(buf15, (16, 1, 4), (4, 0, 1),
            0), reinterpret_tensor(buf14, (16, 4, 4), (16, 4, 1), 0), out=buf16
            )
        buf17 = extern_kernels.convolution(reinterpret_tensor(buf16, (1, 4,
            16), (64, 16, 1), 0), primals_15, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf17, (1, 4, 16), (64, 16, 1))
        buf18 = buf17
        del buf17
        triton_poi_fused_convolution_9[grid(64)](buf18, primals_16, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_16
    return (buf18, primals_2, primals_5, primals_7, primals_9, primals_12,
        primals_15, buf1, reinterpret_tensor(primals_11, (1, 4, 4), (16, 4,
        1), 0), buf11, buf14, reinterpret_tensor(buf16, (1, 4, 16), (64, 16,
        1), 0), reinterpret_tensor(buf15, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0),
        reinterpret_tensor(buf5, (16, 1, 1), (1, 1, 1), 0),
        reinterpret_tensor(buf6, (4, 1, 4), (4, 4, 1), 0),
        reinterpret_tensor(buf7, (4, 4, 1), (4, 1, 4), 0))


class LayerNorm(nn.Module):

    def __init__(self, channels, eps=1e-05):
        super().__init__()
        self.channels = channels
        self.eps = eps
        self.gamma = nn.Parameter(torch.ones(channels))
        self.beta = nn.Parameter(torch.zeros(channels))

    def forward(self, x):
        mean = torch.mean(x, 1, keepdim=True)
        variance = torch.mean((x - mean) ** 2, 1, keepdim=True)
        x = (x - mean) * torch.rsqrt(variance + self.eps)
        x = x * self.gamma.view(1, -1, 1) + self.beta.view(1, -1, 1)
        return x


class RelativeMultiHeadAttention(nn.Module):

    def __init__(self, channels, num_heads, dropout):
        super(RelativeMultiHeadAttention, self).__init__()
        assert channels % num_heads == 0, 'd_model % num_heads should be zero.'
        self.channels = channels
        self.inner_channels = channels // num_heads
        self.num_heads = num_heads
        self.sqrt_dim = math.sqrt(channels)
        self.query_proj = nn.Conv1d(channels, channels, 1)
        self.key_proj = nn.Conv1d(channels, channels, 1)
        self.value_proj = nn.Conv1d(channels, channels, 1)
        self.pos_proj = nn.Conv1d(channels, channels, 1, bias=False)
        self.dropout = nn.Dropout(p=dropout)
        self.u_bias = nn.Parameter(torch.Tensor(self.num_heads, self.
            inner_channels))
        self.v_bias = nn.Parameter(torch.Tensor(self.num_heads, self.
            inner_channels))
        torch.nn.init.xavier_uniform_(self.u_bias)
        torch.nn.init.xavier_uniform_(self.v_bias)
        self.out_proj = nn.Conv1d(channels, channels, 1)

    def forward(self, query, key, value, pos_embedding, mask=None):
        B = value.size(0)
        query = self.query_proj(query).view(B, self.num_heads, self.
            inner_channels, -1)
        key = self.key_proj(key).view(B, self.num_heads, self.
            inner_channels, -1)
        value = self.value_proj(value).view(B, self.num_heads, self.
            inner_channels, -1)
        B_pos = pos_embedding.size(0)
        pos_emb = self.pos_proj(pos_embedding).view(B_pos, self.num_heads,
            self.inner_channels, -1)
        content_score = torch.matmul((query + self.u_bias[None, :, :, None]
            ).transpose(-1, -2), key)
        pos_score = torch.matmul((query + self.v_bias[None, :, :, None]).
            transpose(-1, -2), pos_emb)
        pos_score = self.rel_shift(pos_score)
        score = (content_score + pos_score) / self.sqrt_dim
        if mask is not None:
            score = score.masked_fill(mask == 0, -10000.0)
        attn_map = F.softmax(score, -1)
        attn = self.dropout(attn_map)
        context = torch.matmul(value, attn)
        context = context.contiguous().view(B, self.channels, -1)
        return self.out_proj(context)

    @staticmethod
    def rel_shift(x):
        B, H, T1, T2 = x.size()
        zero_pad = torch.zeros((B, H, T1, 1), device=x.device, dtype=x.dtype)
        x_padded = torch.cat([zero_pad, x], dim=-1)
        x_padded = x_padded.view(B, H, T2 + 1, T1)
        x = x_padded[:, :, 1:].view_as(x)[:, :, :, :T2 // 2 + 1]
        return x


class RelativeSelfAttentionLayerNew(nn.Module):

    def __init__(self, channels, n_heads, dropout):
        super(RelativeSelfAttentionLayerNew, self).__init__()
        self.norm = LayerNorm(channels)
        self.mha = RelativeMultiHeadAttention(channels, n_heads, dropout)
        self.dropout = nn.Dropout(dropout)

    def forward(self, input_0, input_1, input_2):
        primals_3 = self.norm.gamma
        primals_4 = self.norm.beta
        primals_13 = self.mha.u_bias
        primals_14 = self.mha.v_bias
        primals_5 = self.mha.query_proj.weight
        primals_6 = self.mha.query_proj.bias
        primals_7 = self.mha.key_proj.weight
        primals_8 = self.mha.key_proj.bias
        primals_9 = self.mha.value_proj.weight
        primals_10 = self.mha.value_proj.bias
        primals_12 = self.mha.pos_proj.weight
        primals_15 = self.mha.out_proj.weight
        primals_16 = self.mha.out_proj.bias
        primals_1 = input_0
        primals_2 = input_1
        primals_11 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16])
        return output[0]
