# AOT ID: ['0_inference']
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_9/inductor_cache/um/cum65j23qchrjf5dndblqgbw6zomhgwfj2obfidtgy7b5j3zwklm.py
# Topologically Sorted Source Nodes: [pred], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   pred => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_0 = async_compile.triton('triton_poi_fused__softmax_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 4)
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_9/inductor_cache/wk/cwk2wao7opapqbjj7klnqrd6tgist3ts3nc5veryzhzstwpx7d4l.py
# Topologically Sorted Source Nodes: [pred], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   pred => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %div : [num_users=4] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_1 = async_compile.triton('triton_poi_fused__softmax_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: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 4)
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x2), tmp8, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_9/inductor_cache/mb/cmbyjklxdj62rhtaf6uasmez273r2bgqaeedzwxsddkjznudmv6z.py
# Topologically Sorted Source Nodes: [ne, valid_mask, valid_mask_1, valid_pred, valid_target, mul_2, intersection, sub, mul_3, fps, mul_5, add, sub_1, mul_4, fns, mul_6, denominator, add_2, truediv, tversky_loss_value, add_12, valid_mask_2, valid_pred_1, valid_target_1, mul_9, intersection_1, sub_3, mul_10, fps_1, mul_12, add_3, sub_4, mul_11, fns_1, mul_13, denominator_1, add_5, truediv_1, tversky_loss_value_1, add_13, valid_mask_3, valid_pred_2, valid_target_2, mul_16, intersection_2, sub_6, mul_17, fps_2, mul_19, add_6, sub_7, mul_18, fns_2, mul_20, denominator_2, add_8, truediv_2, tversky_loss_value_2, add_14, valid_mask_4, valid_pred_3, valid_target_3, mul_23, intersection_3, sub_9, mul_24, fps_3, mul_26, add_9, sub_10, mul_25, fns_3, mul_27, denominator_3, add_11, truediv_3, tversky_loss_value_3, add_15, loss, loss_1], Original ATen: [aten.ne, aten._to_copy, aten.view, aten.mul, aten.sum, aten.rsub, aten.add, aten.div]
# Source node to ATen node mapping:
#   add => add
#   add_11 => add_11
#   add_12 => add_12
#   add_13 => add_13
#   add_14 => add_14
#   add_15 => add_15
#   add_2 => add_2
#   add_3 => add_3
#   add_5 => add_5
#   add_6 => add_6
#   add_8 => add_8
#   add_9 => add_9
#   denominator => add_1
#   denominator_1 => add_4
#   denominator_2 => add_7
#   denominator_3 => add_10
#   fns => sum_4
#   fns_1 => sum_7
#   fns_2 => sum_10
#   fns_3 => sum_13
#   fps => sum_3
#   fps_1 => sum_6
#   fps_2 => sum_9
#   fps_3 => sum_12
#   intersection => sum_2
#   intersection_1 => sum_5
#   intersection_2 => sum_8
#   intersection_3 => sum_11
#   loss => div_5
#   loss_1 => mul_28
#   mul_10 => mul_10
#   mul_11 => mul_11
#   mul_12 => mul_12
#   mul_13 => mul_13
#   mul_16 => mul_16
#   mul_17 => mul_17
#   mul_18 => mul_18
#   mul_19 => mul_19
#   mul_2 => mul_2
#   mul_20 => mul_20
#   mul_23 => mul_23
#   mul_24 => mul_24
#   mul_25 => mul_25
#   mul_26 => mul_26
#   mul_27 => mul_27
#   mul_3 => mul_3
#   mul_4 => mul_4
#   mul_5 => mul_5
#   mul_6 => mul_6
#   mul_9 => mul_9
#   ne => ne
#   sub => sub_1
#   sub_1 => sub_2
#   sub_10 => sub_11
#   sub_3 => sub_4
#   sub_4 => sub_5
#   sub_6 => sub_7
#   sub_7 => sub_8
#   sub_9 => sub_10
#   truediv => div_1
#   truediv_1 => div_2
#   truediv_2 => div_3
#   truediv_3 => div_4
#   tversky_loss_value => sub_3
#   tversky_loss_value_1 => sub_6
#   tversky_loss_value_2 => sub_9
#   tversky_loss_value_3 => sub_12
#   valid_mask => convert_element_type_2
#   valid_mask_1 => view_2
#   valid_mask_2 => view_5
#   valid_mask_3 => view_8
#   valid_mask_4 => view_11
#   valid_pred => mul
#   valid_pred_1 => mul_7
#   valid_pred_2 => mul_14
#   valid_pred_3 => mul_21
#   valid_target => mul_1
#   valid_target_1 => mul_8
#   valid_target_2 => mul_15
#   valid_target_3 => mul_22
# Graph fragment:
#   %ne : [num_users=1] = call_function[target=torch.ops.aten.ne.Scalar](args = (%arg1_1, 255), kwargs = {})
#   %convert_element_type_2 : [num_users=4] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%ne, torch.int64), kwargs = {})
#   %view_2 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%convert_element_type_2, [4, -1]), kwargs = {})
#   %mul : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view, %view_2), kwargs = {})
#   %mul_1 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_1, %view_2), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %mul_1), kwargs = {})
#   %sum_2 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [1]), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_1), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %sub_1), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_3, [1]), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_3, 0.3), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_2, %mul_5), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_2, %mul_1), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_4, [1]), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_4, 0.7), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, %mul_6), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_1, 1e-06), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_2, %add_2), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_1), kwargs = {})
#   %add_12 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_3, 0), kwargs = {})
#   %view_5 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%convert_element_type_2, [4, -1]), kwargs = {})
#   %mul_7 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_3, %view_5), kwargs = {})
#   %mul_8 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_3, %view_5), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_7, %mul_8), kwargs = {})
#   %sum_5 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_9, [1]), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_8), kwargs = {})
#   %mul_10 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_7, %sub_4), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_10, [1]), kwargs = {})
#   %mul_12 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, 0.3), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_5, %mul_12), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_7), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, %mul_8), kwargs = {})
#   %sum_7 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_11, [1]), kwargs = {})
#   %mul_13 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_7, 0.7), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_3, %mul_13), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_4, 1e-06), kwargs = {})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_5, %add_5), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_2), kwargs = {})
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_12, %sub_6), kwargs = {})
#   %view_8 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%convert_element_type_2, [4, -1]), kwargs = {})
#   %mul_14 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_6, %view_8), kwargs = {})
#   %mul_15 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_5, %view_8), kwargs = {})
#   %mul_16 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_14, %mul_15), kwargs = {})
#   %sum_8 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_16, [1]), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_15), kwargs = {})
#   %mul_17 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_14, %sub_7), kwargs = {})
#   %sum_9 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_17, [1]), kwargs = {})
#   %mul_19 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_9, 0.3), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_8, %mul_19), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_14), kwargs = {})
#   %mul_18 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_8, %mul_15), kwargs = {})
#   %sum_10 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_18, [1]), kwargs = {})
#   %mul_20 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_10, 0.7), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, %mul_20), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_7, 1e-06), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_8, %add_8), kwargs = {})
#   %sub_9 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_3), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_13, %sub_9), kwargs = {})
#   %view_11 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%convert_element_type_2, [4, -1]), kwargs = {})
#   %mul_21 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_9, %view_11), kwargs = {})
#   %mul_22 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_7, %view_11), kwargs = {})
#   %mul_23 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_21, %mul_22), kwargs = {})
#   %sum_11 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_23, [1]), kwargs = {})
#   %sub_10 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_22), kwargs = {})
#   %mul_24 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_21, %sub_10), kwargs = {})
#   %sum_12 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_24, [1]), kwargs = {})
#   %mul_26 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_12, 0.3), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_11, %mul_26), kwargs = {})
#   %sub_11 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_21), kwargs = {})
#   %mul_25 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_11, %mul_22), kwargs = {})
#   %sum_13 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_25, [1]), kwargs = {})
#   %mul_27 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_13, 0.7), kwargs = {})
#   %add_10 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_9, %mul_27), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_10, 1e-06), kwargs = {})
#   %div_4 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_11, %add_11), kwargs = {})
#   %sub_12 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_4), kwargs = {})
#   %add_15 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_14, %sub_12), kwargs = {})
#   %div_5 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_15, 4.0), kwargs = {})
#   %mul_28 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div_5, 1.0), kwargs = {})
triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_2 = async_compile.triton('triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_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=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 8, '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_add_div_mul_ne_rsub_sum_view_2(in_out_ptr0, in_ptr0, in_ptr1, 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 + (4*x0), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (4*x0), xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp31 = tl.load(in_ptr1 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp45 = tl.load(in_ptr1 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp82 = tl.load(in_ptr0 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp133 = tl.load(in_ptr0 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp184 = tl.load(in_ptr0 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp2 = 255.0
    tmp3 = tmp1 != tmp2
    tmp4 = tmp3.to(tl.int64)
    tmp5 = tmp4.to(tl.float32)
    tmp6 = tmp0 * tmp5
    tmp7 = tmp1.to(tl.int64)
    tmp8 = tl.full([1], 0, tl.int64)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp10 = tl.full([1], 3, tl.int64)
    tmp11 = triton_helpers.minimum(tmp9, tmp10)
    tmp12 = tmp11 == tmp8
    tmp13 = tmp12.to(tl.int64)
    tmp14 = tmp13 * tmp4
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp6 * tmp15
    tmp18 = tmp17 != tmp2
    tmp19 = tmp18.to(tl.int64)
    tmp20 = tmp19.to(tl.float32)
    tmp21 = tmp0 * tmp20
    tmp22 = tmp17.to(tl.int64)
    tmp23 = triton_helpers.maximum(tmp22, tmp8)
    tmp24 = triton_helpers.minimum(tmp23, tmp10)
    tmp25 = tmp24 == tmp8
    tmp26 = tmp25.to(tl.int64)
    tmp27 = tmp26 * tmp19
    tmp28 = tmp27.to(tl.float32)
    tmp29 = tmp21 * tmp28
    tmp30 = tmp16 + tmp29
    tmp32 = tmp31 != tmp2
    tmp33 = tmp32.to(tl.int64)
    tmp34 = tmp33.to(tl.float32)
    tmp35 = tmp0 * tmp34
    tmp36 = tmp31.to(tl.int64)
    tmp37 = triton_helpers.maximum(tmp36, tmp8)
    tmp38 = triton_helpers.minimum(tmp37, tmp10)
    tmp39 = tmp38 == tmp8
    tmp40 = tmp39.to(tl.int64)
    tmp41 = tmp40 * tmp33
    tmp42 = tmp41.to(tl.float32)
    tmp43 = tmp35 * tmp42
    tmp44 = tmp30 + tmp43
    tmp46 = tmp45 != tmp2
    tmp47 = tmp46.to(tl.int64)
    tmp48 = tmp47.to(tl.float32)
    tmp49 = tmp0 * tmp48
    tmp50 = tmp45.to(tl.int64)
    tmp51 = triton_helpers.maximum(tmp50, tmp8)
    tmp52 = triton_helpers.minimum(tmp51, tmp10)
    tmp53 = tmp52 == tmp8
    tmp54 = tmp53.to(tl.int64)
    tmp55 = tmp54 * tmp47
    tmp56 = tmp55.to(tl.float32)
    tmp57 = tmp49 * tmp56
    tmp58 = tmp44 + tmp57
    tmp59 = 1.0
    tmp60 = tmp59 - tmp15
    tmp61 = tmp6 * tmp60
    tmp62 = tmp59 - tmp28
    tmp63 = tmp21 * tmp62
    tmp64 = tmp61 + tmp63
    tmp65 = tmp59 - tmp42
    tmp66 = tmp35 * tmp65
    tmp67 = tmp64 + tmp66
    tmp68 = tmp59 - tmp56
    tmp69 = tmp49 * tmp68
    tmp70 = tmp67 + tmp69
    tmp71 = tmp59 - tmp6
    tmp72 = tmp71 * tmp15
    tmp73 = tmp59 - tmp21
    tmp74 = tmp73 * tmp28
    tmp75 = tmp72 + tmp74
    tmp76 = tmp59 - tmp35
    tmp77 = tmp76 * tmp42
    tmp78 = tmp75 + tmp77
    tmp79 = tmp59 - tmp49
    tmp80 = tmp79 * tmp56
    tmp81 = tmp78 + tmp80
    tmp83 = tmp82 * tmp5
    tmp84 = tl.full([1], 1, tl.int64)
    tmp85 = tmp11 == tmp84
    tmp86 = tmp85.to(tl.int64)
    tmp87 = tmp86 * tmp4
    tmp88 = tmp87.to(tl.float32)
    tmp89 = tmp83 * tmp88
    tmp90 = tmp82 * tmp20
    tmp91 = tmp24 == tmp84
    tmp92 = tmp91.to(tl.int64)
    tmp93 = tmp92 * tmp19
    tmp94 = tmp93.to(tl.float32)
    tmp95 = tmp90 * tmp94
    tmp96 = tmp89 + tmp95
    tmp97 = tmp82 * tmp34
    tmp98 = tmp38 == tmp84
    tmp99 = tmp98.to(tl.int64)
    tmp100 = tmp99 * tmp33
    tmp101 = tmp100.to(tl.float32)
    tmp102 = tmp97 * tmp101
    tmp103 = tmp96 + tmp102
    tmp104 = tmp82 * tmp48
    tmp105 = tmp52 == tmp84
    tmp106 = tmp105.to(tl.int64)
    tmp107 = tmp106 * tmp47
    tmp108 = tmp107.to(tl.float32)
    tmp109 = tmp104 * tmp108
    tmp110 = tmp103 + tmp109
    tmp111 = tmp59 - tmp88
    tmp112 = tmp83 * tmp111
    tmp113 = tmp59 - tmp94
    tmp114 = tmp90 * tmp113
    tmp115 = tmp112 + tmp114
    tmp116 = tmp59 - tmp101
    tmp117 = tmp97 * tmp116
    tmp118 = tmp115 + tmp117
    tmp119 = tmp59 - tmp108
    tmp120 = tmp104 * tmp119
    tmp121 = tmp118 + tmp120
    tmp122 = tmp59 - tmp83
    tmp123 = tmp122 * tmp88
    tmp124 = tmp59 - tmp90
    tmp125 = tmp124 * tmp94
    tmp126 = tmp123 + tmp125
    tmp127 = tmp59 - tmp97
    tmp128 = tmp127 * tmp101
    tmp129 = tmp126 + tmp128
    tmp130 = tmp59 - tmp104
    tmp131 = tmp130 * tmp108
    tmp132 = tmp129 + tmp131
    tmp134 = tmp133 * tmp5
    tmp135 = tl.full([1], 2, tl.int64)
    tmp136 = tmp11 == tmp135
    tmp137 = tmp136.to(tl.int64)
    tmp138 = tmp137 * tmp4
    tmp139 = tmp138.to(tl.float32)
    tmp140 = tmp134 * tmp139
    tmp141 = tmp133 * tmp20
    tmp142 = tmp24 == tmp135
    tmp143 = tmp142.to(tl.int64)
    tmp144 = tmp143 * tmp19
    tmp145 = tmp144.to(tl.float32)
    tmp146 = tmp141 * tmp145
    tmp147 = tmp140 + tmp146
    tmp148 = tmp133 * tmp34
    tmp149 = tmp38 == tmp135
    tmp150 = tmp149.to(tl.int64)
    tmp151 = tmp150 * tmp33
    tmp152 = tmp151.to(tl.float32)
    tmp153 = tmp148 * tmp152
    tmp154 = tmp147 + tmp153
    tmp155 = tmp133 * tmp48
    tmp156 = tmp52 == tmp135
    tmp157 = tmp156.to(tl.int64)
    tmp158 = tmp157 * tmp47
    tmp159 = tmp158.to(tl.float32)
    tmp160 = tmp155 * tmp159
    tmp161 = tmp154 + tmp160
    tmp162 = tmp59 - tmp139
    tmp163 = tmp134 * tmp162
    tmp164 = tmp59 - tmp145
    tmp165 = tmp141 * tmp164
    tmp166 = tmp163 + tmp165
    tmp167 = tmp59 - tmp152
    tmp168 = tmp148 * tmp167
    tmp169 = tmp166 + tmp168
    tmp170 = tmp59 - tmp159
    tmp171 = tmp155 * tmp170
    tmp172 = tmp169 + tmp171
    tmp173 = tmp59 - tmp134
    tmp174 = tmp173 * tmp139
    tmp175 = tmp59 - tmp141
    tmp176 = tmp175 * tmp145
    tmp177 = tmp174 + tmp176
    tmp178 = tmp59 - tmp148
    tmp179 = tmp178 * tmp152
    tmp180 = tmp177 + tmp179
    tmp181 = tmp59 - tmp155
    tmp182 = tmp181 * tmp159
    tmp183 = tmp180 + tmp182
    tmp185 = tmp184 * tmp5
    tmp186 = tmp11 == tmp10
    tmp187 = tmp186.to(tl.int64)
    tmp188 = tmp187 * tmp4
    tmp189 = tmp188.to(tl.float32)
    tmp190 = tmp185 * tmp189
    tmp191 = tmp184 * tmp20
    tmp192 = tmp24 == tmp10
    tmp193 = tmp192.to(tl.int64)
    tmp194 = tmp193 * tmp19
    tmp195 = tmp194.to(tl.float32)
    tmp196 = tmp191 * tmp195
    tmp197 = tmp190 + tmp196
    tmp198 = tmp184 * tmp34
    tmp199 = tmp38 == tmp10
    tmp200 = tmp199.to(tl.int64)
    tmp201 = tmp200 * tmp33
    tmp202 = tmp201.to(tl.float32)
    tmp203 = tmp198 * tmp202
    tmp204 = tmp197 + tmp203
    tmp205 = tmp184 * tmp48
    tmp206 = tmp52 == tmp10
    tmp207 = tmp206.to(tl.int64)
    tmp208 = tmp207 * tmp47
    tmp209 = tmp208.to(tl.float32)
    tmp210 = tmp205 * tmp209
    tmp211 = tmp204 + tmp210
    tmp212 = tmp59 - tmp189
    tmp213 = tmp185 * tmp212
    tmp214 = tmp59 - tmp195
    tmp215 = tmp191 * tmp214
    tmp216 = tmp213 + tmp215
    tmp217 = tmp59 - tmp202
    tmp218 = tmp198 * tmp217
    tmp219 = tmp216 + tmp218
    tmp220 = tmp59 - tmp209
    tmp221 = tmp205 * tmp220
    tmp222 = tmp219 + tmp221
    tmp223 = tmp59 - tmp185
    tmp224 = tmp223 * tmp189
    tmp225 = tmp59 - tmp191
    tmp226 = tmp225 * tmp195
    tmp227 = tmp224 + tmp226
    tmp228 = tmp59 - tmp198
    tmp229 = tmp228 * tmp202
    tmp230 = tmp227 + tmp229
    tmp231 = tmp59 - tmp205
    tmp232 = tmp231 * tmp209
    tmp233 = tmp230 + tmp232
    tmp234 = 0.3
    tmp235 = tmp70 * tmp234
    tmp236 = tmp58 + tmp235
    tmp237 = 0.7
    tmp238 = tmp81 * tmp237
    tmp239 = tmp236 + tmp238
    tmp240 = 1e-06
    tmp241 = tmp239 + tmp240
    tmp242 = tmp58 / tmp241
    tmp243 = tmp59 - tmp242
    tmp244 = 0.0
    tmp245 = tmp243 + tmp244
    tmp246 = tmp121 * tmp234
    tmp247 = tmp110 + tmp246
    tmp248 = tmp132 * tmp237
    tmp249 = tmp247 + tmp248
    tmp250 = tmp249 + tmp240
    tmp251 = tmp110 / tmp250
    tmp252 = tmp59 - tmp251
    tmp253 = tmp245 + tmp252
    tmp254 = tmp172 * tmp234
    tmp255 = tmp161 + tmp254
    tmp256 = tmp183 * tmp237
    tmp257 = tmp255 + tmp256
    tmp258 = tmp257 + tmp240
    tmp259 = tmp161 / tmp258
    tmp260 = tmp59 - tmp259
    tmp261 = tmp253 + tmp260
    tmp262 = tmp222 * tmp234
    tmp263 = tmp211 + tmp262
    tmp264 = tmp233 * tmp237
    tmp265 = tmp263 + tmp264
    tmp266 = tmp265 + tmp240
    tmp267 = tmp211 / tmp266
    tmp268 = tmp59 - tmp267
    tmp269 = tmp261 + tmp268
    tmp270 = 0.25
    tmp271 = tmp269 * tmp270
    tmp272 = tmp271 * tmp59
    tl.store(in_out_ptr0 + (x0), tmp272, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pred], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(arg0_1, buf0, 16, grid=grid(16), stream=stream0)
        del arg0_1
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [pred], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf0, buf1, 16, grid=grid(16), stream=stream0)
        del buf0
        buf10 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf11 = buf10; del buf10  # reuse
        buf15 = buf11; del buf11  # reuse
        # Topologically Sorted Source Nodes: [ne, valid_mask, valid_mask_1, valid_pred, valid_target, mul_2, intersection, sub, mul_3, fps, mul_5, add, sub_1, mul_4, fns, mul_6, denominator, add_2, truediv, tversky_loss_value, add_12, valid_mask_2, valid_pred_1, valid_target_1, mul_9, intersection_1, sub_3, mul_10, fps_1, mul_12, add_3, sub_4, mul_11, fns_1, mul_13, denominator_1, add_5, truediv_1, tversky_loss_value_1, add_13, valid_mask_3, valid_pred_2, valid_target_2, mul_16, intersection_2, sub_6, mul_17, fps_2, mul_19, add_6, sub_7, mul_18, fns_2, mul_20, denominator_2, add_8, truediv_2, tversky_loss_value_2, add_14, valid_mask_4, valid_pred_3, valid_target_3, mul_23, intersection_3, sub_9, mul_24, fps_3, mul_26, add_9, sub_10, mul_25, fns_3, mul_27, denominator_3, add_11, truediv_3, tversky_loss_value_3, add_15, loss, loss_1], Original ATen: [aten.ne, aten._to_copy, aten.view, aten.mul, aten.sum, aten.rsub, aten.add, aten.div]
        triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_2.run(buf15, buf1, arg1_1, 4, grid=grid(4), stream=stream0)
        del arg1_1
        del buf1
    return (buf15, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    arg1_1 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1, arg1_1])
    return print_performance(fn, times=times, repeat=repeat)


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

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 numpy as np
import torch.nn as nn
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_2(in_out_ptr0,
    in_ptr0, in_ptr1, 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 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp31 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp45 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp82 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp133 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp184 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = 255.0
    tmp3 = tmp1 != tmp2
    tmp4 = tmp3.to(tl.int64)
    tmp5 = tmp4.to(tl.float32)
    tmp6 = tmp0 * tmp5
    tmp7 = tmp1.to(tl.int64)
    tmp8 = tl.full([1], 0, tl.int64)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp10 = tl.full([1], 3, tl.int64)
    tmp11 = triton_helpers.minimum(tmp9, tmp10)
    tmp12 = tmp11 == tmp8
    tmp13 = tmp12.to(tl.int64)
    tmp14 = tmp13 * tmp4
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp6 * tmp15
    tmp18 = tmp17 != tmp2
    tmp19 = tmp18.to(tl.int64)
    tmp20 = tmp19.to(tl.float32)
    tmp21 = tmp0 * tmp20
    tmp22 = tmp17.to(tl.int64)
    tmp23 = triton_helpers.maximum(tmp22, tmp8)
    tmp24 = triton_helpers.minimum(tmp23, tmp10)
    tmp25 = tmp24 == tmp8
    tmp26 = tmp25.to(tl.int64)
    tmp27 = tmp26 * tmp19
    tmp28 = tmp27.to(tl.float32)
    tmp29 = tmp21 * tmp28
    tmp30 = tmp16 + tmp29
    tmp32 = tmp31 != tmp2
    tmp33 = tmp32.to(tl.int64)
    tmp34 = tmp33.to(tl.float32)
    tmp35 = tmp0 * tmp34
    tmp36 = tmp31.to(tl.int64)
    tmp37 = triton_helpers.maximum(tmp36, tmp8)
    tmp38 = triton_helpers.minimum(tmp37, tmp10)
    tmp39 = tmp38 == tmp8
    tmp40 = tmp39.to(tl.int64)
    tmp41 = tmp40 * tmp33
    tmp42 = tmp41.to(tl.float32)
    tmp43 = tmp35 * tmp42
    tmp44 = tmp30 + tmp43
    tmp46 = tmp45 != tmp2
    tmp47 = tmp46.to(tl.int64)
    tmp48 = tmp47.to(tl.float32)
    tmp49 = tmp0 * tmp48
    tmp50 = tmp45.to(tl.int64)
    tmp51 = triton_helpers.maximum(tmp50, tmp8)
    tmp52 = triton_helpers.minimum(tmp51, tmp10)
    tmp53 = tmp52 == tmp8
    tmp54 = tmp53.to(tl.int64)
    tmp55 = tmp54 * tmp47
    tmp56 = tmp55.to(tl.float32)
    tmp57 = tmp49 * tmp56
    tmp58 = tmp44 + tmp57
    tmp59 = 1.0
    tmp60 = tmp59 - tmp15
    tmp61 = tmp6 * tmp60
    tmp62 = tmp59 - tmp28
    tmp63 = tmp21 * tmp62
    tmp64 = tmp61 + tmp63
    tmp65 = tmp59 - tmp42
    tmp66 = tmp35 * tmp65
    tmp67 = tmp64 + tmp66
    tmp68 = tmp59 - tmp56
    tmp69 = tmp49 * tmp68
    tmp70 = tmp67 + tmp69
    tmp71 = tmp59 - tmp6
    tmp72 = tmp71 * tmp15
    tmp73 = tmp59 - tmp21
    tmp74 = tmp73 * tmp28
    tmp75 = tmp72 + tmp74
    tmp76 = tmp59 - tmp35
    tmp77 = tmp76 * tmp42
    tmp78 = tmp75 + tmp77
    tmp79 = tmp59 - tmp49
    tmp80 = tmp79 * tmp56
    tmp81 = tmp78 + tmp80
    tmp83 = tmp82 * tmp5
    tmp84 = tl.full([1], 1, tl.int64)
    tmp85 = tmp11 == tmp84
    tmp86 = tmp85.to(tl.int64)
    tmp87 = tmp86 * tmp4
    tmp88 = tmp87.to(tl.float32)
    tmp89 = tmp83 * tmp88
    tmp90 = tmp82 * tmp20
    tmp91 = tmp24 == tmp84
    tmp92 = tmp91.to(tl.int64)
    tmp93 = tmp92 * tmp19
    tmp94 = tmp93.to(tl.float32)
    tmp95 = tmp90 * tmp94
    tmp96 = tmp89 + tmp95
    tmp97 = tmp82 * tmp34
    tmp98 = tmp38 == tmp84
    tmp99 = tmp98.to(tl.int64)
    tmp100 = tmp99 * tmp33
    tmp101 = tmp100.to(tl.float32)
    tmp102 = tmp97 * tmp101
    tmp103 = tmp96 + tmp102
    tmp104 = tmp82 * tmp48
    tmp105 = tmp52 == tmp84
    tmp106 = tmp105.to(tl.int64)
    tmp107 = tmp106 * tmp47
    tmp108 = tmp107.to(tl.float32)
    tmp109 = tmp104 * tmp108
    tmp110 = tmp103 + tmp109
    tmp111 = tmp59 - tmp88
    tmp112 = tmp83 * tmp111
    tmp113 = tmp59 - tmp94
    tmp114 = tmp90 * tmp113
    tmp115 = tmp112 + tmp114
    tmp116 = tmp59 - tmp101
    tmp117 = tmp97 * tmp116
    tmp118 = tmp115 + tmp117
    tmp119 = tmp59 - tmp108
    tmp120 = tmp104 * tmp119
    tmp121 = tmp118 + tmp120
    tmp122 = tmp59 - tmp83
    tmp123 = tmp122 * tmp88
    tmp124 = tmp59 - tmp90
    tmp125 = tmp124 * tmp94
    tmp126 = tmp123 + tmp125
    tmp127 = tmp59 - tmp97
    tmp128 = tmp127 * tmp101
    tmp129 = tmp126 + tmp128
    tmp130 = tmp59 - tmp104
    tmp131 = tmp130 * tmp108
    tmp132 = tmp129 + tmp131
    tmp134 = tmp133 * tmp5
    tmp135 = tl.full([1], 2, tl.int64)
    tmp136 = tmp11 == tmp135
    tmp137 = tmp136.to(tl.int64)
    tmp138 = tmp137 * tmp4
    tmp139 = tmp138.to(tl.float32)
    tmp140 = tmp134 * tmp139
    tmp141 = tmp133 * tmp20
    tmp142 = tmp24 == tmp135
    tmp143 = tmp142.to(tl.int64)
    tmp144 = tmp143 * tmp19
    tmp145 = tmp144.to(tl.float32)
    tmp146 = tmp141 * tmp145
    tmp147 = tmp140 + tmp146
    tmp148 = tmp133 * tmp34
    tmp149 = tmp38 == tmp135
    tmp150 = tmp149.to(tl.int64)
    tmp151 = tmp150 * tmp33
    tmp152 = tmp151.to(tl.float32)
    tmp153 = tmp148 * tmp152
    tmp154 = tmp147 + tmp153
    tmp155 = tmp133 * tmp48
    tmp156 = tmp52 == tmp135
    tmp157 = tmp156.to(tl.int64)
    tmp158 = tmp157 * tmp47
    tmp159 = tmp158.to(tl.float32)
    tmp160 = tmp155 * tmp159
    tmp161 = tmp154 + tmp160
    tmp162 = tmp59 - tmp139
    tmp163 = tmp134 * tmp162
    tmp164 = tmp59 - tmp145
    tmp165 = tmp141 * tmp164
    tmp166 = tmp163 + tmp165
    tmp167 = tmp59 - tmp152
    tmp168 = tmp148 * tmp167
    tmp169 = tmp166 + tmp168
    tmp170 = tmp59 - tmp159
    tmp171 = tmp155 * tmp170
    tmp172 = tmp169 + tmp171
    tmp173 = tmp59 - tmp134
    tmp174 = tmp173 * tmp139
    tmp175 = tmp59 - tmp141
    tmp176 = tmp175 * tmp145
    tmp177 = tmp174 + tmp176
    tmp178 = tmp59 - tmp148
    tmp179 = tmp178 * tmp152
    tmp180 = tmp177 + tmp179
    tmp181 = tmp59 - tmp155
    tmp182 = tmp181 * tmp159
    tmp183 = tmp180 + tmp182
    tmp185 = tmp184 * tmp5
    tmp186 = tmp11 == tmp10
    tmp187 = tmp186.to(tl.int64)
    tmp188 = tmp187 * tmp4
    tmp189 = tmp188.to(tl.float32)
    tmp190 = tmp185 * tmp189
    tmp191 = tmp184 * tmp20
    tmp192 = tmp24 == tmp10
    tmp193 = tmp192.to(tl.int64)
    tmp194 = tmp193 * tmp19
    tmp195 = tmp194.to(tl.float32)
    tmp196 = tmp191 * tmp195
    tmp197 = tmp190 + tmp196
    tmp198 = tmp184 * tmp34
    tmp199 = tmp38 == tmp10
    tmp200 = tmp199.to(tl.int64)
    tmp201 = tmp200 * tmp33
    tmp202 = tmp201.to(tl.float32)
    tmp203 = tmp198 * tmp202
    tmp204 = tmp197 + tmp203
    tmp205 = tmp184 * tmp48
    tmp206 = tmp52 == tmp10
    tmp207 = tmp206.to(tl.int64)
    tmp208 = tmp207 * tmp47
    tmp209 = tmp208.to(tl.float32)
    tmp210 = tmp205 * tmp209
    tmp211 = tmp204 + tmp210
    tmp212 = tmp59 - tmp189
    tmp213 = tmp185 * tmp212
    tmp214 = tmp59 - tmp195
    tmp215 = tmp191 * tmp214
    tmp216 = tmp213 + tmp215
    tmp217 = tmp59 - tmp202
    tmp218 = tmp198 * tmp217
    tmp219 = tmp216 + tmp218
    tmp220 = tmp59 - tmp209
    tmp221 = tmp205 * tmp220
    tmp222 = tmp219 + tmp221
    tmp223 = tmp59 - tmp185
    tmp224 = tmp223 * tmp189
    tmp225 = tmp59 - tmp191
    tmp226 = tmp225 * tmp195
    tmp227 = tmp224 + tmp226
    tmp228 = tmp59 - tmp198
    tmp229 = tmp228 * tmp202
    tmp230 = tmp227 + tmp229
    tmp231 = tmp59 - tmp205
    tmp232 = tmp231 * tmp209
    tmp233 = tmp230 + tmp232
    tmp234 = 0.3
    tmp235 = tmp70 * tmp234
    tmp236 = tmp58 + tmp235
    tmp237 = 0.7
    tmp238 = tmp81 * tmp237
    tmp239 = tmp236 + tmp238
    tmp240 = 1e-06
    tmp241 = tmp239 + tmp240
    tmp242 = tmp58 / tmp241
    tmp243 = tmp59 - tmp242
    tmp244 = 0.0
    tmp245 = tmp243 + tmp244
    tmp246 = tmp121 * tmp234
    tmp247 = tmp110 + tmp246
    tmp248 = tmp132 * tmp237
    tmp249 = tmp247 + tmp248
    tmp250 = tmp249 + tmp240
    tmp251 = tmp110 / tmp250
    tmp252 = tmp59 - tmp251
    tmp253 = tmp245 + tmp252
    tmp254 = tmp172 * tmp234
    tmp255 = tmp161 + tmp254
    tmp256 = tmp183 * tmp237
    tmp257 = tmp255 + tmp256
    tmp258 = tmp257 + tmp240
    tmp259 = tmp161 / tmp258
    tmp260 = tmp59 - tmp259
    tmp261 = tmp253 + tmp260
    tmp262 = tmp222 * tmp234
    tmp263 = tmp211 + tmp262
    tmp264 = tmp233 * tmp237
    tmp265 = tmp263 + tmp264
    tmp266 = tmp265 + tmp240
    tmp267 = tmp211 / tmp266
    tmp268 = tmp59 - tmp267
    tmp269 = tmp261 + tmp268
    tmp270 = 0.25
    tmp271 = tmp269 * tmp270
    tmp272 = tmp271 * tmp59
    tl.store(in_out_ptr0 + x0, tmp272, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del arg0_1
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(16)](buf0, buf1, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf0
        buf10 = empty_strided_cuda((4,), (1,), torch.float32)
        buf11 = buf10
        del buf10
        buf15 = buf11
        del buf11
        triton_poi_fused__to_copy_add_div_mul_ne_rsub_sum_view_2[grid(4)](buf15
            , buf1, arg1_1, 4, XBLOCK=4, num_warps=1, num_stages=1)
        del arg1_1
        del buf1
    return buf15,


def get_class_weight(class_weight):
    """Get class weight for loss function.

    Args:
        class_weight (list[float] | str | None): If class_weight is a str,
            take it as a file name and read from it.
    """
    if isinstance(class_weight, str):
        if class_weight.endswith('.npy'):
            class_weight = np.load(class_weight)
        else:
            class_weight = mmcv.load(class_weight)
    return class_weight


def binary_tversky_loss(pred, target, valid_mask, alpha, beta, eps=1e-06):
    assert pred.shape[0] == target.shape[0]
    pred = pred.reshape(pred.shape[0], -1)
    target = target.reshape(target.shape[0], -1)
    valid_mask = valid_mask.reshape(valid_mask.shape[0], -1)
    valid_pred = torch.mul(pred, valid_mask)
    valid_target = torch.mul(target, valid_mask)
    intersection = torch.sum(valid_pred * valid_target, dim=1)
    fps = torch.sum(valid_pred * (1.0 - valid_target), dim=1)
    fns = torch.sum((1.0 - valid_pred) * valid_target, dim=1)
    numerator = intersection
    denominator = intersection + alpha * fps + beta * fns
    return 1.0 - numerator / (denominator + eps)


def tversky_loss(pred, target, valid_mask, alpha, beta, eps=1e-06,
    class_weight=None, reduction='mean', avg_factor=None, ignore_index=255,
    **kwargs):
    assert pred.shape[0] == target.shape[0]
    num_classes = pred.shape[1]
    if num_classes == 1:
        class_ids = [0] if ignore_index != 0 else []
    elif num_classes == 2:
        class_ids = [1] if ignore_index != 1 else []
    else:
        class_ids = [i for i in range(num_classes) if i != ignore_index]
    assert len(class_ids) >= 1
    class_losses = []
    for i in class_ids:
        tversky_loss_value = binary_tversky_loss(pred[:, i], target[..., i],
            valid_mask=valid_mask, alpha=alpha, beta=beta, eps=eps)
        if class_weight is not None:
            tversky_loss_value *= class_weight[i]
        class_losses.append(tversky_loss_value)
    if avg_factor is None:
        if reduction == 'mean':
            loss = sum(class_losses) / float(len(class_losses))
        elif reduction == 'sum':
            loss = sum(class_losses)
        elif reduction == 'none':
            loss = class_losses
        else:
            raise ValueError(f'unknown reduction type: {reduction}')
    elif reduction == 'mean':
        loss = sum(class_losses) / avg_factor
    elif reduction != 'none':
        raise ValueError('avg_factor can not be used with reduction="sum"')
    return loss


class TverskyLossNew(nn.Module):
    """TverskyLoss.

    This loss is proposed in `Tversky loss function for image segmentation
    using 3D fully convolutional deep networks <https://arxiv.org/abs/1706.05721>`_.
    """

    def __init__(self, alpha=0.3, beta=0.7, eps=1e-06, reduction='mean',
        class_weight=None, loss_weight=1.0):
        super(TverskyLossNew, self).__init__()
        self.alpha = alpha
        self.beta = beta
        self.eps = eps
        self.reduction = reduction
        self.class_weight = get_class_weight(class_weight)
        self.loss_weight = loss_weight

    @property
    def name(self):
        return 'tversky'

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0]
