# AOT ID: ['5_inference']
from ctypes import c_void_p, c_long
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
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
alloc_from_pool = torch.ops.inductor._alloc_from_pool
reinterpret_tensor = torch.ops.inductor._reinterpret_tensor
async_compile = AsyncCompile()
# kernel path: /tmp/torchinductor_root/ve/cve3kymtfiex4o22aahcdsqjeevm7wsdfiybt3kkoumwkgrlmjcl.py
# Source Nodes: [K, Q, V, _tgt, q], Original ATen: [aten._to_copy, aten.add, aten.native_layer_norm]
# K => convert_element_type_8
# Q => convert_element_type_2
# V => convert_element_type_14
# _tgt => add, add_1, mul, mul_1, rsqrt, sub, var_mean
# q => add_2
triton_per_fused__to_copy_add_native_layer_norm_0 = async_compile.triton('triton_', '''
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.persistent_reduction(
size_hints=[8192, 256],
reduction_hint=ReductionHint.INNER,
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp16', 5: '*fp16', 6: '*fp16', 7: 'i32', 8: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 7, 8), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__to_copy_add_native_layer_norm_0', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 4, 'num_reduction': 4, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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}
)
@triton.jit
def triton_(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr3, out_ptr4, out_ptr5, xnumel, rnumel):
xnumel = 4624
XBLOCK: tl.constexpr = 1
rnumel = 256
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[:]
roffset = 0
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + (256*x0)), rmask & xmask, other=0.0)
tmp24 = tl.load(in_ptr1 + (r1), rmask, eviction_policy='evict_last', other=0.0)
tmp26 = tl.load(in_ptr2 + (r1), rmask, eviction_policy='evict_last', other=0.0)
tmp28 = tl.load(in_ptr3 + (r1 + (256*x0)), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.where(rmask & xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [RBLOCK])
tmp6 = tl.where(rmask & xmask, tmp4, 0)
tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0))
tmp8 = tl.full([1], 256, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = tl.where(rmask & xmask, tmp13, 0)
tmp16 = triton_helpers.promote_to_tensor(tl.sum(tmp15, 0))
tmp17 = tmp0 - tmp10
tmp18 = 256.0
tmp19 = tmp16 / tmp18
tmp20 = 1e-05
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp17 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tmp29 = tmp27 + tmp28
tmp30 = tmp29.to(tl.float32)
tmp31 = tmp27.to(tl.float32)
tl.store(out_ptr3 + (r1 + (256*x0)), tmp30, rmask & xmask)
tl.store(out_ptr4 + (r1 + (256*x0)), tmp30, rmask & xmask)
tl.store(out_ptr5 + (r1 + (256*x0)), tmp31, rmask & xmask)
''', device_str='cuda')
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
# kernel path: /tmp/torchinductor_root/ld/cldnvvcszzbw2u35pztkdro56yut3i522sotxjmggvzj53sfjd2g.py
# Source Nodes: [Q], Original ATen: [aten._to_copy]
# Q => convert_element_type_1
triton_poi_fused__to_copy_1 = async_compile.triton('triton_', '''
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=[65536],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 65536
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/is/cisqqmevi5qvtitkbeqmioaswyzxh2agrpbjiretwponubx4wru2.py
# Source Nodes: [K], Original ATen: [aten._to_copy]
# K => convert_element_type_6
triton_poi_fused__to_copy_2 = async_compile.triton('triton_', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor
from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties
@triton_heuristics.pointwise(
size_hints=[256],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), xmask)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/zx/czx5exiyzo4vwpc3n6tikqns6gnoecay6qn2r7vkhpstcwta5wa7.py
# Source Nodes: [Q_1], Original ATen: [aten.div]
# Q_1 => div
triton_poi_fused_div_3 = async_compile.triton('triton_', '''
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=[2097152],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_div_3', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 1183744
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 256
tmp0 = tl.load(in_out_ptr0 + (x2), None).to(tl.float32)
tmp1 = tl.load(in_ptr0 + (x0), None, eviction_policy='evict_last')
tmp2 = tmp1.to(tl.float32)
tmp3 = tmp0 + tmp2
tmp4 = 0.17677669529663687
tmp5 = tmp3 * tmp4
tl.store(in_out_ptr0 + (x2), tmp5, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/vn/cvncd74toz2pwdrsevknjpf54rbub4bc4lmzgjzgx57qe6u65ulq.py
# Source Nodes: [attn, matmul_1], Original ATen: [aten._softmax, aten._to_copy]
# attn => amax, convert_element_type_20, div_1, exp, sub_1, sum_1
# matmul_1 => convert_element_type_21
triton_red_fused__softmax__to_copy_4 = async_compile.triton('triton_', '''
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.reduction(
size_hints=[65536, 8192],
reduction_hint=ReductionHint.DEFAULT,
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_red_fused__softmax__to_copy_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 2, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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}
)
@triton.jit
def triton_(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr, RBLOCK : tl.constexpr):
xnumel = 36992
rnumel = 4624
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x3 = xindex
_tmp3 = tl.full([XBLOCK, RBLOCK], float("-inf"), tl.float32)
x0 = xindex % 4624
x1 = (xindex // 4624)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp0 = tl.load(in_ptr0 + (r2 + (4624*x3)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp1 = tmp0.to(tl.float32)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = triton_helpers.maximum(_tmp3, tmp2)
_tmp3 = tl.where(rmask & xmask, tmp4, _tmp3)
tmp3 = triton_helpers.max2(_tmp3, 1)[:, None]
_tmp10 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp5 = tl.load(in_ptr0 + (r2 + (4624*x3)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp6 = tmp5.to(tl.float32)
tmp7 = tmp6 - tmp3
tmp8 = tl_math.exp(tmp7)
tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp11 = _tmp10 + tmp9
_tmp10 = tl.where(rmask & xmask, tmp11, _tmp10)
tmp10 = tl.sum(_tmp10, 1)[:, None]
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp12 = tl.load(in_ptr0 + (r2 + (4624*x3)), rmask & xmask, eviction_policy='evict_first', other=0.0).to(tl.float32)
tmp13 = tmp12.to(tl.float32)
tmp14 = tmp13 - tmp3
tmp15 = tl_math.exp(tmp14)
tmp16 = tmp15 / tmp10
tmp17 = tmp16.to(tl.float32)
tl.store(out_ptr2 + (r2 + (4672*x3)), tmp17, rmask & xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/54/c54hnb2v6hf6dov24c7bcdjsengr3o6qiexvmcbggt5fdj7remvo.py
# Source Nodes: [outputs_1], Original ATen: [aten.clone]
# outputs_1 => clone_1
triton_poi_fused_clone_5 = async_compile.triton('triton_', '''
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=[2097152],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 1183744
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 32
x1 = (xindex // 32) % 8
x2 = (xindex // 256)
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + (32*x2) + (147968*x1)), None).to(tl.float32)
tl.store(out_ptr0 + (x3), tmp0, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/og/cog2kpwz2yd7tf7aras3txpynnqywvs2dgcfggdpuziw7wowjaef.py
# Source Nodes: [_tgt_1, curr_QV, tgt], Original ATen: [aten._to_copy, aten.add, aten.native_layer_norm]
# _tgt_1 => add_4, add_5, mul_2, mul_3, rsqrt_1, sub_2, var_mean_1
# curr_QV => convert_element_type_31
# tgt => add_3
triton_per_fused__to_copy_add_native_layer_norm_6 = async_compile.triton('triton_', '''
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.persistent_reduction(
size_hints=[8192, 256],
reduction_hint=ReductionHint.INNER,
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: '*fp16', 8: 'i32', 9: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__to_copy_add_native_layer_norm_6', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 5, 'num_reduction': 4, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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}
)
@triton.jit
def triton_(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr3, out_ptr4, xnumel, rnumel):
xnumel = 4624
XBLOCK: tl.constexpr = 1
rnumel = 256
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[:]
roffset = 0
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + (256*x0)), rmask & xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r1 + (256*x0)), rmask & xmask, other=0.0).to(tl.float32)
tmp2 = tl.load(in_ptr2 + (r1), rmask, eviction_policy='evict_last', other=0.0)
tmp30 = tl.load(in_ptr3 + (r1), rmask, eviction_policy='evict_last', other=0.0)
tmp32 = tl.load(in_ptr4 + (r1), rmask, eviction_policy='evict_last', other=0.0)
tmp3 = tmp2.to(tl.float32)
tmp4 = tmp1 + tmp3
tmp5 = tmp4.to(tl.float32)
tmp6 = tmp0 + tmp5
tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
tmp9 = tl.where(rmask & xmask, tmp7, 0)
tmp10 = tl.broadcast_to(tmp7, [RBLOCK])
tmp12 = tl.where(rmask & xmask, tmp10, 0)
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0))
tmp14 = tl.full([1], 256, tl.int32)
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp13 / tmp15
tmp17 = tmp7 - tmp16
tmp18 = tmp17 * tmp17
tmp19 = tl.broadcast_to(tmp18, [RBLOCK])
tmp21 = tl.where(rmask & xmask, tmp19, 0)
tmp22 = triton_helpers.promote_to_tensor(tl.sum(tmp21, 0))
tmp23 = tmp6 - tmp16
tmp24 = 256.0
tmp25 = tmp22 / tmp24
tmp26 = 1e-05
tmp27 = tmp25 + tmp26
tmp28 = libdevice.rsqrt(tmp27)
tmp29 = tmp23 * tmp28
tmp31 = tmp29 * tmp30
tmp33 = tmp31 + tmp32
tmp34 = tmp33.to(tl.float32)
tl.store(out_ptr0 + (r1 + (256*x0)), tmp6, rmask & xmask)
tl.store(out_ptr3 + (r1 + (256*x0)), tmp33, rmask & xmask)
tl.store(out_ptr4 + (r1 + (256*x0)), tmp34, rmask & xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/3y/c3y6n5l67gkydr2tk6tgi4gamvt7ow5mmhwncg77dykjfaui4csu.py
# Source Nodes: [curr_QV], Original ATen: [aten._to_copy]
# curr_QV => convert_element_type_30
triton_poi_fused__to_copy_7 = async_compile.triton('triton_', '''
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=[131072],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 131072
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/et/cetvktg47qcfuibcbbp2tvp6ktcppxx5sfiexlsz6qufq6wm3mnf.py
# Source Nodes: [curr_QV], Original ATen: [aten._to_copy]
# curr_QV => convert_element_type_29
triton_poi_fused__to_copy_8 = async_compile.triton('triton_', '''
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=[512],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_8', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 512
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.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/c6/cc6y7wireldz46nw5ymn4ucbt3l2kp2rszgyzuoi4yotzpikhjwn.py
# Source Nodes: [ID_KV], Original ATen: [aten._to_copy]
# ID_KV => convert_element_type_37
triton_poi_fused__to_copy_9 = async_compile.triton('triton_', '''
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=[2097152],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_9', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 1183744
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/bd/cbdjwo6zi5he3lxwklhrdjsghfhepaz5y572zr6gm2c24b7snm4t.py
# Source Nodes: [ID_KV], Original ATen: [aten._to_copy]
# ID_KV => convert_element_type_36
triton_poi_fused__to_copy_10 = async_compile.triton('triton_', '''
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=[131072],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_10', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 65792
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.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/ny/cny4ywplr7u3hcgv2tnxlkme34dbcst3o7glzqdiqo4l3k45zylc.py
# Source Nodes: [tensor], Original ATen: [aten.clone]
# tensor => clone_2
triton_poi_fused_clone_11 = async_compile.triton('triton_', '''
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, 8192], tile_hint=TileHint.SQUARE,
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_11', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
ynumel = 256
xnumel = 4624
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + (512*x1)), xmask & ymask, eviction_policy='evict_last').to(tl.float32)
tl.store(out_ptr0 + (x1 + (4624*y0)), tmp0, xmask & ymask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/jh/cjhtfgurr3pdayluihg7f6sov4wf7vmbo6igf62vphdoexvbto5n.py
# Source Nodes: [K_2, Q_3], Original ATen: [aten.div, aten.mul]
# K_2 => mul_4
# Q_3 => div_2
triton_poi_fused_div_mul_12 = async_compile.triton('triton_', '''
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=[2097152],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: '*fp32', 3: '*fp16', 4: '*fp16', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), '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_div_mul_12', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
xnumel = 1183744
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 256
x1 = (xindex // 256)
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + (512*x1)), None).to(tl.float32)
tmp1 = tl.load(in_ptr1 + (257*x1), None, eviction_policy='evict_last').to(tl.float32)
tmp2 = tl.load(in_ptr2 + (0))
tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
tmp4 = tmp3.to(tl.float32)
tmp5 = tmp1 + tmp4
tmp6 = libdevice.tanh(tmp5)
tmp7 = 1.0
tmp8 = tmp6 + tmp7
tmp9 = tmp0 * tmp8
tmp10 = 0.0625
tmp11 = tmp0 * tmp10
tl.store(out_ptr0 + (x2), tmp9, None)
tl.store(out_ptr1 + (x2), tmp11, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/5q/c5q5ec5s4mva4nijobtalyg2kj5opsx7tekplmx3mjfmb332vzdo.py
# Source Nodes: [tensor_1], Original ATen: [aten.clone]
# tensor_1 => clone_3
triton_poi_fused_clone_13 = async_compile.triton('triton_', '''
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, 8192], tile_hint=TileHint.SQUARE,
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_13', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
ynumel = 256
xnumel = 4624
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + (256*x1)), xmask & ymask, eviction_policy='evict_last').to(tl.float32)
tl.store(out_ptr0 + (x1 + (4624*y0)), tmp0, xmask & ymask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/k3/ck34prinya5rgegfdn6l6bsmaqvdchdsibghqm2ovtnvpoyz4kx2.py
# Source Nodes: [V_2], Original ATen: [aten.add]
# V_2 => add_7
triton_poi_fused_add_14 = async_compile.triton('triton_', '''
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=[2097152],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: '*fp32', 3: '*fp16', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), '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_14', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 1183744
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 256
x1 = (xindex // 256)
x2 = xindex
tmp0 = tl.load(in_ptr0 + (256 + x0 + (512*x1)), None).to(tl.float32)
tmp1 = tl.load(in_ptr1 + (1 + x0 + (257*x1)), None).to(tl.float32)
tmp2 = tl.load(in_ptr2 + (1 + x0), None, eviction_policy='evict_last')
tmp3 = tmp2.to(tl.float32)
tmp4 = tmp1 + tmp3
tmp5 = tmp0 + tmp4
tl.store(out_ptr0 + (x2), tmp5, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/qw/cqw7624l52yr24g4mkdqvf7bfaj5r5o2xbvqvljr6odz33uudzn4.py
# Source Nodes: [attn_2, matmul_3], Original ATen: [aten._softmax, aten._to_copy]
# attn_2 => amax_1, convert_element_type_43, div_3, exp_1, sub_3, sum_2
# matmul_3 => convert_element_type_44
triton_red_fused__softmax__to_copy_15 = async_compile.triton('triton_', '''
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.reduction(
size_hints=[8192, 8192],
reduction_hint=ReductionHint.INNER,
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_red_fused__softmax__to_copy_15', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 2, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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}
)
@triton.jit
def triton_(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr, RBLOCK : tl.constexpr):
xnumel = 4624
rnumel = 4624
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
_tmp3 = tl.full([XBLOCK, RBLOCK], float("-inf"), tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + (4624*x0)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp1 = tmp0.to(tl.float32)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = triton_helpers.maximum(_tmp3, tmp2)
_tmp3 = tl.where(rmask & xmask, tmp4, _tmp3)
tmp3 = triton_helpers.max2(_tmp3, 1)[:, None]
_tmp10 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp5 = tl.load(in_ptr0 + (r1 + (4624*x0)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp6 = tmp5.to(tl.float32)
tmp7 = tmp6 - tmp3
tmp8 = tl_math.exp(tmp7)
tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp11 = _tmp10 + tmp9
_tmp10 = tl.where(rmask & xmask, tmp11, _tmp10)
tmp10 = tl.sum(_tmp10, 1)[:, None]
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp12 = tl.load(in_ptr0 + (r1 + (4624*x0)), rmask & xmask, eviction_policy='evict_first', other=0.0).to(tl.float32)
tmp13 = tmp12.to(tl.float32)
tmp14 = tmp13 - tmp3
tmp15 = tl_math.exp(tmp14)
tmp16 = tmp15 / tmp10
tmp17 = tmp16.to(tl.float32)
tl.store(out_ptr2 + (r1 + (4672*x0)), tmp17, rmask & xmask)
''', device_str='cuda')
async_compile.wait(globals())
del async_compile
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1, arg9_1, arg10_1, arg11_1, arg12_1, arg13_1, arg14_1, arg15_1, arg16_1, arg17_1, arg18_1, arg19_1, arg20_1 = args
args.clear()
assert_size_stride(arg0_1, (256, ), (1, ))
assert_size_stride(arg1_1, (256, ), (1, ))
assert_size_stride(arg2_1, (4624, 1, 256), (256, 256, 1))
assert_size_stride(arg3_1, (4624, 1, 256), (256, 256, 1))
assert_size_stride(arg4_1, (256, 256), (256, 1))
assert_size_stride(arg5_1, (256, ), (1, ))
assert_size_stride(arg6_1, (256, 256), (256, 1))
assert_size_stride(arg7_1, (256, ), (1, ))
assert_size_stride(arg8_1, (256, 256), (256, 1))
assert_size_stride(arg9_1, (256, ), (1, ))
assert_size_stride(arg10_1, (256, 256), (256, 1))
assert_size_stride(arg11_1, (256, ), (1, ))
assert_size_stride(arg12_1, (256, ), (1, ))
assert_size_stride(arg13_1, (256, ), (1, ))
assert_size_stride(arg14_1, (512, 256), (256, 1))
assert_size_stride(arg15_1, (512, ), (1, ))
assert_size_stride(arg16_1, (4624, 1, 256), (256, 256, 1))
assert_size_stride(arg17_1, (257, 256), (256, 1))
assert_size_stride(arg18_1, (257, ), (1, ))
assert_size_stride(arg19_1, (256, 256), (256, 1))
assert_size_stride(arg20_1, (256, ), (1, ))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf4 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float16)
buf7 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float16)
buf15 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float16)
# Source Nodes: [K, Q, V, _tgt, q], Original ATen: [aten._to_copy, aten.add, aten.native_layer_norm]
stream0 = get_raw_stream(0)
triton_per_fused__to_copy_add_native_layer_norm_0.run(arg2_1, arg0_1, arg1_1, arg3_1, buf4, buf7, buf15, 4624, 256, grid=grid(4624), stream=stream0)
del arg0_1
del arg1_1
del arg3_1
buf5 = empty_strided_cuda((256, 256), (256, 1), torch.float16)
# Source Nodes: [Q], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_1.run(arg4_1, buf5, 65536, grid=grid(65536), stream=stream0)
del arg4_1
buf6 = empty_strided_cuda((4624, 256), (256, 1), torch.float16)
# Source Nodes: [], Original ATen: []
extern_kernels.mm(reinterpret_tensor(buf4, (4624, 256), (256, 1), 0), reinterpret_tensor(buf5, (256, 256), (1, 256), 0), out=buf6)
buf8 = buf5; del buf5 # reuse
# Source Nodes: [K], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_1.run(arg6_1, buf8, 65536, grid=grid(65536), stream=stream0)
del arg6_1
buf9 = empty_strided_cuda((256, ), (1, ), torch.float16)
# Source Nodes: [K], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_2.run(arg7_1, buf9, 256, grid=grid(256), stream=stream0)
del arg7_1
buf10 = reinterpret_tensor(buf4, (4624, 256), (256, 1), 0); del buf4 # reuse
# Source Nodes: [K], Original ATen: [aten._to_copy, aten.addmm]
extern_kernels.addmm(buf9, reinterpret_tensor(buf7, (4624, 256), (256, 1), 0), reinterpret_tensor(buf8, (256, 256), (1, 256), 0), alpha=1, beta=1, out=buf10)
buf11 = reinterpret_tensor(buf6, (4624, 1, 256), (256, 256, 1), 0); del buf6 # reuse
# Source Nodes: [Q_1], Original ATen: [aten.div]
triton_poi_fused_div_3.run(buf11, arg5_1, 1183744, grid=grid(1183744), stream=stream0)
del arg5_1
buf12 = empty_strided_cuda((8, 4624, 4624), (21381376, 4624, 1), torch.float16)
# Source Nodes: [QK], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf11, (8, 4624, 32), (32, 256, 1), 0), reinterpret_tensor(buf10, (8, 32, 4624), (32, 1, 256), 0), out=buf12)
buf19 = empty_strided_cuda((1, 8, 4624, 4624), (172826624, 21603328, 4672, 1), torch.float16)
# Source Nodes: [attn, matmul_1], Original ATen: [aten._softmax, aten._to_copy]
triton_red_fused__softmax__to_copy_4.run(buf12, buf19, 36992, 4624, grid=grid(36992), stream=stream0)
del buf12
buf16 = buf8; del buf8 # reuse
# Source Nodes: [V], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_1.run(arg8_1, buf16, 65536, grid=grid(65536), stream=stream0)
del arg8_1
buf17 = buf9; del buf9 # reuse
# Source Nodes: [V], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_2.run(arg9_1, buf17, 256, grid=grid(256), stream=stream0)
del arg9_1
buf18 = reinterpret_tensor(buf11, (4624, 256), (256, 1), 0); del buf11 # reuse
# Source Nodes: [V], Original ATen: [aten._to_copy, aten.addmm]
extern_kernels.addmm(buf17, reinterpret_tensor(buf15, (4624, 256), (256, 1), 0), reinterpret_tensor(buf16, (256, 256), (1, 256), 0), alpha=1, beta=1, out=buf18)
buf20 = reinterpret_tensor(buf15, (8, 4624, 32), (147968, 32, 1), 0); del buf15 # reuse
# Source Nodes: [matmul_1], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf19, (8, 4624, 4624), (21603328, 4672, 1), 0), reinterpret_tensor(buf18, (8, 4624, 32), (32, 256, 1), 0), out=buf20)
del buf19
buf21 = reinterpret_tensor(buf18, (4624, 1, 8, 32), (256, 1, 32, 1), 0); del buf18 # reuse
# Source Nodes: [outputs_1], Original ATen: [aten.clone]
triton_poi_fused_clone_5.run(buf20, buf21, 1183744, grid=grid(1183744), stream=stream0)
buf22 = buf16; del buf16 # reuse
# Source Nodes: [outputs_2], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_1.run(arg10_1, buf22, 65536, grid=grid(65536), stream=stream0)
del arg10_1
buf23 = reinterpret_tensor(buf20, (4624, 256), (256, 1), 0); del buf20 # reuse
# Source Nodes: [], Original ATen: []
extern_kernels.mm(reinterpret_tensor(buf21, (4624, 256), (256, 1), 0), reinterpret_tensor(buf22, (256, 256), (1, 256), 0), out=buf23)
buf24 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float32)
buf28 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float32)
buf29 = reinterpret_tensor(buf21, (4624, 1, 256), (256, 256, 1), 0); del buf21 # reuse
# Source Nodes: [_tgt_1, curr_QV, tgt], Original ATen: [aten._to_copy, aten.add, aten.native_layer_norm]
triton_per_fused__to_copy_add_native_layer_norm_6.run(arg2_1, buf23, arg11_1, arg12_1, arg13_1, buf24, buf28, buf29, 4624, 256, grid=grid(4624), stream=stream0)
del arg11_1
del arg12_1
del arg13_1
del arg2_1
buf30 = empty_strided_cuda((512, 256), (256, 1), torch.float16)
# Source Nodes: [curr_QV], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_7.run(arg14_1, buf30, 131072, grid=grid(131072), stream=stream0)
del arg14_1
buf31 = empty_strided_cuda((512, ), (1, ), torch.float16)
# Source Nodes: [curr_QV], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_8.run(arg15_1, buf31, 512, grid=grid(512), stream=stream0)
del arg15_1
buf32 = empty_strided_cuda((4624, 512), (512, 1), torch.float16)
# Source Nodes: [curr_QV], Original ATen: [aten._to_copy, aten.addmm]
extern_kernels.addmm(buf31, reinterpret_tensor(buf29, (4624, 256), (256, 1), 0), reinterpret_tensor(buf30, (256, 512), (1, 256), 0), alpha=1, beta=1, out=buf32)
del buf30
del buf31
buf33 = buf29; del buf29 # reuse
# Source Nodes: [ID_KV], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_9.run(arg16_1, buf33, 1183744, grid=grid(1183744), stream=stream0)
del arg16_1
buf34 = empty_strided_cuda((257, 256), (256, 1), torch.float16)
# Source Nodes: [ID_KV], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_10.run(arg17_1, buf34, 65792, grid=grid(65792), stream=stream0)
del arg17_1
buf35 = empty_strided_cuda((4624, 257), (257, 1), torch.float16)
# Source Nodes: [], Original ATen: []
extern_kernels.mm(reinterpret_tensor(buf33, (4624, 256), (256, 1), 0), reinterpret_tensor(buf34, (256, 257), (1, 256), 0), out=buf35)
del buf34
buf36 = reinterpret_tensor(buf33, (1, 256, 68, 68), (1183744, 4624, 68, 1), 0); del buf33 # reuse
# Source Nodes: [tensor], Original ATen: [aten.clone]
triton_poi_fused_clone_11.run(buf32, buf36, 256, 4624, grid=grid(256, 4624), stream=stream0)
buf37 = reinterpret_tensor(buf23, (4624, 1, 1, 256), (256, 1, 1183744, 1), 0); del buf23 # reuse
buf41 = reinterpret_tensor(buf10, (4624, 1, 256), (256, 256, 1), 0); del buf10 # reuse
# Source Nodes: [K_2, Q_3], Original ATen: [aten.div, aten.mul]
triton_poi_fused_div_mul_12.run(buf32, buf35, arg18_1, buf37, buf41, 1183744, grid=grid(1183744), stream=stream0)
buf38 = reinterpret_tensor(buf7, (1, 256, 68, 68), (1183744, 4624, 68, 1), 0); del buf7 # reuse
# Source Nodes: [tensor_1], Original ATen: [aten.clone]
triton_poi_fused_clone_13.run(buf37, buf38, 256, 4624, grid=grid(256, 4624), stream=stream0)
buf39 = empty_strided_cuda((4624, 1, 256), (256, 256, 1), torch.float16)
# Source Nodes: [V_2], Original ATen: [aten.add]
triton_poi_fused_add_14.run(buf32, buf35, arg18_1, buf39, 1183744, grid=grid(1183744), stream=stream0)
del arg18_1
del buf35
buf40 = empty_strided_cuda((1, 256, 68, 68), (1183744, 4624, 68, 1), torch.float16)
# Source Nodes: [tensor_2], Original ATen: [aten.clone]
triton_poi_fused_clone_13.run(buf39, buf40, 256, 4624, grid=grid(256, 4624), stream=stream0)
buf42 = empty_strided_cuda((1, 4624, 4624), (21381376, 4624, 1), torch.float16)
# Source Nodes: [QK_1], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf41, (1, 4624, 256), (0, 256, 1), 0), reinterpret_tensor(buf37, (1, 256, 4624), (0, 1, 256), 0), out=buf42)
buf45 = empty_strided_cuda((1, 1, 4624, 4624), (21603328, 4672, 4672, 1), torch.float16)
# Source Nodes: [attn_2, matmul_3], Original ATen: [aten._softmax, aten._to_copy]
triton_red_fused__softmax__to_copy_15.run(buf42, buf45, 4624, 4624, grid=grid(4624), stream=stream0)
del buf42
buf46 = reinterpret_tensor(buf41, (1, 4624, 256), (1183744, 256, 1), 0); del buf41 # reuse
# Source Nodes: [matmul_3], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf45, (1, 4624, 4624), (0, 4672, 1), 0), reinterpret_tensor(buf39, (1, 4624, 256), (1183744, 256, 1), 0), out=buf46)
del buf45
buf47 = buf22; del buf22 # reuse
# Source Nodes: [outputs_5], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_1.run(arg19_1, buf47, 65536, grid=grid(65536), stream=stream0)
del arg19_1
buf48 = buf17; del buf17 # reuse
# Source Nodes: [outputs_5], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_2.run(arg20_1, buf48, 256, grid=grid(256), stream=stream0)
del arg20_1
buf49 = empty_strided_cuda((4624, 256), (256, 1), torch.float16)
# Source Nodes: [outputs_5], Original ATen: [aten._to_copy, aten.addmm]
extern_kernels.addmm(buf48, reinterpret_tensor(buf46, (4624, 256), (256, 1), 0), reinterpret_tensor(buf47, (256, 256), (1, 256), 0), alpha=1, beta=1, out=buf49)
del buf46
del buf47
del buf48
return (buf36, buf38, buf40, buf24, buf28, reinterpret_tensor(buf49, (4624, 1, 256), (256, 256, 1), 0), reinterpret_tensor(buf32, (4624, 1, 256), (512, 512, 1), 0), reinterpret_tensor(buf32, (4624, 1, 256), (512, 512, 1), 256), reinterpret_tensor(buf37, (4624, 1, 256), (256, 256, 1), 0), buf39, )
def benchmark_compiled_module(times=10, repeat=10):
from torch._dynamo.testing import rand_strided
from torch._inductor.utils import print_performance
arg0_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg1_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg2_1 = rand_strided((4624, 1, 256), (256, 256, 1), device='cuda:0', dtype=torch.float32)
arg3_1 = rand_strided((4624, 1, 256), (256, 256, 1), device='cuda:0', dtype=torch.float32)
arg4_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg5_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg6_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg7_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg8_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg9_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg10_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg11_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg12_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg13_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
arg14_1 = rand_strided((512, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg15_1 = rand_strided((512, ), (1, ), device='cuda:0', dtype=torch.float32)
arg16_1 = rand_strided((4624, 1, 256), (256, 256, 1), device='cuda:0', dtype=torch.float32)
arg17_1 = rand_strided((257, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg18_1 = rand_strided((257, ), (1, ), device='cuda:0', dtype=torch.float32)
arg19_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg20_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
fn = lambda: call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1, arg9_1, arg10_1, arg11_1, arg12_1, arg13_1, arg14_1, arg15_1, arg16_1, arg17_1, arg18_1, arg19_1, arg20_1])
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)