# 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_1/inductor_cache/t6/ct63xddmvrwrurfmzfkl2onel7brbvegrcdo7jl4mmzcpzcc76ah.py
# Topologically Sorted Source Nodes: [add_1, cur, logsumexp], Original ATen: [aten.add, aten.logsumexp]
# Source node to ATen node mapping:
#   add_1 => add_1
#   cur => add_2
#   logsumexp => abs_1, amax, eq, exp, full_default, sub, sum_1, where
# Graph fragment:
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%unsqueeze, %unsqueeze_1), kwargs = {})
#   %add_2 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_1, %permute_2), kwargs = {})
#   %amax : [num_users=2] = call_function[target=torch.ops.aten.amax.default](args = (%add_2, [1], True), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%amax,), kwargs = {})
#   %eq : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%abs_1, inf), kwargs = {})
#   %full_default : [num_users=4] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq, %full_default, %amax), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_2, %where), 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]), kwargs = {})
triton_poi_fused_add_logsumexp_0 = async_compile.triton('triton_poi_fused_add_logsumexp_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: '*i64', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), '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_logsumexp_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 13, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_logsumexp_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (0))
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + (16*x1), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (4 + x0 + (16*x1)), xmask)
    tmp8 = tl.load(in_ptr2 + (4*x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (1))
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp12 = tl.load(in_ptr1 + (1 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr2 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr0 + (2))
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK])
    tmp21 = tl.load(in_ptr1 + (2 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr2 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (3))
    tmp29 = tl.broadcast_to(tmp28, [XBLOCK])
    tmp30 = tl.load(in_ptr1 + (3 + (16*x1)), xmask, eviction_policy='evict_last')
    tmp34 = tl.load(in_ptr2 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp3 = tmp2.to(tl.float32)
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5.to(tl.float32)
    tmp7 = tmp4 + tmp6
    tmp9 = tmp7 + tmp8
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 + tmp13
    tmp15 = tmp14 + tmp6
    tmp17 = tmp15 + tmp16
    tmp18 = triton_helpers.maximum(tmp9, tmp17)
    tmp22 = tmp21.to(tl.float32)
    tmp23 = tmp20 + tmp22
    tmp24 = tmp23 + tmp6
    tmp26 = tmp24 + tmp25
    tmp27 = triton_helpers.maximum(tmp18, tmp26)
    tmp31 = tmp30.to(tl.float32)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp32 + tmp6
    tmp35 = tmp33 + tmp34
    tmp36 = triton_helpers.maximum(tmp27, tmp35)
    tmp37 = tl_math.abs(tmp36)
    tmp38 = float("inf")
    tmp39 = tmp37 == tmp38
    tmp40 = 0.0
    tmp41 = tl.where(tmp39, tmp40, tmp36)
    tmp42 = tmp9 - tmp41
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp17 - tmp41
    tmp45 = tl_math.exp(tmp44)
    tmp46 = tmp43 + tmp45
    tmp47 = tmp26 - tmp41
    tmp48 = tl_math.exp(tmp47)
    tmp49 = tmp46 + tmp48
    tmp50 = tmp35 - tmp41
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp49 + tmp51
    tl.store(out_ptr0 + (x2), tmp36, xmask)
    tl.store(out_ptr1 + (x2), tmp52, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/ip/cip4b45ktm4voqrpp53advyy56sjyrnwf2eiklzwxplbmwnudd6o.py
# Topologically Sorted Source Nodes: [logsumexp, add_3, cur_1, logsumexp_1], Original ATen: [aten.logsumexp, aten.add]
# Source node to ATen node mapping:
#   add_3 => add_4
#   cur_1 => add_5
#   logsumexp => full_default
#   logsumexp_1 => abs_2, amax_1, eq_1, exp_1, sub_1, sum_2, where_1
# Graph fragment:
#   %full_default : [num_users=4] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%unsqueeze_2, %unsqueeze_3), kwargs = {})
#   %add_5 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_4, %permute_2), kwargs = {})
#   %amax_1 : [num_users=2] = call_function[target=torch.ops.aten.amax.default](args = (%add_5, [1], True), kwargs = {})
#   %abs_2 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%amax_1,), kwargs = {})
#   %eq_1 : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%abs_2, inf), kwargs = {})
#   %where_1 : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq_1, %full_default, %amax_1), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_5, %where_1), kwargs = {})
#   %exp_1 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_1, [1]), kwargs = {})
triton_poi_fused_add_logsumexp_1 = async_compile.triton('triton_poi_fused_add_logsumexp_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*i64', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), '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_logsumexp_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 13, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_logsumexp_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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')
    tmp2 = tl.load(in_ptr1 + (4*x1), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (8 + x0 + (16*x1)), xmask)
    tmp12 = tl.load(in_ptr3 + (4*x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr1 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr3 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr1 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp33 = tl.load(in_ptr3 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp36 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp38 = tl.load(in_ptr1 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp44 = tl.load(in_ptr3 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp1 = tl_math.log(tmp0)
    tmp3 = tl_math.abs(tmp2)
    tmp4 = float("inf")
    tmp5 = tmp3 == tmp4
    tmp6 = 0.0
    tmp7 = tl.where(tmp5, tmp6, tmp2)
    tmp8 = tmp1 + tmp7
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tl_math.log(tmp14)
    tmp17 = tl_math.abs(tmp16)
    tmp18 = tmp17 == tmp4
    tmp19 = tl.where(tmp18, tmp6, tmp16)
    tmp20 = tmp15 + tmp19
    tmp21 = tmp20 + tmp10
    tmp23 = tmp21 + tmp22
    tmp24 = triton_helpers.maximum(tmp13, tmp23)
    tmp26 = tl_math.log(tmp25)
    tmp28 = tl_math.abs(tmp27)
    tmp29 = tmp28 == tmp4
    tmp30 = tl.where(tmp29, tmp6, tmp27)
    tmp31 = tmp26 + tmp30
    tmp32 = tmp31 + tmp10
    tmp34 = tmp32 + tmp33
    tmp35 = triton_helpers.maximum(tmp24, tmp34)
    tmp37 = tl_math.log(tmp36)
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp39 == tmp4
    tmp41 = tl.where(tmp40, tmp6, tmp38)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp42 + tmp10
    tmp45 = tmp43 + tmp44
    tmp46 = triton_helpers.maximum(tmp35, tmp45)
    tmp47 = tl_math.abs(tmp46)
    tmp48 = tmp47 == tmp4
    tmp49 = tl.where(tmp48, tmp6, tmp46)
    tmp50 = tmp13 - tmp49
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp23 - tmp49
    tmp53 = tl_math.exp(tmp52)
    tmp54 = tmp51 + tmp53
    tmp55 = tmp34 - tmp49
    tmp56 = tl_math.exp(tmp55)
    tmp57 = tmp54 + tmp56
    tmp58 = tmp45 - tmp49
    tmp59 = tl_math.exp(tmp58)
    tmp60 = tmp57 + tmp59
    tl.store(out_ptr0 + (x2), tmp46, xmask)
    tl.store(out_ptr1 + (x2), tmp60, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/dy/cdy57vwzdvcdqwbotoym6jkngdeywqpl7c6kmxpvecoo7otey4bd.py
# Topologically Sorted Source Nodes: [logsumexp, add_5, cur_2, logsumexp_2], Original ATen: [aten.logsumexp, aten.add]
# Source node to ATen node mapping:
#   add_5 => add_7
#   cur_2 => add_8
#   logsumexp => full_default
#   logsumexp_2 => abs_3, amax_2, eq_2, exp_2, sub_2, sum_3, where_2
# Graph fragment:
#   %full_default : [num_users=4] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%unsqueeze_4, %unsqueeze_5), kwargs = {})
#   %add_8 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_7, %permute_2), kwargs = {})
#   %amax_2 : [num_users=2] = call_function[target=torch.ops.aten.amax.default](args = (%add_8, [1], True), kwargs = {})
#   %abs_3 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%amax_2,), kwargs = {})
#   %eq_2 : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%abs_3, inf), kwargs = {})
#   %where_2 : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq_2, %full_default, %amax_2), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_8, %where_2), kwargs = {})
#   %exp_2 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_2, [1]), kwargs = {})
triton_poi_fused_add_logsumexp_2 = async_compile.triton('triton_poi_fused_add_logsumexp_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: '*i64', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), '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_logsumexp_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 13, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_logsumexp_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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')
    tmp2 = tl.load(in_ptr1 + (4*x1), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (12 + x0 + (16*x1)), xmask)
    tmp12 = tl.load(in_ptr3 + (4*x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr1 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr3 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr1 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp33 = tl.load(in_ptr3 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp36 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp38 = tl.load(in_ptr1 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp44 = tl.load(in_ptr3 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp1 = tl_math.log(tmp0)
    tmp3 = tl_math.abs(tmp2)
    tmp4 = float("inf")
    tmp5 = tmp3 == tmp4
    tmp6 = 0.0
    tmp7 = tl.where(tmp5, tmp6, tmp2)
    tmp8 = tmp1 + tmp7
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tl_math.log(tmp14)
    tmp17 = tl_math.abs(tmp16)
    tmp18 = tmp17 == tmp4
    tmp19 = tl.where(tmp18, tmp6, tmp16)
    tmp20 = tmp15 + tmp19
    tmp21 = tmp20 + tmp10
    tmp23 = tmp21 + tmp22
    tmp24 = triton_helpers.maximum(tmp13, tmp23)
    tmp26 = tl_math.log(tmp25)
    tmp28 = tl_math.abs(tmp27)
    tmp29 = tmp28 == tmp4
    tmp30 = tl.where(tmp29, tmp6, tmp27)
    tmp31 = tmp26 + tmp30
    tmp32 = tmp31 + tmp10
    tmp34 = tmp32 + tmp33
    tmp35 = triton_helpers.maximum(tmp24, tmp34)
    tmp37 = tl_math.log(tmp36)
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp39 == tmp4
    tmp41 = tl.where(tmp40, tmp6, tmp38)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp42 + tmp10
    tmp45 = tmp43 + tmp44
    tmp46 = triton_helpers.maximum(tmp35, tmp45)
    tmp47 = tl_math.abs(tmp46)
    tmp48 = tmp47 == tmp4
    tmp49 = tl.where(tmp48, tmp6, tmp46)
    tmp50 = tmp13 - tmp49
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp23 - tmp49
    tmp53 = tl_math.exp(tmp52)
    tmp54 = tmp51 + tmp53
    tmp55 = tmp34 - tmp49
    tmp56 = tl_math.exp(tmp55)
    tmp57 = tmp54 + tmp56
    tmp58 = tmp45 - tmp49
    tmp59 = tl_math.exp(tmp58)
    tmp60 = tmp57 + tmp59
    tl.store(out_ptr0 + (x2), tmp46, xmask)
    tl.store(out_ptr1 + (x2), tmp60, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/nq/cnqhciwfke5eb5tu7d76qfs4bmxzvzqvaqtr5kz5ywnopvcq7jfb.py
# Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
# Source node to ATen node mapping:
#   stack => cat
# Graph fragment:
#   %cat : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%gather_1, %index, %index_1, %index_2, %gather_2],), kwargs = {})
triton_poi_fused_stack_3 = async_compile.triton('triton_poi_fused_stack_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=[32], 
    filename=__file__,
    triton_meta={'signature': {0: '*i64', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_stack_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 8, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_stack_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 20
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4*x0), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp6 = tl.full([XBLOCK], 4, tl.int32)
    tmp7 = tmp5 + tmp6
    tmp8 = tmp5 < 0
    tmp9 = tl.where(tmp8, tmp7, tmp5)
    tl.device_assert(((0 <= tl.broadcast_to(tmp9, [XBLOCK])) & (tl.broadcast_to(tmp9, [XBLOCK]) < 4)) | ~(tmp4 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp9, [XBLOCK]) < 4")
    tmp11 = tl.load(in_ptr1 + (tl.broadcast_to(tmp9, [XBLOCK])), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp12 = tmp0 >= tmp3
    tmp13 = tl.full([1], 8, tl.int64)
    tmp14 = tmp0 < tmp13
    tmp15 = tmp12 & tmp14
    tmp16 = tl.load(in_ptr0 + (1 + (4*((-4) + x0))), tmp15 & xmask, eviction_policy='evict_last', other=0.0)
    tmp17 = tmp16 + tmp6
    tmp18 = tmp16 < 0
    tmp19 = tl.where(tmp18, tmp17, tmp16)
    tl.device_assert(((0 <= tl.broadcast_to(tmp19, [XBLOCK])) & (tl.broadcast_to(tmp19, [XBLOCK]) < 4)) | ~(tmp15 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp19, [XBLOCK]) < 4")
    tmp21 = tl.load(in_ptr0 + (4*((-4) + x0)), tmp15 & xmask, eviction_policy='evict_last', other=0.0)
    tmp22 = tmp21 + tmp6
    tmp23 = tmp21 < 0
    tmp24 = tl.where(tmp23, tmp22, tmp21)
    tl.device_assert(((0 <= tl.broadcast_to(tmp24, [XBLOCK])) & (tl.broadcast_to(tmp24, [XBLOCK]) < 4)) | ~(tmp15 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp24, [XBLOCK]) < 4")
    tmp26 = tl.load(in_ptr2 + (tl.broadcast_to(tmp24 + (4*tmp19), [XBLOCK])), tmp15 & xmask, eviction_policy='evict_last', other=0.0)
    tmp27 = tmp0 >= tmp13
    tmp28 = tl.full([1], 12, tl.int64)
    tmp29 = tmp0 < tmp28
    tmp30 = tmp27 & tmp29
    tmp31 = tl.load(in_ptr0 + (2 + (4*((-8) + x0))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp32 = tmp31 + tmp6
    tmp33 = tmp31 < 0
    tmp34 = tl.where(tmp33, tmp32, tmp31)
    tl.device_assert(((0 <= tl.broadcast_to(tmp34, [XBLOCK])) & (tl.broadcast_to(tmp34, [XBLOCK]) < 4)) | ~(tmp30 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp34, [XBLOCK]) < 4")
    tmp36 = tl.load(in_ptr0 + (1 + (4*((-8) + x0))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp37 = tmp36 + tmp6
    tmp38 = tmp36 < 0
    tmp39 = tl.where(tmp38, tmp37, tmp36)
    tl.device_assert(((0 <= tl.broadcast_to(tmp39, [XBLOCK])) & (tl.broadcast_to(tmp39, [XBLOCK]) < 4)) | ~(tmp30 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp39, [XBLOCK]) < 4")
    tmp41 = tl.load(in_ptr2 + (tl.broadcast_to(tmp39 + (4*tmp34), [XBLOCK])), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp42 = tmp0 >= tmp28
    tmp43 = tl.full([1], 16, tl.int64)
    tmp44 = tmp0 < tmp43
    tmp45 = tmp42 & tmp44
    tmp46 = tl.load(in_ptr0 + (3 + (4*((-12) + x0))), tmp45 & xmask, eviction_policy='evict_last', other=0.0)
    tmp47 = tmp46 + tmp6
    tmp48 = tmp46 < 0
    tmp49 = tl.where(tmp48, tmp47, tmp46)
    tl.device_assert(((0 <= tl.broadcast_to(tmp49, [XBLOCK])) & (tl.broadcast_to(tmp49, [XBLOCK]) < 4)) | ~(tmp45 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp49, [XBLOCK]) < 4")
    tmp51 = tl.load(in_ptr0 + (2 + (4*((-12) + x0))), tmp45 & xmask, eviction_policy='evict_last', other=0.0)
    tmp52 = tmp51 + tmp6
    tmp53 = tmp51 < 0
    tmp54 = tl.where(tmp53, tmp52, tmp51)
    tl.device_assert(((0 <= tl.broadcast_to(tmp54, [XBLOCK])) & (tl.broadcast_to(tmp54, [XBLOCK]) < 4)) | ~(tmp45 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp54, [XBLOCK]) < 4")
    tmp56 = tl.load(in_ptr2 + (tl.broadcast_to(tmp54 + (4*tmp49), [XBLOCK])), tmp45 & xmask, eviction_policy='evict_last', other=0.0)
    tmp57 = tmp0 >= tmp43
    tmp58 = tl.full([1], 20, tl.int64)
    tmp59 = tmp0 < tmp58
    tmp60 = tl.load(in_ptr0 + (3 + (4*((-16) + x0))), tmp57 & xmask, eviction_policy='evict_last', other=0.0)
    tmp61 = tmp60 + tmp6
    tmp62 = tmp60 < 0
    tmp63 = tl.where(tmp62, tmp61, tmp60)
    tl.device_assert(((0 <= tl.broadcast_to(tmp63, [XBLOCK])) & (tl.broadcast_to(tmp63, [XBLOCK]) < 4)) | ~(tmp57 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp63, [XBLOCK]) < 4")
    tmp65 = tl.load(in_ptr3 + (tl.broadcast_to(tmp63, [XBLOCK])), tmp57 & xmask, eviction_policy='evict_last', other=0.0)
    tmp66 = tl.where(tmp45, tmp56, tmp65)
    tmp67 = tl.where(tmp30, tmp41, tmp66)
    tmp68 = tl.where(tmp15, tmp26, tmp67)
    tmp69 = tl.where(tmp4, tmp11, tmp68)
    tl.store(out_ptr0 + (x0), tmp69, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/jo/cjof6wkwqqyuqnshhtxfbhtrtthq7x2eqwfhv2hmeqmry3wo3epy.py
# Topologically Sorted Source Nodes: [logsumexp, logsumexp_2, prev_4, normalizers, emits, trans, target_scores, sub, loss], Original ATen: [aten.logsumexp, aten.add, aten.sum, aten.sub, aten.mean]
# Source node to ATen node mapping:
#   emits => sum_5
#   logsumexp => full_default
#   logsumexp_2 => add_9, log_2
#   loss => mean
#   normalizers => abs_4, add_11, amax_3, eq_3, exp_3, log_3, sub_3, sum_4, where_3
#   prev_4 => add_10
#   sub => sub_4
#   target_scores => add_12
#   trans => sum_6
# Graph fragment:
#   %full_default : [num_users=4] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %log_2 : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_3,), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%log_2, %squeeze_2), kwargs = {})
#   %add_10 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_9, %primals_4), kwargs = {})
#   %amax_3 : [num_users=2] = call_function[target=torch.ops.aten.amax.default](args = (%add_10, [1], True), kwargs = {})
#   %abs_4 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%amax_3,), kwargs = {})
#   %eq_3 : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%abs_4, inf), kwargs = {})
#   %where_3 : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq_3, %full_default, %amax_3), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_10, %where_3), kwargs = {})
#   %exp_3 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_3,), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_3, [1]), kwargs = {})
#   %log_3 : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_4,), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%log_3, %squeeze_3), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%squeeze_4, [1]), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view, [0]), kwargs = {})
#   %add_12 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_5, %sum_6), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_11, %add_12), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_4,), kwargs = {})
triton_per_fused_add_logsumexp_mean_sub_sum_4 = async_compile.triton('triton_per_fused_add_logsumexp_mean_sub_sum_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.persistent_reduction(
    size_hints=[1, 4],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i64', 2: '*i64', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: 'i32', 8: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {7: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6), equal_to_1=(7,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_logsumexp_mean_sub_sum_4', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 21, 'num_reduction': 1, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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}
)
@triton.jit
def triton_per_fused_add_logsumexp_mean_sub_sum_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (4*r0), None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp21 = tl.load(in_ptr0 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr2 + (r0), None)
    tmp30 = tl.load(in_ptr2 + (4 + r0), None)
    tmp32 = tl.load(in_ptr2 + (8 + r0), None)
    tmp34 = tl.load(in_ptr2 + (12 + r0), None)
    tmp36 = tl.load(in_ptr2 + (16 + r0), None)
    tmp39 = tl.load(in_ptr3 + (4*r0), None, eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr4 + (4*r0), None, eviction_policy='evict_last')
    tmp48 = tl.load(in_ptr5 + (0))
    tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK])
    tmp51 = tl.load(in_ptr3 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp53 = tl.load(in_ptr4 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp58 = tl.load(in_ptr5 + (1))
    tmp59 = tl.broadcast_to(tmp58, [XBLOCK, RBLOCK])
    tmp62 = tl.load(in_ptr3 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp64 = tl.load(in_ptr4 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp69 = tl.load(in_ptr5 + (2))
    tmp70 = tl.broadcast_to(tmp69, [XBLOCK, RBLOCK])
    tmp73 = tl.load(in_ptr3 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp75 = tl.load(in_ptr4 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp80 = tl.load(in_ptr5 + (3))
    tmp81 = tl.broadcast_to(tmp80, [XBLOCK, RBLOCK])
    tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4), "index out of bounds: 0 <= tmp4 < 4")
    tmp6 = tl.load(in_ptr1 + (tmp4 + (16*r0)), None, eviction_policy='evict_last')
    tmp8 = tmp7 + tmp1
    tmp9 = tmp7 < 0
    tmp10 = tl.where(tmp9, tmp8, tmp7)
    tl.device_assert((0 <= tmp10) & (tmp10 < 4), "index out of bounds: 0 <= tmp10 < 4")
    tmp12 = tl.load(in_ptr1 + (4 + tmp10 + (16*r0)), None, eviction_policy='evict_last')
    tmp13 = tmp6 + tmp12
    tmp15 = tmp14 + tmp1
    tmp16 = tmp14 < 0
    tmp17 = tl.where(tmp16, tmp15, tmp14)
    tl.device_assert((0 <= tmp17) & (tmp17 < 4), "index out of bounds: 0 <= tmp17 < 4")
    tmp19 = tl.load(in_ptr1 + (8 + tmp17 + (16*r0)), None, eviction_policy='evict_last')
    tmp20 = tmp13 + tmp19
    tmp22 = tmp21 + tmp1
    tmp23 = tmp21 < 0
    tmp24 = tl.where(tmp23, tmp22, tmp21)
    tl.device_assert((0 <= tmp24) & (tmp24 < 4), "index out of bounds: 0 <= tmp24 < 4")
    tmp26 = tl.load(in_ptr1 + (12 + tmp24 + (16*r0)), None, eviction_policy='evict_last')
    tmp27 = tmp20 + tmp26
    tmp28 = tmp27.to(tl.float32)
    tmp31 = tmp29 + tmp30
    tmp33 = tmp31 + tmp32
    tmp35 = tmp33 + tmp34
    tmp37 = tmp35 + tmp36
    tmp38 = tmp28 + tmp37
    tmp40 = tl_math.log(tmp39)
    tmp42 = tl_math.abs(tmp41)
    tmp43 = float("inf")
    tmp44 = tmp42 == tmp43
    tmp45 = 0.0
    tmp46 = tl.where(tmp44, tmp45, tmp41)
    tmp47 = tmp40 + tmp46
    tmp50 = tmp47 + tmp49
    tmp52 = tl_math.log(tmp51)
    tmp54 = tl_math.abs(tmp53)
    tmp55 = tmp54 == tmp43
    tmp56 = tl.where(tmp55, tmp45, tmp53)
    tmp57 = tmp52 + tmp56
    tmp60 = tmp57 + tmp59
    tmp61 = triton_helpers.maximum(tmp50, tmp60)
    tmp63 = tl_math.log(tmp62)
    tmp65 = tl_math.abs(tmp64)
    tmp66 = tmp65 == tmp43
    tmp67 = tl.where(tmp66, tmp45, tmp64)
    tmp68 = tmp63 + tmp67
    tmp71 = tmp68 + tmp70
    tmp72 = triton_helpers.maximum(tmp61, tmp71)
    tmp74 = tl_math.log(tmp73)
    tmp76 = tl_math.abs(tmp75)
    tmp77 = tmp76 == tmp43
    tmp78 = tl.where(tmp77, tmp45, tmp75)
    tmp79 = tmp74 + tmp78
    tmp82 = tmp79 + tmp81
    tmp83 = triton_helpers.maximum(tmp72, tmp82)
    tmp84 = tl_math.abs(tmp83)
    tmp85 = tmp84 == tmp43
    tmp86 = tl.where(tmp85, tmp45, tmp83)
    tmp87 = tmp50 - tmp86
    tmp88 = tl_math.exp(tmp87)
    tmp89 = tmp60 - tmp86
    tmp90 = tl_math.exp(tmp89)
    tmp91 = tmp88 + tmp90
    tmp92 = tmp71 - tmp86
    tmp93 = tl_math.exp(tmp92)
    tmp94 = tmp91 + tmp93
    tmp95 = tmp82 - tmp86
    tmp96 = tl_math.exp(tmp95)
    tmp97 = tmp94 + tmp96
    tmp98 = tl_math.log(tmp97)
    tmp99 = tmp98 + tmp86
    tmp100 = tmp99 - tmp38
    tmp101 = tl.broadcast_to(tmp100, [XBLOCK, RBLOCK])
    tmp103 = tl.sum(tmp101, 1)[:, None]
    tmp104 = 4.0
    tmp105 = tmp103 / tmp104
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp105, None)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, ), (1, ))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, ), (1, ))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    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, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add_1, cur, logsumexp], Original ATen: [aten.add, aten.logsumexp]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_logsumexp_0.run(primals_2, primals_1, primals_3, buf0, buf1, 16, grid=grid(16), stream=stream0)
        buf2 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [logsumexp, add_3, cur_1, logsumexp_1], Original ATen: [aten.logsumexp, aten.add]
        triton_poi_fused_add_logsumexp_1.run(buf1, buf0, primals_1, primals_3, buf2, buf3, 16, grid=grid(16), stream=stream0)
        buf4 = reinterpret_tensor(buf1, (4, 1, 4), (4, 16, 1), 0); del buf1  # reuse
        buf5 = reinterpret_tensor(buf0, (4, 4), (4, 1), 0); del buf0  # reuse
        # Topologically Sorted Source Nodes: [logsumexp, add_5, cur_2, logsumexp_2], Original ATen: [aten.logsumexp, aten.add]
        triton_poi_fused_add_logsumexp_2.run(buf3, buf2, primals_1, primals_3, buf4, buf5, 16, grid=grid(16), stream=stream0)
        del buf2
        del buf3
        buf8 = empty_strided_cuda((20, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
        triton_poi_fused_stack_3.run(primals_5, primals_2, primals_3, primals_4, buf8, 20, grid=grid(20), stream=stream0)
        buf10 = empty_strided_cuda((), (), torch.float32)
        buf11 = buf10; del buf10  # reuse
        # Topologically Sorted Source Nodes: [logsumexp, logsumexp_2, prev_4, normalizers, emits, trans, target_scores, sub, loss], Original ATen: [aten.logsumexp, aten.add, aten.sum, aten.sub, aten.mean]
        triton_per_fused_add_logsumexp_mean_sub_sum_4.run(buf11, primals_5, primals_1, buf8, buf5, buf4, primals_4, 1, 4, grid=grid(1), stream=stream0)
        del buf4
        del buf5
        del buf8
    return (buf11, primals_1, primals_2, primals_3, primals_4, reinterpret_tensor(primals_5, (4, ), (4, ), 0), reinterpret_tensor(primals_5, (4, ), (4, ), 1), reinterpret_tensor(primals_5, (4, ), (4, ), 2), reinterpret_tensor(primals_5, (4, ), (4, ), 3), reinterpret_tensor(primals_5, (4, ), (4, ), 3), )


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.int64)
    primals_2 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.int64)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5])
    return print_performance(fn, times=times, repeat=repeat)


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

import torch
import torch.nn as nn


class CRFLoss(nn.Module):

    def __init__(self, L, init):
        super(CRFLoss, self).__init__()
        self.start = nn.Parameter(torch.Tensor(L).uniform_(-init, init))
        self.T = nn.Parameter(torch.Tensor(L, L).uniform_(-init, init))
        self.end = nn.Parameter(torch.Tensor(L).uniform_(-init, init))

    def forward(self, scores, targets):
        normalizers = self.compute_normalizers(scores)
        target_scores = self.score_targets(scores, targets)
        loss = (normalizers - target_scores).mean()
        return loss

    def decode(self, scores):
        _B, T, _L = scores.size()
        prev = self.start.unsqueeze(0) + scores[:, 0]
        back = []
        for i in range(1, T):
            cur = prev.unsqueeze(2) + scores.transpose(0, 1)[i].unsqueeze(1
                ) + self.T.transpose(0, 1)
            prev, indices = cur.max(dim=1)
            back.append(indices)
        prev += self.end
        max_scores, indices = prev.max(dim=1)
        tape = [indices]
        back = list(reversed(back))
        for i in range(T - 1):
            indices = torch.gather(back[i], 1, indices.unsqueeze(1)).squeeze(1)
            tape.append(indices)
        return max_scores, torch.stack(tape[::-1], dim=1)

    def compute_normalizers(self, scores):
        _B, T, _L = scores.size()
        prev = self.start + scores.transpose(0, 1)[0]
        for i in range(1, T):
            cur = prev.unsqueeze(2) + scores.transpose(0, 1)[i].unsqueeze(1
                ) + self.T.transpose(0, 1)
            prev = torch.logsumexp(cur, dim=1).clone()
        prev += self.end
        normalizers = torch.logsumexp(prev, 1)
        return normalizers

    def score_targets(self, scores, targets):
        _B, T, _L = scores.size()
        emits = scores.gather(2, targets.unsqueeze(2)).squeeze(2).sum(1)
        trans = torch.stack([self.start.gather(0, targets[:, 0])] + [self.T
            [targets[:, i], targets[:, i - 1]] for i in range(1, T)] + [
            self.end.gather(0, targets[:, -1])]).sum(0)
        return emits + trans


def get_inputs():
    return [torch.ones([4, 4, 4], dtype=torch.int64), torch.ones([4, 4],
        dtype=torch.int64)]


def get_init_inputs():
    return [[], {'L': 4, 'init': 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
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_add_logsumexp_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + 16 * x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (4 + x0 + 16 * x1), xmask)
    tmp8 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + 1)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp12 = tl.load(in_ptr1 + (1 + 16 * x1), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr0 + 2)
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK])
    tmp21 = tl.load(in_ptr1 + (2 + 16 * x1), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp28 = tl.load(in_ptr0 + 3)
    tmp29 = tl.broadcast_to(tmp28, [XBLOCK])
    tmp30 = tl.load(in_ptr1 + (3 + 16 * x1), xmask, eviction_policy=
        'evict_last')
    tmp34 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp3 = tmp2.to(tl.float32)
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5.to(tl.float32)
    tmp7 = tmp4 + tmp6
    tmp9 = tmp7 + tmp8
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 + tmp13
    tmp15 = tmp14 + tmp6
    tmp17 = tmp15 + tmp16
    tmp18 = triton_helpers.maximum(tmp9, tmp17)
    tmp22 = tmp21.to(tl.float32)
    tmp23 = tmp20 + tmp22
    tmp24 = tmp23 + tmp6
    tmp26 = tmp24 + tmp25
    tmp27 = triton_helpers.maximum(tmp18, tmp26)
    tmp31 = tmp30.to(tl.float32)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp32 + tmp6
    tmp35 = tmp33 + tmp34
    tmp36 = triton_helpers.maximum(tmp27, tmp35)
    tmp37 = tl_math.abs(tmp36)
    tmp38 = float('inf')
    tmp39 = tmp37 == tmp38
    tmp40 = 0.0
    tmp41 = tl.where(tmp39, tmp40, tmp36)
    tmp42 = tmp9 - tmp41
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp17 - tmp41
    tmp45 = tl_math.exp(tmp44)
    tmp46 = tmp43 + tmp45
    tmp47 = tmp26 - tmp41
    tmp48 = tl_math.exp(tmp47)
    tmp49 = tmp46 + tmp48
    tmp50 = tmp35 - tmp41
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp49 + tmp51
    tl.store(out_ptr0 + x2, tmp36, xmask)
    tl.store(out_ptr1 + x2, tmp52, xmask)


@triton.jit
def triton_poi_fused_add_logsumexp_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    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')
    tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask)
    tmp12 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp16 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp33 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp36 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp38 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp44 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = tl_math.log(tmp0)
    tmp3 = tl_math.abs(tmp2)
    tmp4 = float('inf')
    tmp5 = tmp3 == tmp4
    tmp6 = 0.0
    tmp7 = tl.where(tmp5, tmp6, tmp2)
    tmp8 = tmp1 + tmp7
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tl_math.log(tmp14)
    tmp17 = tl_math.abs(tmp16)
    tmp18 = tmp17 == tmp4
    tmp19 = tl.where(tmp18, tmp6, tmp16)
    tmp20 = tmp15 + tmp19
    tmp21 = tmp20 + tmp10
    tmp23 = tmp21 + tmp22
    tmp24 = triton_helpers.maximum(tmp13, tmp23)
    tmp26 = tl_math.log(tmp25)
    tmp28 = tl_math.abs(tmp27)
    tmp29 = tmp28 == tmp4
    tmp30 = tl.where(tmp29, tmp6, tmp27)
    tmp31 = tmp26 + tmp30
    tmp32 = tmp31 + tmp10
    tmp34 = tmp32 + tmp33
    tmp35 = triton_helpers.maximum(tmp24, tmp34)
    tmp37 = tl_math.log(tmp36)
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp39 == tmp4
    tmp41 = tl.where(tmp40, tmp6, tmp38)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp42 + tmp10
    tmp45 = tmp43 + tmp44
    tmp46 = triton_helpers.maximum(tmp35, tmp45)
    tmp47 = tl_math.abs(tmp46)
    tmp48 = tmp47 == tmp4
    tmp49 = tl.where(tmp48, tmp6, tmp46)
    tmp50 = tmp13 - tmp49
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp23 - tmp49
    tmp53 = tl_math.exp(tmp52)
    tmp54 = tmp51 + tmp53
    tmp55 = tmp34 - tmp49
    tmp56 = tl_math.exp(tmp55)
    tmp57 = tmp54 + tmp56
    tmp58 = tmp45 - tmp49
    tmp59 = tl_math.exp(tmp58)
    tmp60 = tmp57 + tmp59
    tl.store(out_ptr0 + x2, tmp46, xmask)
    tl.store(out_ptr1 + x2, tmp60, xmask)


@triton.jit
def triton_poi_fused_add_logsumexp_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    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')
    tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask)
    tmp12 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp16 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp33 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp36 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp38 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp44 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = tl_math.log(tmp0)
    tmp3 = tl_math.abs(tmp2)
    tmp4 = float('inf')
    tmp5 = tmp3 == tmp4
    tmp6 = 0.0
    tmp7 = tl.where(tmp5, tmp6, tmp2)
    tmp8 = tmp1 + tmp7
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tl_math.log(tmp14)
    tmp17 = tl_math.abs(tmp16)
    tmp18 = tmp17 == tmp4
    tmp19 = tl.where(tmp18, tmp6, tmp16)
    tmp20 = tmp15 + tmp19
    tmp21 = tmp20 + tmp10
    tmp23 = tmp21 + tmp22
    tmp24 = triton_helpers.maximum(tmp13, tmp23)
    tmp26 = tl_math.log(tmp25)
    tmp28 = tl_math.abs(tmp27)
    tmp29 = tmp28 == tmp4
    tmp30 = tl.where(tmp29, tmp6, tmp27)
    tmp31 = tmp26 + tmp30
    tmp32 = tmp31 + tmp10
    tmp34 = tmp32 + tmp33
    tmp35 = triton_helpers.maximum(tmp24, tmp34)
    tmp37 = tl_math.log(tmp36)
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp39 == tmp4
    tmp41 = tl.where(tmp40, tmp6, tmp38)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp42 + tmp10
    tmp45 = tmp43 + tmp44
    tmp46 = triton_helpers.maximum(tmp35, tmp45)
    tmp47 = tl_math.abs(tmp46)
    tmp48 = tmp47 == tmp4
    tmp49 = tl.where(tmp48, tmp6, tmp46)
    tmp50 = tmp13 - tmp49
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp23 - tmp49
    tmp53 = tl_math.exp(tmp52)
    tmp54 = tmp51 + tmp53
    tmp55 = tmp34 - tmp49
    tmp56 = tl_math.exp(tmp55)
    tmp57 = tmp54 + tmp56
    tmp58 = tmp45 - tmp49
    tmp59 = tl_math.exp(tmp58)
    tmp60 = tmp57 + tmp59
    tl.store(out_ptr0 + x2, tmp46, xmask)
    tl.store(out_ptr1 + x2, tmp60, xmask)


@triton.jit
def triton_poi_fused_stack_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 20
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + 4 * x0, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.full([XBLOCK], 4, tl.int32)
    tmp7 = tmp5 + tmp6
    tmp8 = tmp5 < 0
    tmp9 = tl.where(tmp8, tmp7, tmp5)
    tl.device_assert((0 <= tl.broadcast_to(tmp9, [XBLOCK])) & (tl.
        broadcast_to(tmp9, [XBLOCK]) < 4) | ~(tmp4 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp9, [XBLOCK]) < 4')
    tmp11 = tl.load(in_ptr1 + tl.broadcast_to(tmp9, [XBLOCK]), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp12 = tmp0 >= tmp3
    tmp13 = tl.full([1], 8, tl.int64)
    tmp14 = tmp0 < tmp13
    tmp15 = tmp12 & tmp14
    tmp16 = tl.load(in_ptr0 + (1 + 4 * (-4 + x0)), tmp15 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp17 = tmp16 + tmp6
    tmp18 = tmp16 < 0
    tmp19 = tl.where(tmp18, tmp17, tmp16)
    tl.device_assert((0 <= tl.broadcast_to(tmp19, [XBLOCK])) & (tl.
        broadcast_to(tmp19, [XBLOCK]) < 4) | ~(tmp15 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp19, [XBLOCK]) < 4')
    tmp21 = tl.load(in_ptr0 + 4 * (-4 + x0), tmp15 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp22 = tmp21 + tmp6
    tmp23 = tmp21 < 0
    tmp24 = tl.where(tmp23, tmp22, tmp21)
    tl.device_assert((0 <= tl.broadcast_to(tmp24, [XBLOCK])) & (tl.
        broadcast_to(tmp24, [XBLOCK]) < 4) | ~(tmp15 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp24, [XBLOCK]) < 4')
    tmp26 = tl.load(in_ptr2 + tl.broadcast_to(tmp24 + 4 * tmp19, [XBLOCK]),
        tmp15 & xmask, eviction_policy='evict_last', other=0.0)
    tmp27 = tmp0 >= tmp13
    tmp28 = tl.full([1], 12, tl.int64)
    tmp29 = tmp0 < tmp28
    tmp30 = tmp27 & tmp29
    tmp31 = tl.load(in_ptr0 + (2 + 4 * (-8 + x0)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp32 = tmp31 + tmp6
    tmp33 = tmp31 < 0
    tmp34 = tl.where(tmp33, tmp32, tmp31)
    tl.device_assert((0 <= tl.broadcast_to(tmp34, [XBLOCK])) & (tl.
        broadcast_to(tmp34, [XBLOCK]) < 4) | ~(tmp30 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp34, [XBLOCK]) < 4')
    tmp36 = tl.load(in_ptr0 + (1 + 4 * (-8 + x0)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp37 = tmp36 + tmp6
    tmp38 = tmp36 < 0
    tmp39 = tl.where(tmp38, tmp37, tmp36)
    tl.device_assert((0 <= tl.broadcast_to(tmp39, [XBLOCK])) & (tl.
        broadcast_to(tmp39, [XBLOCK]) < 4) | ~(tmp30 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp39, [XBLOCK]) < 4')
    tmp41 = tl.load(in_ptr2 + tl.broadcast_to(tmp39 + 4 * tmp34, [XBLOCK]),
        tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp42 = tmp0 >= tmp28
    tmp43 = tl.full([1], 16, tl.int64)
    tmp44 = tmp0 < tmp43
    tmp45 = tmp42 & tmp44
    tmp46 = tl.load(in_ptr0 + (3 + 4 * (-12 + x0)), tmp45 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp47 = tmp46 + tmp6
    tmp48 = tmp46 < 0
    tmp49 = tl.where(tmp48, tmp47, tmp46)
    tl.device_assert((0 <= tl.broadcast_to(tmp49, [XBLOCK])) & (tl.
        broadcast_to(tmp49, [XBLOCK]) < 4) | ~(tmp45 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp49, [XBLOCK]) < 4')
    tmp51 = tl.load(in_ptr0 + (2 + 4 * (-12 + x0)), tmp45 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp52 = tmp51 + tmp6
    tmp53 = tmp51 < 0
    tmp54 = tl.where(tmp53, tmp52, tmp51)
    tl.device_assert((0 <= tl.broadcast_to(tmp54, [XBLOCK])) & (tl.
        broadcast_to(tmp54, [XBLOCK]) < 4) | ~(tmp45 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp54, [XBLOCK]) < 4')
    tmp56 = tl.load(in_ptr2 + tl.broadcast_to(tmp54 + 4 * tmp49, [XBLOCK]),
        tmp45 & xmask, eviction_policy='evict_last', other=0.0)
    tmp57 = tmp0 >= tmp43
    tl.full([1], 20, tl.int64)
    tmp60 = tl.load(in_ptr0 + (3 + 4 * (-16 + x0)), tmp57 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp61 = tmp60 + tmp6
    tmp62 = tmp60 < 0
    tmp63 = tl.where(tmp62, tmp61, tmp60)
    tl.device_assert((0 <= tl.broadcast_to(tmp63, [XBLOCK])) & (tl.
        broadcast_to(tmp63, [XBLOCK]) < 4) | ~(tmp57 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp63, [XBLOCK]) < 4')
    tmp65 = tl.load(in_ptr3 + tl.broadcast_to(tmp63, [XBLOCK]), tmp57 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp66 = tl.where(tmp45, tmp56, tmp65)
    tmp67 = tl.where(tmp30, tmp41, tmp66)
    tmp68 = tl.where(tmp15, tmp26, tmp67)
    tmp69 = tl.where(tmp4, tmp11, tmp68)
    tl.store(out_ptr0 + x0, tmp69, xmask)


@triton.jit
def triton_per_fused_add_logsumexp_mean_sub_sum_4(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, rnumel, XBLOCK: tl
    .constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp21 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr2 + r0, None)
    tmp30 = tl.load(in_ptr2 + (4 + r0), None)
    tmp32 = tl.load(in_ptr2 + (8 + r0), None)
    tmp34 = tl.load(in_ptr2 + (12 + r0), None)
    tmp36 = tl.load(in_ptr2 + (16 + r0), None)
    tmp39 = tl.load(in_ptr3 + 4 * r0, None, eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr4 + 4 * r0, None, eviction_policy='evict_last')
    tmp48 = tl.load(in_ptr5 + 0)
    tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK])
    tmp51 = tl.load(in_ptr3 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp53 = tl.load(in_ptr4 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp58 = tl.load(in_ptr5 + 1)
    tmp59 = tl.broadcast_to(tmp58, [XBLOCK, RBLOCK])
    tmp62 = tl.load(in_ptr3 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp64 = tl.load(in_ptr4 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp69 = tl.load(in_ptr5 + 2)
    tmp70 = tl.broadcast_to(tmp69, [XBLOCK, RBLOCK])
    tmp73 = tl.load(in_ptr3 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp75 = tl.load(in_ptr4 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp80 = tl.load(in_ptr5 + 3)
    tmp81 = tl.broadcast_to(tmp80, [XBLOCK, RBLOCK])
    tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4),
        'index out of bounds: 0 <= tmp4 < 4')
    tmp6 = tl.load(in_ptr1 + (tmp4 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp8 = tmp7 + tmp1
    tmp9 = tmp7 < 0
    tmp10 = tl.where(tmp9, tmp8, tmp7)
    tl.device_assert((0 <= tmp10) & (tmp10 < 4),
        'index out of bounds: 0 <= tmp10 < 4')
    tmp12 = tl.load(in_ptr1 + (4 + tmp10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp13 = tmp6 + tmp12
    tmp15 = tmp14 + tmp1
    tmp16 = tmp14 < 0
    tmp17 = tl.where(tmp16, tmp15, tmp14)
    tl.device_assert((0 <= tmp17) & (tmp17 < 4),
        'index out of bounds: 0 <= tmp17 < 4')
    tmp19 = tl.load(in_ptr1 + (8 + tmp17 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp20 = tmp13 + tmp19
    tmp22 = tmp21 + tmp1
    tmp23 = tmp21 < 0
    tmp24 = tl.where(tmp23, tmp22, tmp21)
    tl.device_assert((0 <= tmp24) & (tmp24 < 4),
        'index out of bounds: 0 <= tmp24 < 4')
    tmp26 = tl.load(in_ptr1 + (12 + tmp24 + 16 * r0), None, eviction_policy
        ='evict_last')
    tmp27 = tmp20 + tmp26
    tmp28 = tmp27.to(tl.float32)
    tmp31 = tmp29 + tmp30
    tmp33 = tmp31 + tmp32
    tmp35 = tmp33 + tmp34
    tmp37 = tmp35 + tmp36
    tmp38 = tmp28 + tmp37
    tmp40 = tl_math.log(tmp39)
    tmp42 = tl_math.abs(tmp41)
    tmp43 = float('inf')
    tmp44 = tmp42 == tmp43
    tmp45 = 0.0
    tmp46 = tl.where(tmp44, tmp45, tmp41)
    tmp47 = tmp40 + tmp46
    tmp50 = tmp47 + tmp49
    tmp52 = tl_math.log(tmp51)
    tmp54 = tl_math.abs(tmp53)
    tmp55 = tmp54 == tmp43
    tmp56 = tl.where(tmp55, tmp45, tmp53)
    tmp57 = tmp52 + tmp56
    tmp60 = tmp57 + tmp59
    tmp61 = triton_helpers.maximum(tmp50, tmp60)
    tmp63 = tl_math.log(tmp62)
    tmp65 = tl_math.abs(tmp64)
    tmp66 = tmp65 == tmp43
    tmp67 = tl.where(tmp66, tmp45, tmp64)
    tmp68 = tmp63 + tmp67
    tmp71 = tmp68 + tmp70
    tmp72 = triton_helpers.maximum(tmp61, tmp71)
    tmp74 = tl_math.log(tmp73)
    tmp76 = tl_math.abs(tmp75)
    tmp77 = tmp76 == tmp43
    tmp78 = tl.where(tmp77, tmp45, tmp75)
    tmp79 = tmp74 + tmp78
    tmp82 = tmp79 + tmp81
    tmp83 = triton_helpers.maximum(tmp72, tmp82)
    tmp84 = tl_math.abs(tmp83)
    tmp85 = tmp84 == tmp43
    tmp86 = tl.where(tmp85, tmp45, tmp83)
    tmp87 = tmp50 - tmp86
    tmp88 = tl_math.exp(tmp87)
    tmp89 = tmp60 - tmp86
    tmp90 = tl_math.exp(tmp89)
    tmp91 = tmp88 + tmp90
    tmp92 = tmp71 - tmp86
    tmp93 = tl_math.exp(tmp92)
    tmp94 = tmp91 + tmp93
    tmp95 = tmp82 - tmp86
    tmp96 = tl_math.exp(tmp95)
    tmp97 = tmp94 + tmp96
    tmp98 = tl_math.log(tmp97)
    tmp99 = tmp98 + tmp86
    tmp100 = tmp99 - tmp38
    tmp101 = tl.broadcast_to(tmp100, [XBLOCK, RBLOCK])
    tmp103 = tl.sum(tmp101, 1)[:, None]
    tmp104 = 4.0
    tmp105 = tmp103 / tmp104
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp105, None)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    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, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_logsumexp_0[grid(16)](primals_2, primals_1,
            primals_3, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_logsumexp_1[grid(16)](buf1, buf0, primals_1,
            primals_3, buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf4 = reinterpret_tensor(buf1, (4, 1, 4), (4, 16, 1), 0)
        del buf1
        buf5 = reinterpret_tensor(buf0, (4, 4), (4, 1), 0)
        del buf0
        triton_poi_fused_add_logsumexp_2[grid(16)](buf3, buf2, primals_1,
            primals_3, buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf2
        del buf3
        buf8 = empty_strided_cuda((20,), (1,), torch.float32)
        triton_poi_fused_stack_3[grid(20)](primals_5, primals_2, primals_3,
            primals_4, buf8, 20, XBLOCK=32, num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((), (), torch.float32)
        buf11 = buf10
        del buf10
        triton_per_fused_add_logsumexp_mean_sub_sum_4[grid(1)](buf11,
            primals_5, primals_1, buf8, buf5, buf4, primals_4, 1, 4, XBLOCK
            =1, num_warps=2, num_stages=1)
        del buf4
        del buf5
        del buf8
    return (buf11, primals_1, primals_2, primals_3, primals_4,
        reinterpret_tensor(primals_5, (4,), (4,), 0), reinterpret_tensor(
        primals_5, (4,), (4,), 1), reinterpret_tensor(primals_5, (4,), (4,),
        2), reinterpret_tensor(primals_5, (4,), (4,), 3),
        reinterpret_tensor(primals_5, (4,), (4,), 3))


class CRFLossNew(nn.Module):

    def __init__(self, L, init):
        super(CRFLossNew, self).__init__()
        self.start = nn.Parameter(torch.Tensor(L).uniform_(-init, init))
        self.T = nn.Parameter(torch.Tensor(L, L).uniform_(-init, init))
        self.end = nn.Parameter(torch.Tensor(L).uniform_(-init, init))

    def decode(self, scores):
        _B, T, _L = scores.size()
        prev = self.start.unsqueeze(0) + scores[:, 0]
        back = []
        for i in range(1, T):
            cur = prev.unsqueeze(2) + scores.transpose(0, 1)[i].unsqueeze(1
                ) + self.T.transpose(0, 1)
            prev, indices = cur.max(dim=1)
            back.append(indices)
        prev += self.end
        max_scores, indices = prev.max(dim=1)
        tape = [indices]
        back = list(reversed(back))
        for i in range(T - 1):
            indices = torch.gather(back[i], 1, indices.unsqueeze(1)).squeeze(1)
            tape.append(indices)
        return max_scores, torch.stack(tape[::-1], dim=1)

    def compute_normalizers(self, scores):
        _B, T, _L = scores.size()
        prev = self.start + scores.transpose(0, 1)[0]
        for i in range(1, T):
            cur = prev.unsqueeze(2) + scores.transpose(0, 1)[i].unsqueeze(1
                ) + self.T.transpose(0, 1)
            prev = torch.logsumexp(cur, dim=1).clone()
        prev += self.end
        normalizers = torch.logsumexp(prev, 1)
        return normalizers

    def score_targets(self, scores, targets):
        _B, T, _L = scores.size()
        emits = scores.gather(2, targets.unsqueeze(2)).squeeze(2).sum(1)
        trans = torch.stack([self.start.gather(0, targets[:, 0])] + [self.T
            [targets[:, i], targets[:, i - 1]] for i in range(1, T)] + [
            self.end.gather(0, targets[:, -1])]).sum(0)
        return emits + trans

    def forward(self, input_0, input_1):
        primals_2 = self.start
        primals_3 = self.T
        primals_4 = self.end
        primals_1 = input_0
        primals_5 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]
