# 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/5m/c5myotvw3pdemp5pfmlym472pjclzco6isrgqghjub4i7ol7yrkn.py
# Topologically Sorted Source Nodes: [add, tmp, max_1, sub, exp, sum_1], Original ATen: [aten.add, aten.max, aten.sub, aten.exp, aten.sum]
# Source node to ATen node mapping:
#   add => add
#   exp => exp
#   max_1 => max_1
#   sub => sub
#   sum_1 => sum_1
#   tmp => add_1
# Graph fragment:
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_2, %view), kwargs = {})
#   %add_1 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, %view_1), kwargs = {})
#   %max_1 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%add_1, 1, True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_1, %getitem), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
triton_poi_fused_add_exp_max_sub_sum_0 = async_compile.triton('triton_poi_fused_add_exp_max_sub_sum_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: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_exp_max_sub_sum_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_add_exp_max_sub_sum_0(in_ptr0, in_ptr1, 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
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (16*x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (4 + x0 + (16*x1)), xmask)
    tmp3 = tl.load(in_ptr1 + (x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (2 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (3 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp5 + tmp1
    tmp8 = tmp6 + tmp7
    tmp9 = triton_helpers.maximum(tmp4, tmp8)
    tmp11 = tmp10 + tmp1
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.maximum(tmp9, tmp13)
    tmp16 = tmp15 + tmp1
    tmp18 = tmp16 + tmp17
    tmp19 = triton_helpers.maximum(tmp14, tmp18)
    tmp20 = tmp4 - tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp8 - tmp19
    tmp23 = tl_math.exp(tmp22)
    tmp24 = tmp21 + tmp23
    tmp25 = tmp13 - tmp19
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp24 + tmp26
    tmp28 = tmp18 - tmp19
    tmp29 = tl_math.exp(tmp28)
    tmp30 = tmp27 + tmp29
    tl.store(out_ptr0 + (x2), tmp19, xmask)
    tl.store(out_ptr1 + (x2), tmp30, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/7f/c7fumiwtt6kidxj2ourt5ztjgb66maxodqoobflayhv3vaf4yzwz.py
# Topologically Sorted Source Nodes: [add_4, tmp_1], Original ATen: [aten.add]
# Source node to ATen node mapping:
#   add_4 => add_4
#   tmp_1 => add_5
# Graph fragment:
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_7, %view_5), kwargs = {})
#   %add_5 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_4, %view_1), kwargs = {})
triton_poi_fused_add_1 = async_compile.triton('triton_poi_fused_add_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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 6, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_add_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = (xindex // 4)
    x2 = (xindex // 16)
    x1 = (xindex // 4) % 4
    x0 = xindex % 4
    x4 = xindex % 16
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr1 + (x3), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr2 + (1 + (4*x2)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr3 + (x1 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr3 + (8 + x0 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr4 + (x4), xmask, eviction_policy='evict_last')
    tmp1 = tl_math.log(tmp0)
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 * tmp4
    tmp7 = 1.0
    tmp8 = tmp7 - tmp4
    tmp9 = tmp6 * tmp8
    tmp10 = tmp5 + tmp9
    tmp12 = tmp10 + tmp11
    tmp14 = tmp12 + tmp13
    tl.store(out_ptr0 + (x5), tmp14, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/xb/cxbjkkwpz3o6faa425lkz7ibnew4joeb34s3s2vlwo6ps5yzcqik.py
# Topologically Sorted Source Nodes: [mul, mul_1, alpha_1, mul_2, mul_3, alpha_2], Original ATen: [aten.mul, aten.add]
# Source node to ATen node mapping:
#   alpha_1 => add_3
#   alpha_2 => add_7
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   mul_3 => mul_3
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%squeeze, %view_3), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select, %view_4), kwargs = {})
#   %add_3 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%squeeze_1, %view_8), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_3, %view_9), kwargs = {})
#   %add_7 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_2, %mul_3), kwargs = {})
triton_poi_fused_add_mul_2 = async_compile.triton('triton_poi_fused_add_mul_2', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*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_add_mul_2', 'mutated_arg_names': ['in_out_ptr0'], '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_add_mul_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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_ptr0 + (4 + x0 + (16*x1)), xmask)
    tmp3 = tl.load(in_ptr0 + (8 + x0 + (16*x1)), xmask)
    tmp5 = tl.load(in_ptr0 + (12 + x0 + (16*x1)), xmask)
    tmp20 = tl.load(in_ptr1 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr2 + (x2), xmask)
    tmp24 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp26 = tl.load(in_ptr1 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr3 + (x0 + (16*x1)), xmask)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp7 = tmp0 - tmp6
    tmp8 = tl_math.exp(tmp7)
    tmp9 = tmp1 - tmp6
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp8 + tmp10
    tmp12 = tmp3 - tmp6
    tmp13 = tl_math.exp(tmp12)
    tmp14 = tmp11 + tmp13
    tmp15 = tmp5 - tmp6
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp14 + tmp16
    tmp18 = tl_math.log(tmp17)
    tmp19 = tmp18 + tmp6
    tmp21 = tmp19 * tmp20
    tmp23 = tl_math.log(tmp22)
    tmp25 = tmp23 + tmp24
    tmp27 = tmp25 * tmp26
    tmp29 = 1.0
    tmp30 = tmp29 - tmp26
    tmp31 = tmp28 * tmp30
    tmp32 = tmp27 + tmp31
    tmp33 = tmp29 - tmp20
    tmp34 = tmp32 * tmp33
    tmp35 = tmp21 + tmp34
    tl.store(in_out_ptr0 + (x2), tmp35, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/ue/cuen3hq2nipfticixxtzr3g7g3plhadomql2lcdufeljpmsl3i34.py
# Topologically Sorted Source Nodes: [add_8, tmp_2, max_3, sub_4, exp_2, sum_3], Original ATen: [aten.add, aten.max, aten.sub, aten.exp, aten.sum]
# Source node to ATen node mapping:
#   add_8 => add_8
#   exp_2 => exp_2
#   max_3 => max_3
#   sub_4 => sub_4
#   sum_3 => sum_3
#   tmp_2 => add_9
# Graph fragment:
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%view_12, %view_10), kwargs = {})
#   %add_9 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_8, %view_1), kwargs = {})
#   %max_3 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%add_9, 1, True), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_9, %getitem_4), kwargs = {})
#   %exp_2 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_4,), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_2, [1], True), kwargs = {})
triton_poi_fused_add_exp_max_sub_sum_3 = async_compile.triton('triton_poi_fused_add_exp_max_sub_sum_3', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*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_add_exp_max_sub_sum_3', '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_add_exp_max_sub_sum_3(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
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (12 + x0 + (16*x1)), xmask)
    tmp3 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr2 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr2 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr2 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp5 + tmp1
    tmp8 = tmp6 + tmp7
    tmp9 = triton_helpers.maximum(tmp4, tmp8)
    tmp11 = tmp10 + tmp1
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.maximum(tmp9, tmp13)
    tmp16 = tmp15 + tmp1
    tmp18 = tmp16 + tmp17
    tmp19 = triton_helpers.maximum(tmp14, tmp18)
    tmp20 = tmp4 - tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp8 - tmp19
    tmp23 = tl_math.exp(tmp22)
    tmp24 = tmp21 + tmp23
    tmp25 = tmp13 - tmp19
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp24 + tmp26
    tmp28 = tmp18 - tmp19
    tmp29 = tl_math.exp(tmp28)
    tmp30 = tmp27 + tmp29
    tl.store(out_ptr0 + (x2), tmp19, xmask)
    tl.store(out_ptr1 + (x2), tmp30, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/6y/c6y3cpr5dht4m6qhclw6j7ib73qcctr2lilhvjlb7rzrtzfibocs.py
# Topologically Sorted Source Nodes: [tags], Original ATen: [aten._to_copy]
# Source node to ATen node mapping:
#   tags => convert_element_type
# Graph fragment:
#   %convert_element_type : [num_users=3] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%permute_1, torch.int64), kwargs = {})
triton_poi_fused__to_copy_4 = async_compile.triton('triton_poi_fused__to_copy_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=[4, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i64', 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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_4', '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__to_copy_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 4
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + (4*x1)), xmask & ymask)
    tmp1 = tmp0.to(tl.int64)
    tl.store(out_ptr0 + (x1 + (4*y0)), tmp1, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/ge/cge7ucglxa3nobf36fyehqsf3q4xpfp6y3tdnycfaogkmxiauodw.py
# Topologically Sorted Source Nodes: [getitem_19], Original ATen: [aten.slice]
# Source node to ATen node mapping:
#   getitem_19 => slice_2
# Graph fragment:
#   %slice_2 : [num_users=2] = call_function[target=torch.ops.aten.slice.Tensor](args = (%convert_element_type, 0, 1, 9223372036854775807), kwargs = {})
triton_poi_fused_slice_5 = async_compile.triton('triton_poi_fused_slice_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=[4, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*i64', 1: '*i64', 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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_slice_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_slice_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 3
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (4 + x1 + (4*y0)), xmask & ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (y0 + (3*x1)), tmp0, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/nn/cnnyf7lx5frntsngzjjvmmzmxwoqgf5cmldad4ifa62vlbjvqcbk.py
# Topologically Sorted Source Nodes: [tags, getitem_18], Original ATen: [aten._to_copy, aten.slice]
# Source node to ATen node mapping:
#   getitem_18 => slice_1
#   tags => convert_element_type
# Graph fragment:
#   %convert_element_type : [num_users=3] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%permute_1, torch.int64), kwargs = {})
#   %slice_1 : [num_users=2] = call_function[target=torch.ops.aten.slice.Tensor](args = (%convert_element_type, 0, 0, 3), kwargs = {})
triton_poi_fused__to_copy_slice_6 = async_compile.triton('triton_poi_fused__to_copy_slice_6', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[4, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*i64', 1: '*i64', 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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_slice_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__to_copy_slice_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 3
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (x1 + (4*y0)), xmask & ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (y0 + (3*x1)), tmp0, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/6j/c6jtxb5inl36t7vk4uqycgihmocdrrsdlwqwayiqclhsbf2u54zk.py
# Topologically Sorted Source Nodes: [mul_4, mul_5, alpha_3, max_4, sub_6, exp_3, sum_4, getitem_20, trans_score_3, score, sum_5, mul_8, score_1, sub_7], Original ATen: [aten.mul, aten.add, aten.max, aten.sub, aten.exp, aten.sum, aten.index]
# Source node to ATen node mapping:
#   alpha_3 => add_11
#   exp_3 => exp_3
#   getitem_20 => index
#   max_4 => max_4
#   mul_4 => mul_4
#   mul_5 => mul_5
#   mul_8 => mul_8
#   score => add_13
#   score_1 => add_14
#   sub_6 => sub_6
#   sub_7 => sub_7
#   sum_4 => sum_4
#   sum_5 => sum_5
#   trans_score_3 => mul_6
# Graph fragment:
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%squeeze_2, %view_13), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_7, %view_14), kwargs = {})
#   %add_11 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_4, %mul_5), kwargs = {})
#   %max_4 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%add_11, 1, True), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_11, %getitem_6), kwargs = {})
#   %exp_3 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_6,), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_3, [1], True), kwargs = {})
#   %index : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_4, [%slice_1, %slice_2]), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index, %slice_3), kwargs = {})
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_6, %slice_5), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%add_13, [0]), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_10, %select_11), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_5, %mul_8), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%squeeze_3, %add_14), kwargs = {})
triton_poi_fused_add_exp_index_max_mul_sub_sum_7 = async_compile.triton('triton_poi_fused_add_exp_index_max_mul_sub_sum_7', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i64', 2: '*i64', 3: '*fp32', 4: '*fp32', 5: '*i64', 6: '*fp32', 7: '*fp32', 8: '*fp32', 9: '*fp32', 10: '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, 7, 8, 9), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_exp_index_max_mul_sub_sum_7', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 26, '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_exp_index_max_mul_sub_sum_7(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, xnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (3*x0), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (3*x0), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr3 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + (x0), xmask)
    tmp20 = tl.load(in_ptr3 + (4*x0), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (1 + (3*x0)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr1 + (1 + (3*x0)), xmask, eviction_policy='evict_last')
    tmp34 = tl.load(in_ptr3 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp36 = tl.load(in_ptr4 + (4 + x0), xmask)
    tmp45 = tl.load(in_ptr0 + (2 + (3*x0)), xmask, eviction_policy='evict_last')
    tmp50 = tl.load(in_ptr1 + (2 + (3*x0)), xmask, eviction_policy='evict_last')
    tmp56 = tl.load(in_ptr3 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp58 = tl.load(in_ptr4 + (8 + x0), xmask)
    tmp67 = tl.load(in_ptr6 + (4*x0), xmask, eviction_policy='evict_last')
    tmp69 = tl.load(in_ptr7 + (4*x0), xmask, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr8 + (4*x0), xmask, eviction_policy='evict_last')
    tmp77 = tl.load(in_ptr6 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp79 = tl.load(in_ptr7 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp82 = tl.load(in_ptr8 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp86 = tl.load(in_ptr6 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp88 = tl.load(in_ptr7 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp91 = tl.load(in_ptr8 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp95 = tl.load(in_ptr6 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp97 = tl.load(in_ptr7 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp100 = tl.load(in_ptr8 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp117 = tl.load(in_ptr4 + (12 + x0), xmask)
    tmp1 = tl.full([XBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert(((0 <= tmp4) & (tmp4 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp4 < 4")
    tmp7 = tmp6 + tmp1
    tmp8 = tmp6 < 0
    tmp9 = tl.where(tmp8, tmp7, tmp6)
    tl.device_assert(((0 <= tmp9) & (tmp9 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp9 < 4")
    tmp11 = tl.load(in_ptr2 + (tmp9 + (4*tmp4)), xmask, eviction_policy='evict_last')
    tmp13 = tmp11 * tmp12
    tmp15 = tmp14 + tmp1
    tmp16 = tmp14 < 0
    tmp17 = tl.where(tmp16, tmp15, tmp14)
    tl.device_assert(((0 <= tmp17) & (tmp17 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp17 < 4")
    tmp19 = tl.load(in_ptr5 + (tmp17 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp21 = tmp19 * tmp20
    tmp22 = tmp13 + tmp21
    tmp24 = tmp23 + tmp1
    tmp25 = tmp23 < 0
    tmp26 = tl.where(tmp25, tmp24, tmp23)
    tl.device_assert(((0 <= tmp26) & (tmp26 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp26 < 4")
    tmp29 = tmp28 + tmp1
    tmp30 = tmp28 < 0
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tl.device_assert(((0 <= tmp31) & (tmp31 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp31 < 4")
    tmp33 = tl.load(in_ptr2 + (tmp31 + (4*tmp26)), xmask, eviction_policy='evict_last')
    tmp35 = tmp33 * tmp34
    tmp37 = tmp36 + tmp1
    tmp38 = tmp36 < 0
    tmp39 = tl.where(tmp38, tmp37, tmp36)
    tl.device_assert(((0 <= tmp39) & (tmp39 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp39 < 4")
    tmp41 = tl.load(in_ptr5 + (4 + tmp39 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp42 = tmp41 * tmp12
    tmp43 = tmp35 + tmp42
    tmp44 = tmp22 + tmp43
    tmp46 = tmp45 + tmp1
    tmp47 = tmp45 < 0
    tmp48 = tl.where(tmp47, tmp46, tmp45)
    tl.device_assert(((0 <= tmp48) & (tmp48 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp48 < 4")
    tmp51 = tmp50 + tmp1
    tmp52 = tmp50 < 0
    tmp53 = tl.where(tmp52, tmp51, tmp50)
    tl.device_assert(((0 <= tmp53) & (tmp53 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp53 < 4")
    tmp55 = tl.load(in_ptr2 + (tmp53 + (4*tmp48)), xmask, eviction_policy='evict_last')
    tmp57 = tmp55 * tmp56
    tmp59 = tmp58 + tmp1
    tmp60 = tmp58 < 0
    tmp61 = tl.where(tmp60, tmp59, tmp58)
    tl.device_assert(((0 <= tmp61) & (tmp61 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp61 < 4")
    tmp63 = tl.load(in_ptr5 + (8 + tmp61 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp64 = tmp63 * tmp34
    tmp65 = tmp57 + tmp64
    tmp66 = tmp44 + tmp65
    tmp68 = tl_math.log(tmp67)
    tmp70 = tmp68 + tmp69
    tmp71 = tmp70 * tmp56
    tmp73 = 1.0
    tmp74 = tmp73 - tmp56
    tmp75 = tmp72 * tmp74
    tmp76 = tmp71 + tmp75
    tmp78 = tl_math.log(tmp77)
    tmp80 = tmp78 + tmp79
    tmp81 = tmp80 * tmp56
    tmp83 = tmp82 * tmp74
    tmp84 = tmp81 + tmp83
    tmp85 = triton_helpers.maximum(tmp76, tmp84)
    tmp87 = tl_math.log(tmp86)
    tmp89 = tmp87 + tmp88
    tmp90 = tmp89 * tmp56
    tmp92 = tmp91 * tmp74
    tmp93 = tmp90 + tmp92
    tmp94 = triton_helpers.maximum(tmp85, tmp93)
    tmp96 = tl_math.log(tmp95)
    tmp98 = tmp96 + tmp97
    tmp99 = tmp98 * tmp56
    tmp101 = tmp100 * tmp74
    tmp102 = tmp99 + tmp101
    tmp103 = triton_helpers.maximum(tmp94, tmp102)
    tmp104 = tmp76 - tmp103
    tmp105 = tl_math.exp(tmp104)
    tmp106 = tmp84 - tmp103
    tmp107 = tl_math.exp(tmp106)
    tmp108 = tmp105 + tmp107
    tmp109 = tmp93 - tmp103
    tmp110 = tl_math.exp(tmp109)
    tmp111 = tmp108 + tmp110
    tmp112 = tmp102 - tmp103
    tmp113 = tl_math.exp(tmp112)
    tmp114 = tmp111 + tmp113
    tmp115 = tl_math.log(tmp114)
    tmp116 = tmp115 + tmp103
    tmp118 = tmp117 + tmp1
    tmp119 = tmp117 < 0
    tmp120 = tl.where(tmp119, tmp118, tmp117)
    tl.device_assert(((0 <= tmp120) & (tmp120 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp120 < 4")
    tmp122 = tl.load(in_ptr5 + (12 + tmp120 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp123 = tmp122 * tmp56
    tmp124 = tmp123 * tmp56
    tmp125 = tmp66 + tmp124
    tmp126 = tmp116 - tmp125
    tl.store(in_out_ptr0 + (x0), tmp126, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add, tmp, max_1, sub, exp, sum_1], Original ATen: [aten.add, aten.max, aten.sub, aten.exp, aten.sum]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_exp_max_sub_sum_0.run(primals_1, primals_4, buf0, buf1, 16, grid=grid(16), stream=stream0)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add_4, tmp_1], Original ATen: [aten.add]
        triton_poi_fused_add_1.run(buf1, buf0, primals_3, primals_1, primals_4, buf2, 64, grid=grid(64), stream=stream0)
        buf3 = reinterpret_tensor(buf0, (4, 4), (4, 1), 0); del buf0  # reuse
        # Topologically Sorted Source Nodes: [mul, mul_1, alpha_1, mul_2, mul_3, alpha_2], Original ATen: [aten.mul, aten.add]
        triton_poi_fused_add_mul_2.run(buf3, buf2, primals_3, buf1, primals_1, 16, grid=grid(16), stream=stream0)
        del buf2
        buf4 = buf1; del buf1  # reuse
        buf5 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add_8, tmp_2, max_3, sub_4, exp_2, sum_3], Original ATen: [aten.add, aten.max, aten.sub, aten.exp, aten.sum]
        triton_poi_fused_add_exp_max_sub_sum_3.run(buf3, primals_1, primals_4, buf4, buf5, 16, grid=grid(16), stream=stream0)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.int64)
        # Topologically Sorted Source Nodes: [tags], Original ATen: [aten._to_copy]
        triton_poi_fused__to_copy_4.run(primals_2, buf8, 4, 4, grid=grid(4, 4), stream=stream0)
        del primals_2
        buf10 = empty_strided_cuda((3, 4), (1, 3), torch.int64)
        # Topologically Sorted Source Nodes: [getitem_19], Original ATen: [aten.slice]
        triton_poi_fused_slice_5.run(buf8, buf10, 3, 4, grid=grid(3, 4), stream=stream0)
        buf9 = empty_strided_cuda((3, 4), (1, 3), torch.int64)
        # Topologically Sorted Source Nodes: [tags, getitem_18], Original ATen: [aten._to_copy, aten.slice]
        triton_poi_fused__to_copy_slice_6.run(buf8, buf9, 3, 4, grid=grid(3, 4), stream=stream0)
        buf11 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf12 = buf11; del buf11  # reuse
        # Topologically Sorted Source Nodes: [mul_4, mul_5, alpha_3, max_4, sub_6, exp_3, sum_4, getitem_20, trans_score_3, score, sum_5, mul_8, score_1, sub_7], Original ATen: [aten.mul, aten.add, aten.max, aten.sub, aten.exp, aten.sum, aten.index]
        triton_poi_fused_add_exp_index_max_mul_sub_sum_7.run(buf12, buf9, buf10, primals_4, primals_3, buf8, primals_1, buf5, buf4, buf3, 4, grid=grid(4), stream=stream0)
        del buf3
        del buf4
        del buf5
        del buf8
    return (buf12, primals_1, primals_3, primals_4, buf9, buf10, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (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, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4])
    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
from torch import nn
import torch.utils.data
import torch.nn.init as init


def initial_parameter(net, initial_method=None):
    """A method used to initialize the weights of PyTorch models.

    :param net: a PyTorch model
    :param initial_method: str, one of the following initializations

            - xavier_uniform
            - xavier_normal (default)
            - kaiming_normal, or msra
            - kaiming_uniform
            - orthogonal
            - sparse
            - normal
            - uniform

    """
    if initial_method == 'xavier_uniform':
        init_method = init.xavier_uniform_
    elif initial_method == 'xavier_normal':
        init_method = init.xavier_normal_
    elif initial_method == 'kaiming_normal' or initial_method == 'msra':
        init_method = init.kaiming_normal_
    elif initial_method == 'kaiming_uniform':
        init_method = init.kaiming_uniform_
    elif initial_method == 'orthogonal':
        init_method = init.orthogonal_
    elif initial_method == 'sparse':
        init_method = init.sparse_
    elif initial_method == 'normal':
        init_method = init.normal_
    elif initial_method == 'uniform':
        init_method = init.uniform_
    else:
        init_method = init.xavier_normal_

    def weights_init(m):
        if isinstance(m, nn.Conv2d) or isinstance(m, nn.Conv1d) or isinstance(m
            , nn.Conv3d):
            if initial_method is not None:
                init_method(m.weight.data)
            else:
                init.xavier_normal_(m.weight.data)
            init.normal_(m.bias.data)
        elif isinstance(m, nn.LSTM):
            for w in m.parameters():
                if len(w.data.size()) > 1:
                    init_method(w.data)
                else:
                    init.normal_(w.data)
        elif hasattr(m, 'weight') and m.weight.requires_grad:
            init_method(m.weight.data)
        else:
            for w in m.parameters():
                if w.requires_grad:
                    if len(w.data.size()) > 1:
                        init_method(w.data)
                    else:
                        init.normal_(w.data)
    net.apply(weights_init)


def log_sum_exp(x, dim=-1):
    max_value, _ = x.max(dim=dim, keepdim=True)
    res = torch.log(torch.sum(torch.exp(x - max_value), dim=dim, keepdim=True)
        ) + max_value
    return res.squeeze(dim)


class ConditionalRandomField(nn.Module):

    def __init__(self, tag_size, include_start_end_trans=False,
        initial_method=None):
        """
        :param tag_size: int, num of tags
        :param include_start_end_trans: bool, whether to include start/end tag
        """
        super(ConditionalRandomField, self).__init__()
        self.include_start_end_trans = include_start_end_trans
        self.tag_size = tag_size
        self.trans_m = nn.Parameter(torch.randn(tag_size, tag_size))
        if self.include_start_end_trans:
            self.start_scores = nn.Parameter(torch.randn(tag_size))
            self.end_scores = nn.Parameter(torch.randn(tag_size))
        initial_parameter(self, initial_method)

    def reset_parameter(self):
        nn.init.xavier_normal_(self.trans_m)
        if self.include_start_end_trans:
            nn.init.normal_(self.start_scores)
            nn.init.normal_(self.end_scores)

    def _normalizer_likelihood(self, logits, mask):
        """
        Computes the (batch_size,) denominator term for the log-likelihood, which is the
        sum of the likelihoods across all possible state sequences.
        :param logits:FloatTensor, max_len x batch_size x tag_size
        :param mask:ByteTensor, max_len x batch_size
        :return:FloatTensor, batch_size
        """
        seq_len, batch_size, n_tags = logits.size()
        alpha = logits[0]
        if self.include_start_end_trans:
            alpha += self.start_scores.view(1, -1)
        for i in range(1, seq_len):
            emit_score = logits[i].view(batch_size, 1, n_tags)
            trans_score = self.trans_m.view(1, n_tags, n_tags)
            tmp = alpha.view(batch_size, n_tags, 1) + emit_score + trans_score
            alpha = log_sum_exp(tmp, 1) * mask[i].view(batch_size, 1
                ) + alpha * (1 - mask[i]).view(batch_size, 1)
        if self.include_start_end_trans:
            alpha += self.end_scores.view(1, -1)
        return log_sum_exp(alpha, 1)

    def _glod_score(self, logits, tags, mask):
        """
        Compute the score for the gold path.
        :param logits: FloatTensor, max_len x batch_size x tag_size
        :param tags: LongTensor, max_len x batch_size
        :param mask: ByteTensor, max_len x batch_size
        :return:FloatTensor, batch_size
        """
        seq_len, batch_size, _ = logits.size()
        batch_idx = torch.arange(batch_size, dtype=torch.long, device=
            logits.device)
        seq_idx = torch.arange(seq_len, dtype=torch.long, device=logits.device)
        trans_score = self.trans_m[tags[:seq_len - 1], tags[1:]] * mask[1:, :]
        emit_score = logits[seq_idx.view(-1, 1), batch_idx.view(1, -1), tags
            ] * mask
        score = trans_score + emit_score[:seq_len - 1, :]
        score = score.sum(0) + emit_score[-1] * mask[-1]
        if self.include_start_end_trans:
            st_scores = self.start_scores.view(1, -1).repeat(batch_size, 1)[
                batch_idx, tags[0]]
            last_idx = mask.long().sum(0) - 1
            ed_scores = self.end_scores.view(1, -1).repeat(batch_size, 1)[
                batch_idx, tags[last_idx, batch_idx]]
            score += st_scores + ed_scores
        return score

    def forward(self, feats, tags, mask):
        """
        Calculate the neg log likelihood
        :param feats:FloatTensor, batch_size x max_len x tag_size
        :param tags:LongTensor, batch_size x max_len
        :param mask:ByteTensor batch_size x max_len
        :return:FloatTensor, batch_size
        """
        feats = feats.transpose(0, 1)
        tags = tags.transpose(0, 1).long()
        mask = mask.transpose(0, 1).float()
        all_path_score = self._normalizer_likelihood(feats, mask)
        gold_path_score = self._glod_score(feats, tags, mask)
        return all_path_score - gold_path_score

    def viterbi_decode(self, data, mask, get_score=False):
        """
        Given a feats matrix, return best decode path and best score.
        :param data:FloatTensor, batch_size x max_len x tag_size
        :param mask:ByteTensor batch_size x max_len
        :param get_score: bool, whether to output the decode score.
        :return: scores, paths
        """
        batch_size, seq_len, n_tags = data.size()
        data = data.transpose(0, 1).data
        mask = mask.transpose(0, 1).data.float()
        vpath = data.new_zeros((seq_len, batch_size, n_tags), dtype=torch.long)
        vscore = data[0]
        if self.include_start_end_trans:
            vscore += self.start_scores.view(1, -1)
        for i in range(1, seq_len):
            prev_score = vscore.view(batch_size, n_tags, 1)
            cur_score = data[i].view(batch_size, 1, n_tags)
            trans_score = self.trans_m.view(1, n_tags, n_tags).data
            score = prev_score + trans_score + cur_score
            best_score, best_dst = score.max(1)
            vpath[i] = best_dst
            vscore = best_score * mask[i].view(batch_size, 1) + vscore * (1 -
                mask[i]).view(batch_size, 1)
        if self.include_start_end_trans:
            vscore += self.end_scores.view(1, -1)
        batch_idx = torch.arange(batch_size, dtype=torch.long, device=data.
            device)
        seq_idx = torch.arange(seq_len, dtype=torch.long, device=data.device)
        lens = mask.long().sum(0) - 1
        idxes = (lens.view(1, -1) - seq_idx.view(-1, 1)) % seq_len
        ans = data.new_empty((seq_len, batch_size), dtype=torch.long)
        ans_score, last_tags = vscore.max(1)
        ans[idxes[0], batch_idx] = last_tags
        for i in range(seq_len - 1):
            last_tags = vpath[idxes[i], batch_idx, last_tags]
            ans[idxes[i + 1], batch_idx] = last_tags
        if get_score:
            return ans_score, ans.transpose(0, 1)
        return ans.transpose(0, 1)


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


def get_init_inputs():
    return [[], {'tag_size': 4}]

import torch
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
from torch import nn
import torch.utils.data
import torch.nn.init as init
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_add_exp_max_sub_sum_0(in_ptr0, in_ptr1, 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
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + 16 * x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
    tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + 16 * x1), xmask, eviction_policy='evict_last'
        )
    tmp7 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (2 + 16 * x1), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (3 + 16 * x1), xmask, eviction_policy=
        'evict_last')
    tmp17 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp5 + tmp1
    tmp8 = tmp6 + tmp7
    tmp9 = triton_helpers.maximum(tmp4, tmp8)
    tmp11 = tmp10 + tmp1
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.maximum(tmp9, tmp13)
    tmp16 = tmp15 + tmp1
    tmp18 = tmp16 + tmp17
    tmp19 = triton_helpers.maximum(tmp14, tmp18)
    tmp20 = tmp4 - tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp8 - tmp19
    tmp23 = tl_math.exp(tmp22)
    tmp24 = tmp21 + tmp23
    tmp25 = tmp13 - tmp19
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp24 + tmp26
    tmp28 = tmp18 - tmp19
    tmp29 = tl_math.exp(tmp28)
    tmp30 = tmp27 + tmp29
    tl.store(out_ptr0 + x2, tmp19, xmask)
    tl.store(out_ptr1 + x2, tmp30, xmask)


@triton.jit
def triton_poi_fused_add_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex // 4
    x2 = xindex // 16
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x4 = xindex % 16
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr2 + (1 + 4 * x2), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr3 + (x1 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp11 = tl.load(in_ptr3 + (8 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp13 = tl.load(in_ptr4 + x4, xmask, eviction_policy='evict_last')
    tmp1 = tl_math.log(tmp0)
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 * tmp4
    tmp7 = 1.0
    tmp8 = tmp7 - tmp4
    tmp9 = tmp6 * tmp8
    tmp10 = tmp5 + tmp9
    tmp12 = tmp10 + tmp11
    tmp14 = tmp12 + tmp13
    tl.store(out_ptr0 + x5, tmp14, xmask)


@triton.jit
def triton_poi_fused_add_mul_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, 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_ptr0 + (4 + x0 + 16 * x1), xmask)
    tmp3 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
    tmp5 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
    tmp20 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr2 + x2, xmask)
    tmp24 = tl.load(in_out_ptr0 + x2, xmask)
    tmp26 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp28 = tl.load(in_ptr3 + (x0 + 16 * x1), xmask)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp7 = tmp0 - tmp6
    tmp8 = tl_math.exp(tmp7)
    tmp9 = tmp1 - tmp6
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp8 + tmp10
    tmp12 = tmp3 - tmp6
    tmp13 = tl_math.exp(tmp12)
    tmp14 = tmp11 + tmp13
    tmp15 = tmp5 - tmp6
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp14 + tmp16
    tmp18 = tl_math.log(tmp17)
    tmp19 = tmp18 + tmp6
    tmp21 = tmp19 * tmp20
    tmp23 = tl_math.log(tmp22)
    tmp25 = tmp23 + tmp24
    tmp27 = tmp25 * tmp26
    tmp29 = 1.0
    tmp30 = tmp29 - tmp26
    tmp31 = tmp28 * tmp30
    tmp32 = tmp27 + tmp31
    tmp33 = tmp29 - tmp20
    tmp34 = tmp32 * tmp33
    tmp35 = tmp21 + tmp34
    tl.store(in_out_ptr0 + x2, tmp35, xmask)


@triton.jit
def triton_poi_fused_add_exp_max_sub_sum_3(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
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (12 + x0 + 16 * x1), xmask)
    tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr2 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr2 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr2 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp5 + tmp1
    tmp8 = tmp6 + tmp7
    tmp9 = triton_helpers.maximum(tmp4, tmp8)
    tmp11 = tmp10 + tmp1
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.maximum(tmp9, tmp13)
    tmp16 = tmp15 + tmp1
    tmp18 = tmp16 + tmp17
    tmp19 = triton_helpers.maximum(tmp14, tmp18)
    tmp20 = tmp4 - tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp8 - tmp19
    tmp23 = tl_math.exp(tmp22)
    tmp24 = tmp21 + tmp23
    tmp25 = tmp13 - tmp19
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp24 + tmp26
    tmp28 = tmp18 - tmp19
    tmp29 = tl_math.exp(tmp28)
    tmp30 = tmp27 + tmp29
    tl.store(out_ptr0 + x2, tmp19, xmask)
    tl.store(out_ptr1 + x2, tmp30, xmask)


@triton.jit
def triton_poi_fused__to_copy_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK:
    tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 4
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask)
    tmp1 = tmp0.to(tl.int64)
    tl.store(out_ptr0 + (x1 + 4 * y0), tmp1, xmask & ymask)


@triton.jit
def triton_poi_fused_slice_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 3
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (4 + x1 + 4 * y0), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (y0 + 3 * x1), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused__to_copy_slice_6(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 3
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (x1 + 4 * y0), xmask & ymask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 3 * x1), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_add_exp_index_max_mul_sub_sum_7(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 3 * x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + 3 * x0, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr4 + x0, xmask)
    tmp20 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (1 + 3 * x0), xmask, eviction_policy='evict_last'
        )
    tmp28 = tl.load(in_ptr1 + (1 + 3 * x0), xmask, eviction_policy='evict_last'
        )
    tmp34 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp36 = tl.load(in_ptr4 + (4 + x0), xmask)
    tmp45 = tl.load(in_ptr0 + (2 + 3 * x0), xmask, eviction_policy='evict_last'
        )
    tmp50 = tl.load(in_ptr1 + (2 + 3 * x0), xmask, eviction_policy='evict_last'
        )
    tmp56 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp58 = tl.load(in_ptr4 + (8 + x0), xmask)
    tmp67 = tl.load(in_ptr6 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp69 = tl.load(in_ptr7 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr8 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp77 = tl.load(in_ptr6 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp79 = tl.load(in_ptr7 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp82 = tl.load(in_ptr8 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp86 = tl.load(in_ptr6 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp88 = tl.load(in_ptr7 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp91 = tl.load(in_ptr8 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp95 = tl.load(in_ptr6 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp97 = tl.load(in_ptr7 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp100 = tl.load(in_ptr8 + (3 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp117 = tl.load(in_ptr4 + (12 + x0), xmask)
    tmp1 = tl.full([XBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp4 < 4')
    tmp7 = tmp6 + tmp1
    tmp8 = tmp6 < 0
    tmp9 = tl.where(tmp8, tmp7, tmp6)
    tl.device_assert((0 <= tmp9) & (tmp9 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp9 < 4')
    tmp11 = tl.load(in_ptr2 + (tmp9 + 4 * tmp4), xmask, eviction_policy=
        'evict_last')
    tmp13 = tmp11 * tmp12
    tmp15 = tmp14 + tmp1
    tmp16 = tmp14 < 0
    tmp17 = tl.where(tmp16, tmp15, tmp14)
    tl.device_assert((0 <= tmp17) & (tmp17 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp17 < 4')
    tmp19 = tl.load(in_ptr5 + (tmp17 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp21 = tmp19 * tmp20
    tmp22 = tmp13 + tmp21
    tmp24 = tmp23 + tmp1
    tmp25 = tmp23 < 0
    tmp26 = tl.where(tmp25, tmp24, tmp23)
    tl.device_assert((0 <= tmp26) & (tmp26 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp26 < 4')
    tmp29 = tmp28 + tmp1
    tmp30 = tmp28 < 0
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tl.device_assert((0 <= tmp31) & (tmp31 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp31 < 4')
    tmp33 = tl.load(in_ptr2 + (tmp31 + 4 * tmp26), xmask, eviction_policy=
        'evict_last')
    tmp35 = tmp33 * tmp34
    tmp37 = tmp36 + tmp1
    tmp38 = tmp36 < 0
    tmp39 = tl.where(tmp38, tmp37, tmp36)
    tl.device_assert((0 <= tmp39) & (tmp39 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp39 < 4')
    tmp41 = tl.load(in_ptr5 + (4 + tmp39 + 16 * x0), xmask, eviction_policy
        ='evict_last')
    tmp42 = tmp41 * tmp12
    tmp43 = tmp35 + tmp42
    tmp44 = tmp22 + tmp43
    tmp46 = tmp45 + tmp1
    tmp47 = tmp45 < 0
    tmp48 = tl.where(tmp47, tmp46, tmp45)
    tl.device_assert((0 <= tmp48) & (tmp48 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp48 < 4')
    tmp51 = tmp50 + tmp1
    tmp52 = tmp50 < 0
    tmp53 = tl.where(tmp52, tmp51, tmp50)
    tl.device_assert((0 <= tmp53) & (tmp53 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp53 < 4')
    tmp55 = tl.load(in_ptr2 + (tmp53 + 4 * tmp48), xmask, eviction_policy=
        'evict_last')
    tmp57 = tmp55 * tmp56
    tmp59 = tmp58 + tmp1
    tmp60 = tmp58 < 0
    tmp61 = tl.where(tmp60, tmp59, tmp58)
    tl.device_assert((0 <= tmp61) & (tmp61 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp61 < 4')
    tmp63 = tl.load(in_ptr5 + (8 + tmp61 + 16 * x0), xmask, eviction_policy
        ='evict_last')
    tmp64 = tmp63 * tmp34
    tmp65 = tmp57 + tmp64
    tmp66 = tmp44 + tmp65
    tmp68 = tl_math.log(tmp67)
    tmp70 = tmp68 + tmp69
    tmp71 = tmp70 * tmp56
    tmp73 = 1.0
    tmp74 = tmp73 - tmp56
    tmp75 = tmp72 * tmp74
    tmp76 = tmp71 + tmp75
    tmp78 = tl_math.log(tmp77)
    tmp80 = tmp78 + tmp79
    tmp81 = tmp80 * tmp56
    tmp83 = tmp82 * tmp74
    tmp84 = tmp81 + tmp83
    tmp85 = triton_helpers.maximum(tmp76, tmp84)
    tmp87 = tl_math.log(tmp86)
    tmp89 = tmp87 + tmp88
    tmp90 = tmp89 * tmp56
    tmp92 = tmp91 * tmp74
    tmp93 = tmp90 + tmp92
    tmp94 = triton_helpers.maximum(tmp85, tmp93)
    tmp96 = tl_math.log(tmp95)
    tmp98 = tmp96 + tmp97
    tmp99 = tmp98 * tmp56
    tmp101 = tmp100 * tmp74
    tmp102 = tmp99 + tmp101
    tmp103 = triton_helpers.maximum(tmp94, tmp102)
    tmp104 = tmp76 - tmp103
    tmp105 = tl_math.exp(tmp104)
    tmp106 = tmp84 - tmp103
    tmp107 = tl_math.exp(tmp106)
    tmp108 = tmp105 + tmp107
    tmp109 = tmp93 - tmp103
    tmp110 = tl_math.exp(tmp109)
    tmp111 = tmp108 + tmp110
    tmp112 = tmp102 - tmp103
    tmp113 = tl_math.exp(tmp112)
    tmp114 = tmp111 + tmp113
    tmp115 = tl_math.log(tmp114)
    tmp116 = tmp115 + tmp103
    tmp118 = tmp117 + tmp1
    tmp119 = tmp117 < 0
    tmp120 = tl.where(tmp119, tmp118, tmp117)
    tl.device_assert((0 <= tmp120) & (tmp120 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp120 < 4')
    tmp122 = tl.load(in_ptr5 + (12 + tmp120 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp123 = tmp122 * tmp56
    tmp124 = tmp123 * tmp56
    tmp125 = tmp66 + tmp124
    tmp126 = tmp116 - tmp125
    tl.store(in_out_ptr0 + x0, tmp126, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_exp_max_sub_sum_0[grid(16)](primals_1,
            primals_4, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_1[grid(64)](buf1, buf0, primals_3, primals_1,
            primals_4, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf3 = reinterpret_tensor(buf0, (4, 4), (4, 1), 0)
        del buf0
        triton_poi_fused_add_mul_2[grid(16)](buf3, buf2, primals_3, buf1,
            primals_1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf2
        buf4 = buf1
        del buf1
        buf5 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        triton_poi_fused_add_exp_max_sub_sum_3[grid(16)](buf3, primals_1,
            primals_4, buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.int64)
        triton_poi_fused__to_copy_4[grid(4, 4)](primals_2, buf8, 4, 4,
            XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1)
        del primals_2
        buf10 = empty_strided_cuda((3, 4), (1, 3), torch.int64)
        triton_poi_fused_slice_5[grid(3, 4)](buf8, buf10, 3, 4, XBLOCK=4,
            YBLOCK=4, num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((3, 4), (1, 3), torch.int64)
        triton_poi_fused__to_copy_slice_6[grid(3, 4)](buf8, buf9, 3, 4,
            XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1)
        buf11 = empty_strided_cuda((4,), (1,), torch.float32)
        buf12 = buf11
        del buf11
        triton_poi_fused_add_exp_index_max_mul_sub_sum_7[grid(4)](buf12,
            buf9, buf10, primals_4, primals_3, buf8, primals_1, buf5, buf4,
            buf3, 4, XBLOCK=4, num_warps=1, num_stages=1)
        del buf3
        del buf4
        del buf5
        del buf8
    return buf12, primals_1, primals_3, primals_4, buf9, buf10


def initial_parameter(net, initial_method=None):
    """A method used to initialize the weights of PyTorch models.

    :param net: a PyTorch model
    :param initial_method: str, one of the following initializations

            - xavier_uniform
            - xavier_normal (default)
            - kaiming_normal, or msra
            - kaiming_uniform
            - orthogonal
            - sparse
            - normal
            - uniform

    """
    if initial_method == 'xavier_uniform':
        init_method = init.xavier_uniform_
    elif initial_method == 'xavier_normal':
        init_method = init.xavier_normal_
    elif initial_method == 'kaiming_normal' or initial_method == 'msra':
        init_method = init.kaiming_normal_
    elif initial_method == 'kaiming_uniform':
        init_method = init.kaiming_uniform_
    elif initial_method == 'orthogonal':
        init_method = init.orthogonal_
    elif initial_method == 'sparse':
        init_method = init.sparse_
    elif initial_method == 'normal':
        init_method = init.normal_
    elif initial_method == 'uniform':
        init_method = init.uniform_
    else:
        init_method = init.xavier_normal_

    def weights_init(m):
        if isinstance(m, nn.Conv2d) or isinstance(m, nn.Conv1d) or isinstance(m
            , nn.Conv3d):
            if initial_method is not None:
                init_method(m.weight.data)
            else:
                init.xavier_normal_(m.weight.data)
            init.normal_(m.bias.data)
        elif isinstance(m, nn.LSTM):
            for w in m.parameters():
                if len(w.data.size()) > 1:
                    init_method(w.data)
                else:
                    init.normal_(w.data)
        elif hasattr(m, 'weight') and m.weight.requires_grad:
            init_method(m.weight.data)
        else:
            for w in m.parameters():
                if w.requires_grad:
                    if len(w.data.size()) > 1:
                        init_method(w.data)
                    else:
                        init.normal_(w.data)
    net.apply(weights_init)


def log_sum_exp(x, dim=-1):
    max_value, _ = x.max(dim=dim, keepdim=True)
    res = torch.log(torch.sum(torch.exp(x - max_value), dim=dim, keepdim=True)
        ) + max_value
    return res.squeeze(dim)


class ConditionalRandomFieldNew(nn.Module):

    def __init__(self, tag_size, include_start_end_trans=False,
        initial_method=None):
        """
        :param tag_size: int, num of tags
        :param include_start_end_trans: bool, whether to include start/end tag
        """
        super(ConditionalRandomFieldNew, self).__init__()
        self.include_start_end_trans = include_start_end_trans
        self.tag_size = tag_size
        self.trans_m = nn.Parameter(torch.randn(tag_size, tag_size))
        if self.include_start_end_trans:
            self.start_scores = nn.Parameter(torch.randn(tag_size))
            self.end_scores = nn.Parameter(torch.randn(tag_size))
        initial_parameter(self, initial_method)

    def reset_parameter(self):
        nn.init.xavier_normal_(self.trans_m)
        if self.include_start_end_trans:
            nn.init.normal_(self.start_scores)
            nn.init.normal_(self.end_scores)

    def _normalizer_likelihood(self, logits, mask):
        """
        Computes the (batch_size,) denominator term for the log-likelihood, which is the
        sum of the likelihoods across all possible state sequences.
        :param logits:FloatTensor, max_len x batch_size x tag_size
        :param mask:ByteTensor, max_len x batch_size
        :return:FloatTensor, batch_size
        """
        seq_len, batch_size, n_tags = logits.size()
        alpha = logits[0]
        if self.include_start_end_trans:
            alpha += self.start_scores.view(1, -1)
        for i in range(1, seq_len):
            emit_score = logits[i].view(batch_size, 1, n_tags)
            trans_score = self.trans_m.view(1, n_tags, n_tags)
            tmp = alpha.view(batch_size, n_tags, 1) + emit_score + trans_score
            alpha = log_sum_exp(tmp, 1) * mask[i].view(batch_size, 1
                ) + alpha * (1 - mask[i]).view(batch_size, 1)
        if self.include_start_end_trans:
            alpha += self.end_scores.view(1, -1)
        return log_sum_exp(alpha, 1)

    def _glod_score(self, logits, tags, mask):
        """
        Compute the score for the gold path.
        :param logits: FloatTensor, max_len x batch_size x tag_size
        :param tags: LongTensor, max_len x batch_size
        :param mask: ByteTensor, max_len x batch_size
        :return:FloatTensor, batch_size
        """
        seq_len, batch_size, _ = logits.size()
        batch_idx = torch.arange(batch_size, dtype=torch.long, device=
            logits.device)
        seq_idx = torch.arange(seq_len, dtype=torch.long, device=logits.device)
        trans_score = self.trans_m[tags[:seq_len - 1], tags[1:]] * mask[1:, :]
        emit_score = logits[seq_idx.view(-1, 1), batch_idx.view(1, -1), tags
            ] * mask
        score = trans_score + emit_score[:seq_len - 1, :]
        score = score.sum(0) + emit_score[-1] * mask[-1]
        if self.include_start_end_trans:
            st_scores = self.start_scores.view(1, -1).repeat(batch_size, 1)[
                batch_idx, tags[0]]
            last_idx = mask.long().sum(0) - 1
            ed_scores = self.end_scores.view(1, -1).repeat(batch_size, 1)[
                batch_idx, tags[last_idx, batch_idx]]
            score += st_scores + ed_scores
        return score

    def viterbi_decode(self, data, mask, get_score=False):
        """
        Given a feats matrix, return best decode path and best score.
        :param data:FloatTensor, batch_size x max_len x tag_size
        :param mask:ByteTensor batch_size x max_len
        :param get_score: bool, whether to output the decode score.
        :return: scores, paths
        """
        batch_size, seq_len, n_tags = data.size()
        data = data.transpose(0, 1).data
        mask = mask.transpose(0, 1).data.float()
        vpath = data.new_zeros((seq_len, batch_size, n_tags), dtype=torch.long)
        vscore = data[0]
        if self.include_start_end_trans:
            vscore += self.start_scores.view(1, -1)
        for i in range(1, seq_len):
            prev_score = vscore.view(batch_size, n_tags, 1)
            cur_score = data[i].view(batch_size, 1, n_tags)
            trans_score = self.trans_m.view(1, n_tags, n_tags).data
            score = prev_score + trans_score + cur_score
            best_score, best_dst = score.max(1)
            vpath[i] = best_dst
            vscore = best_score * mask[i].view(batch_size, 1) + vscore * (1 -
                mask[i]).view(batch_size, 1)
        if self.include_start_end_trans:
            vscore += self.end_scores.view(1, -1)
        batch_idx = torch.arange(batch_size, dtype=torch.long, device=data.
            device)
        seq_idx = torch.arange(seq_len, dtype=torch.long, device=data.device)
        lens = mask.long().sum(0) - 1
        idxes = (lens.view(1, -1) - seq_idx.view(-1, 1)) % seq_len
        ans = data.new_empty((seq_len, batch_size), dtype=torch.long)
        ans_score, last_tags = vscore.max(1)
        ans[idxes[0], batch_idx] = last_tags
        for i in range(seq_len - 1):
            last_tags = vpath[idxes[i], batch_idx, last_tags]
            ans[idxes[i + 1], batch_idx] = last_tags
        if get_score:
            return ans_score, ans.transpose(0, 1)
        return ans.transpose(0, 1)

    def forward(self, input_0, input_1, input_2):
        primals_2 = self.trans_m
        primals_1 = input_0
        primals_3 = input_1
        primals_4 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0]
