# 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_4/inductor_cache/da/cdagjo27gj7mwobx6n2o4xjkim6ocjodht5oelr4yz332bexu5n7.py
# Topologically Sorted Source Nodes: [sub, mask_1, query_for_score, query_for_score_1, softmax], Original ATen: [aten.rsub, aten.mul, aten.div, aten.add, aten._softmax]
# Source node to ATen node mapping:
#   mask_1 => mul
#   query_for_score => div
#   query_for_score_1 => add
#   softmax => amax, clone, exp, sub_1, sum_1
#   sub => sub
# Graph fragment:
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %unsqueeze), kwargs = {})
#   %mul : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, -10000.0), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%permute_3, 1.0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %mul), kwargs = {})
#   %clone : [num_users=2] = call_function[target=torch.ops.aten.clone.default](args = (%add,), kwargs = {memory_format: torch.contiguous_format})
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%clone, [-1], True), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%clone, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), 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_mul_rsub_0 = async_compile.triton('triton_poi_fused__softmax_add_div_mul_rsub_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: '*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_mul_rsub_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 9, '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_mul_rsub_0(in_ptr0, in_ptr1, in_ptr2, 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 % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (16*x1)), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + (4*x1), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (4 + x0 + (16*x1)), xmask)
    tmp13 = tl.load(in_ptr2 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (8 + x0 + (16*x1)), xmask)
    tmp21 = tl.load(in_ptr2 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr0 + (12 + x0 + (16*x1)), xmask)
    tmp29 = tl.load(in_ptr2 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tmp6 = tmp3 - tmp5
    tmp7 = -10000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp4 + tmp8
    tmp11 = tmp10 + tmp1
    tmp12 = tmp11 * tmp3
    tmp14 = tmp3 - tmp13
    tmp15 = tmp14 * tmp7
    tmp16 = tmp12 + tmp15
    tmp17 = triton_helpers.maximum(tmp9, tmp16)
    tmp19 = tmp18 + tmp1
    tmp20 = tmp19 * tmp3
    tmp22 = tmp3 - tmp21
    tmp23 = tmp22 * tmp7
    tmp24 = tmp20 + tmp23
    tmp25 = triton_helpers.maximum(tmp17, tmp24)
    tmp27 = tmp26 + tmp1
    tmp28 = tmp27 * tmp3
    tmp30 = tmp3 - tmp29
    tmp31 = tmp30 * tmp7
    tmp32 = tmp28 + tmp31
    tmp33 = triton_helpers.maximum(tmp25, tmp32)
    tmp34 = tmp9 - tmp33
    tmp35 = tl_math.exp(tmp34)
    tmp36 = tmp16 - tmp33
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp24 - tmp33
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tmp42 = tmp32 - tmp33
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp41 + tmp43
    tl.store(out_ptr0 + (x2), tmp33, xmask)
    tl.store(out_ptr1 + (x2), tmp44, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/wm/cwmk76q7cnp6r4ooshjnqn572hfr3p6ih7ndmrcltprhdaqttwfu.py
# Topologically Sorted Source Nodes: [sub, mask_1, query_for_score, query_for_score_1, softmax], Original ATen: [aten.rsub, aten.mul, aten.div, aten.add, aten._softmax]
# Source node to ATen node mapping:
#   mask_1 => mul
#   query_for_score => div
#   query_for_score_1 => add
#   softmax => clone, div_1, exp, sub_1
#   sub => sub
# Graph fragment:
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %unsqueeze), kwargs = {})
#   %mul : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, -10000.0), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%permute_3, 1.0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %mul), kwargs = {})
#   %clone : [num_users=2] = call_function[target=torch.ops.aten.clone.default](args = (%add,), kwargs = {memory_format: torch.contiguous_format})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%clone, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), 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_mul_rsub_1 = async_compile.triton('triton_poi_fused__softmax_add_div_mul_rsub_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, 4], tile_hint=TileHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32', 7: '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_mul_rsub_1', '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_mul_rsub_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 4
    y1 = (yindex // 4)
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + (4*x2) + (16*y1)), xmask & ymask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (y0), ymask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + (x2 + (4*y1)), xmask & ymask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + (y3), ymask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr4 + (y3), ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tmp6 = tmp3 - tmp5
    tmp7 = -10000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp4 + tmp8
    tmp11 = tmp9 - tmp10
    tmp12 = tl_math.exp(tmp11)
    tmp14 = tmp12 / tmp13
    tl.store(out_ptr0 + (x2 + (4*y3)), tmp14, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/xp/cxp3ouwpdhdlmipppq44wjaey2obmthzec7uqoddmpoigfmupxdx.py
# Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   matmul => clone_1
# Graph fragment:
#   %clone_1 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%expand_1,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_2 = async_compile.triton('triton_poi_fused_clone_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, 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_2', '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_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 4
    y1 = (yindex // 4)
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + (4*x2) + (16*y1)), xmask & ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + (4*y3)), tmp0, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/gf/cgfwbglhx6ga4elexo53qyxxhirj2h3x3ece2oayjv24wfpno4tg.py
# Topologically Sorted Source Nodes: [pooled_query_repeat, mixed_query_key_layer], Original ATen: [aten.repeat, aten.mul]
# Source node to ATen node mapping:
#   mixed_query_key_layer => mul_1
#   pooled_query_repeat => repeat
# Graph fragment:
#   %repeat : [num_users=2] = call_function[target=torch.ops.aten.repeat.default](args = (%view_10, [1, 4, 1]), kwargs = {})
#   %mul_1 : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_3, %repeat), kwargs = {})
triton_poi_fused_mul_repeat_3 = async_compile.triton('triton_poi_fused_mul_repeat_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=[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_mul_repeat_3', '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_mul_repeat_3(in_ptr0, in_ptr1, 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
    x0 = xindex % 4
    x2 = (xindex // 16)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (4*x2)), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x3), xmask)
    tmp2 = tmp1 * tmp0
    tl.store(out_ptr0 + (x3), tmp0, xmask)
    tl.store(out_ptr1 + (x3), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/fx/cfxro6sxxrznbua5rn3ewzc4i4pgisfs7mxqr2w4qi37zuqxkkty.py
# Topologically Sorted Source Nodes: [mul_2], Original ATen: [aten.mul]
# Source node to ATen node mapping:
#   mul_2 => mul_2
# Graph fragment:
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_16, %permute_4), kwargs = {})
triton_poi_fused_mul_4 = async_compile.triton('triton_poi_fused_mul_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: '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_mul_4', '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_mul_4(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
    x0 = xindex % 4
    x2 = (xindex // 16)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (4*x2)), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x3), xmask)
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + (x3), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/56/c566ex7xddxc2fqpwqlmymdyd23nesbsyghxftm7cy73ebnuo3ke.py
# Topologically Sorted Source Nodes: [weighted_value_2], Original ATen: [aten.add]
# Source node to ATen node mapping:
#   weighted_value_2 => add_2
# Graph fragment:
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_19, %view_1), kwargs = {})
triton_poi_fused_add_5 = async_compile.triton('triton_poi_fused_add_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=[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_add_5', 'mutated_arg_names': ['in_out_ptr0'], '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_5(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (x2), xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(in_out_ptr0 + (x2), tmp4, xmask)
''', 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 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, ), (1, ))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4, ), (1, ))
    assert_size_stride(primals_7, (4, 4), (4, 1))
    assert_size_stride(primals_8, (4, ), (1, ))
    assert_size_stride(primals_9, (4, 4), (4, 1))
    assert_size_stride(primals_10, (4, ), (1, ))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mixed_query_layer], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_4, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0)
        del primals_3
        del primals_4
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mixed_key_layer], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_6, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1)
        del primals_5
        del primals_6
        buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(buf0, reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
        buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        # Topologically Sorted Source Nodes: [sub, mask_1, query_for_score, query_for_score_1, softmax], Original ATen: [aten.rsub, aten.mul, aten.div, aten.add, aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_add_div_mul_rsub_0.run(buf2, primals_8, primals_1, buf3, buf4, 16, grid=grid(16), stream=stream0)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub, mask_1, query_for_score, query_for_score_1, softmax], Original ATen: [aten.rsub, aten.mul, aten.div, aten.add, aten._softmax]
        triton_poi_fused__softmax_add_div_mul_rsub_1.run(buf2, primals_8, primals_1, buf3, buf4, buf5, 16, 4, grid=grid(16, 4), stream=stream0)
        del primals_8
        buf6 = reinterpret_tensor(buf2, (4, 4, 4, 1), (16, 4, 1, 1), 0); del buf2  # reuse
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.clone]
        triton_poi_fused_clone_2.run(buf0, buf6, 16, 4, grid=grid(16, 4), stream=stream0)
        buf7 = reinterpret_tensor(buf4, (16, 1, 1), (1, 1, 1), 0); del buf4  # reuse
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf5, (16, 1, 4), (4, 4, 1), 0), reinterpret_tensor(buf6, (16, 4, 1), (4, 1, 0), 0), out=buf7)
        buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pooled_query_repeat, mixed_query_key_layer], Original ATen: [aten.repeat, aten.mul]
        triton_poi_fused_mul_repeat_3.run(buf7, buf1, buf8, buf9, 64, grid=grid(64), stream=stream0)
        buf10 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(reinterpret_tensor(buf9, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf10)
        buf11 = reinterpret_tensor(buf7, (4, 4, 1), (4, 1, 16), 0); del buf7  # reuse
        buf12 = buf3; del buf3  # reuse
        # Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_add_div_mul_rsub_0.run(buf10, primals_10, primals_1, buf11, buf12, 16, grid=grid(16), stream=stream0)
        buf13 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_add_div_mul_rsub_1.run(buf10, primals_10, primals_1, buf11, buf12, buf13, 16, 4, grid=grid(16, 4), stream=stream0)
        del buf11
        del primals_1
        del primals_10
        buf14 = reinterpret_tensor(buf10, (4, 4, 4, 1), (16, 4, 1, 1), 0); del buf10  # reuse
        # Topologically Sorted Source Nodes: [pooled_key], Original ATen: [aten.clone]
        triton_poi_fused_clone_2.run(buf9, buf14, 16, 4, grid=grid(16, 4), stream=stream0)
        buf15 = reinterpret_tensor(buf12, (16, 1, 1), (1, 1, 1), 0); del buf12  # reuse
        # Topologically Sorted Source Nodes: [pooled_key], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf13, (16, 1, 4), (4, 4, 1), 0), reinterpret_tensor(buf14, (16, 4, 1), (4, 1, 0), 0), out=buf15)
        buf16 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 16), torch.float32)
        # Topologically Sorted Source Nodes: [mul_2], Original ATen: [aten.mul]
        triton_poi_fused_mul_4.run(buf15, buf0, buf16, 64, grid=grid(64), stream=stream0)
        buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf17)
        buf18 = reinterpret_tensor(buf17, (4, 4, 4), (16, 4, 1), 0); del buf17  # reuse
        # Topologically Sorted Source Nodes: [weighted_value_2], Original ATen: [aten.add]
        triton_poi_fused_add_5.run(buf18, primals_12, buf0, 64, grid=grid(64), stream=stream0)
        del primals_12
    return (buf18, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), buf0, buf1, buf5, buf8, reinterpret_tensor(buf9, (16, 4), (4, 1), 0), buf13, buf15, reinterpret_tensor(buf16, (16, 4), (4, 1), 0), primals_11, reinterpret_tensor(buf14, (16, 1, 4), (4, 1, 1), 0), primals_9, reinterpret_tensor(buf6, (16, 1, 4), (4, 1, 1), 0), primals_7, )


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), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 4), (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), (4, 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), (4, 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), (4, 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, ), (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])
    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 torch
import torch.nn as nn


class FastAttention(nn.Module):
    """ wuch15's Fastformer Attention module (Official) """

    def __init__(self, dim, dim_head, heads, dropout=0.1, initializer_range
        =0.02):
        super(FastAttention, self).__init__()
        self.initializer_range = initializer_range
        if dim % dim_head != 0:
            raise ValueError(
                'The hidden size (%d) is not a multiple of the number of attention heads (%d)'
                 % (dim, dim_head))
        self.attention_head_size = int(dim / dim_head)
        self.num_attention_heads = dim_head
        self.all_head_size = (self.num_attention_heads * self.
            attention_head_size)
        self.input_dim = dim
        self.query = nn.Linear(self.input_dim, self.all_head_size)
        self.to_q_attn_logits = nn.Linear(self.all_head_size, self.
            num_attention_heads)
        self.key = nn.Linear(self.input_dim, self.all_head_size)
        self.to_k_attn_logits = nn.Linear(self.all_head_size, self.
            num_attention_heads)
        self.transform = nn.Linear(self.all_head_size, self.all_head_size)
        self.softmax = nn.Softmax(dim=-1)
        self.apply(self.init_weights)
        self.dropout = nn.Dropout(dropout)

    def init_weights(self, module):
        if isinstance(module, nn.Linear):
            module.weight.data.normal_(mean=0.0, std=self.initializer_range)
        if isinstance(module, nn.Linear) and module.bias is not None:
            module.bias.data.zero_()

    def transpose_for_scores(self, x):
        new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.
            attention_head_size)
        x = x.view(*new_x_shape)
        return x.permute(0, 2, 1, 3)

    def forward(self, hidden_states, mask):
        """
        hidden_states -- [B, T, H]
        mask -- [B, T]
        """
        mask = mask.unsqueeze(1)
        mask = mask
        mask = (1.0 - mask) * -10000.0
        _batch_size, seq_len, _ = hidden_states.shape
        mixed_query_layer = self.query(hidden_states)
        mixed_key_layer = self.key(hidden_states)
        query_for_score = self.to_q_attn_logits(mixed_query_layer).transpose(
            1, 2) / self.attention_head_size ** 0.5
        query_for_score += mask
        query_weight = self.softmax(query_for_score).unsqueeze(2)
        query_layer = self.transpose_for_scores(mixed_query_layer)
        pooled_query = torch.matmul(query_weight, query_layer).transpose(1, 2
            ).view(-1, 1, self.num_attention_heads * self.attention_head_size)
        pooled_query_repeat = pooled_query.repeat(1, seq_len, 1)
        mixed_query_key_layer = mixed_key_layer * pooled_query_repeat
        query_key_score = (self.to_k_attn_logits(mixed_query_key_layer) / 
            self.attention_head_size ** 0.5).transpose(1, 2)
        query_key_score += mask
        query_key_weight = self.softmax(query_key_score).unsqueeze(2)
        key_layer = self.transpose_for_scores(mixed_query_key_layer)
        pooled_key = torch.matmul(query_key_weight, key_layer)
        weighted_value = (pooled_key * query_layer).transpose(1, 2)
        weighted_value = weighted_value.reshape(weighted_value.size()[:-2] +
            (self.num_attention_heads * self.attention_head_size,))
        weighted_value = self.transform(weighted_value) + mixed_query_layer
        return self.dropout(weighted_value)


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


def get_init_inputs():
    return [[], {'dim': 4, 'dim_head': 4, 'heads': 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 math as tl_math
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__softmax_add_div_mul_rsub_0(in_ptr0, in_ptr1, in_ptr2,
    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 % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
    tmp13 = tl.load(in_ptr2 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp18 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
    tmp21 = tl.load(in_ptr2 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp26 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
    tmp29 = tl.load(in_ptr2 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tmp6 = tmp3 - tmp5
    tmp7 = -10000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp4 + tmp8
    tmp11 = tmp10 + tmp1
    tmp12 = tmp11 * tmp3
    tmp14 = tmp3 - tmp13
    tmp15 = tmp14 * tmp7
    tmp16 = tmp12 + tmp15
    tmp17 = triton_helpers.maximum(tmp9, tmp16)
    tmp19 = tmp18 + tmp1
    tmp20 = tmp19 * tmp3
    tmp22 = tmp3 - tmp21
    tmp23 = tmp22 * tmp7
    tmp24 = tmp20 + tmp23
    tmp25 = triton_helpers.maximum(tmp17, tmp24)
    tmp27 = tmp26 + tmp1
    tmp28 = tmp27 * tmp3
    tmp30 = tmp3 - tmp29
    tmp31 = tmp30 * tmp7
    tmp32 = tmp28 + tmp31
    tmp33 = triton_helpers.maximum(tmp25, tmp32)
    tmp34 = tmp9 - tmp33
    tmp35 = tl_math.exp(tmp34)
    tmp36 = tmp16 - tmp33
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp24 - tmp33
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tmp42 = tmp32 - tmp33
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp41 + tmp43
    tl.store(out_ptr0 + x2, tmp33, xmask)
    tl.store(out_ptr1 + x2, tmp44, xmask)


@triton.jit
def triton_poi_fused__softmax_add_div_mul_rsub_1(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr,
    XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + (x2 + 4 * y1), xmask & ymask, eviction_policy=
        'evict_last')
    tmp10 = tl.load(in_ptr3 + y3, ymask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr4 + y3, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tmp6 = tmp3 - tmp5
    tmp7 = -10000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp4 + tmp8
    tmp11 = tmp9 - tmp10
    tmp12 = tl_math.exp(tmp11)
    tmp14 = tmp12 / tmp13
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp14, xmask & ymask)


@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_mul_repeat_3(in_ptr0, in_ptr1, 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
    x0 = xindex % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp1 = tl.load(in_ptr1 + x3, xmask)
    tmp2 = tmp1 * tmp0
    tl.store(out_ptr0 + x3, tmp0, xmask)
    tl.store(out_ptr1 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_mul_4(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
    x0 = xindex % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp1 = tl.load(in_ptr1 + x3, xmask)
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_5(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tl.store(in_out_ptr0 + x2, tmp4, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
        ) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 4), (4, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4), (4, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_4, reinterpret_tensor(primals_2, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf0)
        del primals_3
        del primals_4
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_6, reinterpret_tensor(primals_2, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf1)
        del primals_5
        del primals_6
        buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(primals_7, (4, 4), (1, 4
            ), 0), out=buf2)
        buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_add_div_mul_rsub_0[grid(16)](buf2,
            primals_8, primals_1, buf3, buf4, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused__softmax_add_div_mul_rsub_1[grid(16, 4)](buf2,
            primals_8, primals_1, buf3, buf4, buf5, 16, 4, XBLOCK=4, YBLOCK
            =8, num_warps=1, num_stages=1)
        del primals_8
        buf6 = reinterpret_tensor(buf2, (4, 4, 4, 1), (16, 4, 1, 1), 0)
        del buf2
        triton_poi_fused_clone_2[grid(16, 4)](buf0, buf6, 16, 4, XBLOCK=4,
            YBLOCK=16, num_warps=1, num_stages=1)
        buf7 = reinterpret_tensor(buf4, (16, 1, 1), (1, 1, 1), 0)
        del buf4
        extern_kernels.bmm(reinterpret_tensor(buf5, (16, 1, 4), (4, 4, 1), 
            0), reinterpret_tensor(buf6, (16, 4, 1), (4, 1, 0), 0), out=buf7)
        buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_mul_repeat_3[grid(64)](buf7, buf1, buf8, buf9, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf9, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf10)
        buf11 = reinterpret_tensor(buf7, (4, 4, 1), (4, 1, 16), 0)
        del buf7
        buf12 = buf3
        del buf3
        triton_poi_fused__softmax_add_div_mul_rsub_0[grid(16)](buf10,
            primals_10, primals_1, buf11, buf12, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf13 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused__softmax_add_div_mul_rsub_1[grid(16, 4)](buf10,
            primals_10, primals_1, buf11, buf12, buf13, 16, 4, XBLOCK=4,
            YBLOCK=8, num_warps=1, num_stages=1)
        del buf11
        del primals_1
        del primals_10
        buf14 = reinterpret_tensor(buf10, (4, 4, 4, 1), (16, 4, 1, 1), 0)
        del buf10
        triton_poi_fused_clone_2[grid(16, 4)](buf9, buf14, 16, 4, XBLOCK=4,
            YBLOCK=16, num_warps=1, num_stages=1)
        buf15 = reinterpret_tensor(buf12, (16, 1, 1), (1, 1, 1), 0)
        del buf12
        extern_kernels.bmm(reinterpret_tensor(buf13, (16, 1, 4), (4, 4, 1),
            0), reinterpret_tensor(buf14, (16, 4, 1), (4, 1, 0), 0), out=buf15)
        buf16 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 16), torch.float32)
        triton_poi_fused_mul_4[grid(64)](buf15, buf0, buf16, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf16, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf17)
        buf18 = reinterpret_tensor(buf17, (4, 4, 4), (16, 4, 1), 0)
        del buf17
        triton_poi_fused_add_5[grid(64)](buf18, primals_12, buf0, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_12
    return buf18, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0
        ), buf0, buf1, buf5, buf8, reinterpret_tensor(buf9, (16, 4), (4, 1), 0
        ), buf13, buf15, reinterpret_tensor(buf16, (16, 4), (4, 1), 0
        ), primals_11, reinterpret_tensor(buf14, (16, 1, 4), (4, 1, 1), 0
        ), primals_9, reinterpret_tensor(buf6, (16, 1, 4), (4, 1, 1), 0
        ), primals_7


class FastAttentionNew(nn.Module):
    """ wuch15's Fastformer Attention module (Official) """

    def __init__(self, dim, dim_head, heads, dropout=0.1, initializer_range
        =0.02):
        super(FastAttentionNew, self).__init__()
        self.initializer_range = initializer_range
        if dim % dim_head != 0:
            raise ValueError(
                'The hidden size (%d) is not a multiple of the number of attention heads (%d)'
                 % (dim, dim_head))
        self.attention_head_size = int(dim / dim_head)
        self.num_attention_heads = dim_head
        self.all_head_size = (self.num_attention_heads * self.
            attention_head_size)
        self.input_dim = dim
        self.query = nn.Linear(self.input_dim, self.all_head_size)
        self.to_q_attn_logits = nn.Linear(self.all_head_size, self.
            num_attention_heads)
        self.key = nn.Linear(self.input_dim, self.all_head_size)
        self.to_k_attn_logits = nn.Linear(self.all_head_size, self.
            num_attention_heads)
        self.transform = nn.Linear(self.all_head_size, self.all_head_size)
        self.softmax = nn.Softmax(dim=-1)
        self.apply(self.init_weights)
        self.dropout = nn.Dropout(dropout)

    def init_weights(self, module):
        if isinstance(module, nn.Linear):
            module.weight.data.normal_(mean=0.0, std=self.initializer_range)
        if isinstance(module, nn.Linear) and module.bias is not None:
            module.bias.data.zero_()

    def transpose_for_scores(self, x):
        new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.
            attention_head_size)
        x = x.view(*new_x_shape)
        return x.permute(0, 2, 1, 3)

    def forward(self, input_0, input_1):
        primals_1 = self.query.weight
        primals_4 = self.query.bias
        primals_3 = self.to_q_attn_logits.weight
        primals_6 = self.to_q_attn_logits.bias
        primals_5 = self.key.weight
        primals_8 = self.key.bias
        primals_7 = self.to_k_attn_logits.weight
        primals_10 = self.to_k_attn_logits.bias
        primals_9 = self.transform.weight
        primals_12 = self.transform.bias
        primals_2 = input_0
        primals_11 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12])
        return output[0]
