# 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_4/inductor_cache/4s/c4s63j6mvfuvext2t2cidkkt5ddb6evlex2lwuvnabga4rsw5ie6.py
# Topologically Sorted Source Nodes: [max_1], Original ATen: [aten.max]
# Source node to ATen node mapping:
#   max_1 => max_1
# Graph fragment:
#   %max_1 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%view_1, -1), kwargs = {})
triton_per_fused_max_0 = async_compile.triton('triton_per_fused_max_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_max_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 1, '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}
)
@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (16*x0)), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, float("-inf"))
    tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/bq/cbqq2xgq45szt2u7qi54ixzipn2dum6zf3a4e3qwnrupgah6z3ll.py
# Topologically Sorted Source Nodes: [summed], Original ATen: [aten.sum]
# Source node to ATen node mapping:
#   summed => sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view, [-1]), kwargs = {})
triton_per_fused_sum_1 = async_compile.triton('triton_per_fused_sum_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_sum_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 1, '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}
)
@triton.jit
def triton_per_fused_sum_1(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (16*x0)), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/44/c44aqxyg5dsh5loywzzadng7tffslpcogbkveq344dztt2ax4pkq.py
# Topologically Sorted Source Nodes: [gt, targets_fc, binary_cross_entropy_with_logits], Original ATen: [aten.gt, aten._to_copy, aten.binary_cross_entropy_with_logits]
# Source node to ATen node mapping:
#   binary_cross_entropy_with_logits => abs_1, exp, full_default, log1p, mean, minimum, mul, neg, sub, sub_1, sub_2
#   gt => gt
#   targets_fc => convert_element_type
# Graph fragment:
#   %gt : [num_users=1] = call_function[target=torch.ops.aten.gt.Scalar](args = (%sum_1, 0), kwargs = {})
#   %convert_element_type : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%gt, torch.float32), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %convert_element_type), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %getitem), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %minimum : [num_users=1] = call_function[target=torch.ops.aten.minimum.default](args = (%full_default, %getitem), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%getitem,), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%abs_1,), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%neg,), kwargs = {})
#   %log1p : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%minimum, %log1p), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul, %sub_1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_2,), kwargs = {})
triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2 = async_compile.triton('triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_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.persistent_reduction(
    size_hints=[1, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {3: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 4), equal_to_1=(3,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 1, '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}
)
@triton.jit
def triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    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 + (r0), None)
    tmp6 = tl.load(in_ptr1 + (r0), None)
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = tmp2.to(tl.float32)
    tmp4 = 1.0
    tmp5 = tmp4 - tmp3
    tmp7 = tmp5 * tmp6
    tmp8 = triton_helpers.minimum(tmp1, tmp6)
    tmp9 = tl_math.abs(tmp6)
    tmp10 = -tmp9
    tmp11 = tl_math.exp(tmp10)
    tmp12 = libdevice.log1p(tmp11)
    tmp13 = tmp8 - tmp12
    tmp14 = tmp7 - tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tl.store(out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp17, None)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/zo/czok6dmxojezdhlzhf4i7xepckz2xmjnr3xmjxnb3bcgrtialigw.py
# Topologically Sorted Source Nodes: [binary_cross_entropy_with_logits_1], Original ATen: [aten.binary_cross_entropy_with_logits]
# Source node to ATen node mapping:
#   binary_cross_entropy_with_logits_1 => abs_2, exp_1, full_default_1, log1p_1, mean_5, minimum_1, mul_11, neg_1, sub_7, sub_8, sub_9
# Graph fragment:
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_7, %arg1_1), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %minimum_1 : [num_users=1] = call_function[target=torch.ops.aten.minimum.default](args = (%full_default_1, %arg1_1), kwargs = {})
#   %abs_2 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%arg1_1,), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%abs_2,), kwargs = {})
#   %exp_1 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%neg_1,), kwargs = {})
#   %log1p_1 : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp_1,), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%minimum_1, %log1p_1), kwargs = {})
#   %sub_9 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul_11, %sub_8), kwargs = {})
#   %mean_5 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_9,), kwargs = {})
triton_per_fused_binary_cross_entropy_with_logits_3 = async_compile.triton('triton_per_fused_binary_cross_entropy_with_logits_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.persistent_reduction(
    size_hints=[1, 256],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {3: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 4), equal_to_1=(3,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_binary_cross_entropy_with_logits_3', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 2, 'num_reduction': 1, '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}
)
@triton.jit
def triton_per_fused_binary_cross_entropy_with_logits_3(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel):
    xnumel = 1
    XBLOCK: tl.constexpr = 1
    rnumel = 256
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    xmask = tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    roffset = 0
    rmask = tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (r0), None)
    tmp3 = tl.load(in_ptr1 + (r0), None)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tmp2 * tmp3
    tmp5 = 0.0
    tmp6 = triton_helpers.minimum(tmp5, tmp3)
    tmp7 = tl_math.abs(tmp3)
    tmp8 = -tmp7
    tmp9 = tl_math.exp(tmp8)
    tmp10 = libdevice.log1p(tmp9)
    tmp11 = tmp6 - tmp10
    tmp12 = tmp4 - tmp11
    tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
    tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tl.store(out_ptr0 + (tl.full([1], 0, tl.int32)), tmp15, None)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/sm/csmlqdo5seb7xeh7b4rk22epnaj2komkonpqsj56xrdjng6vtq4y.py
# Topologically Sorted Source Nodes: [mul_1, intersection, sum_3, sum_4], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   intersection => sum_2
#   mul_1 => mul_2
#   sum_3 => sum_3
#   sum_4 => sum_4
# Graph fragment:
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_2, %view_3), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [1]), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_2, [1]), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_3, [1]), kwargs = {})
triton_per_fused_mul_sum_4 = async_compile.triton('triton_per_fused_mul_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=[4, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 3, '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}
)
@triton.jit
def triton_per_fused_mul_sum_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (64*x0)), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (r1 + (64*x0)), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp7, xmask)
    tl.store(out_ptr1 + (x0), tmp11, xmask)
    tl.store(out_ptr2 + (x0), tmp15, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/2g/c2gagxetloc44hzb24nfmumgfrgfaeztmdk7rm4yugeev6uskipb.py
# Topologically Sorted Source Nodes: [mul_3, intersection_1, sum_6, sum_7], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   intersection_1 => sum_5
#   mul_3 => mul_4
#   sum_6 => sum_6
#   sum_7 => sum_7
# Graph fragment:
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_4, %view_5), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_4, [1]), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_4, [1]), kwargs = {})
#   %sum_7 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_5, [1]), kwargs = {})
triton_per_fused_mul_sum_5 = async_compile.triton('triton_per_fused_mul_sum_5', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.persistent_reduction(
    size_hints=[4, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 3, '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}
)
@triton.jit
def triton_per_fused_mul_sum_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (16 + r1 + (64*x0)), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (16 + r1 + (64*x0)), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp7, xmask)
    tl.store(out_ptr1 + (x0), tmp11, xmask)
    tl.store(out_ptr2 + (x0), tmp15, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/wp/cwpkk6hbytfxyk4cdywum5vb4buyn3zapu3h4yilbkl2czz7okxm.py
# Topologically Sorted Source Nodes: [mul_5, intersection_2, sum_9, sum_10], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   intersection_2 => sum_8
#   mul_5 => mul_6
#   sum_10 => sum_10
#   sum_9 => sum_9
# Graph fragment:
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_6, %view_7), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_6, [1]), kwargs = {})
#   %sum_9 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_6, [1]), kwargs = {})
#   %sum_10 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_7, [1]), kwargs = {})
triton_per_fused_mul_sum_6 = async_compile.triton('triton_per_fused_mul_sum_6', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.persistent_reduction(
    size_hints=[4, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 3, '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}
)
@triton.jit
def triton_per_fused_mul_sum_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (32 + r1 + (64*x0)), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (32 + r1 + (64*x0)), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp7, xmask)
    tl.store(out_ptr1 + (x0), tmp11, xmask)
    tl.store(out_ptr2 + (x0), tmp15, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/aw/cawi56mp5p2xtdnkn2urt6np7tktgl52d676uwzxkyac2wp3fpma.py
# Topologically Sorted Source Nodes: [mul_7, intersection_3, sum_12, sum_13], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   intersection_3 => sum_11
#   mul_7 => mul_8
#   sum_12 => sum_12
#   sum_13 => sum_13
# Graph fragment:
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_8, %view_9), kwargs = {})
#   %sum_11 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_8, [1]), kwargs = {})
#   %sum_12 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_8, [1]), kwargs = {})
#   %sum_13 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%view_9, [1]), kwargs = {})
triton_per_fused_mul_sum_7 = async_compile.triton('triton_per_fused_mul_sum_7', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.persistent_reduction(
    size_hints=[4, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 3, '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}
)
@triton.jit
def triton_per_fused_mul_sum_7(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (48 + r1 + (64*x0)), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (48 + r1 + (64*x0)), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp7, xmask)
    tl.store(out_ptr1 + (x0), tmp11, xmask)
    tl.store(out_ptr2 + (x0), tmp15, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/zq/czqgnu4gkdvlkmjtia2pekei5a7ae2pe6vijazy3vhlcktkz6g74.py
# Topologically Sorted Source Nodes: [gt, targets_fc, binary_cross_entropy_with_logits, loss_fc, binary_cross_entropy_with_logits_1, loss_seg_bce, add_13, mul_2, add_1, union, add_2, score, sub, score_1, loss, mul_4, add_5, union_1, add_6, score_2, sub_1, score_3, loss_1, mul_6, add_8, union_2, add_9, score_4, sub_2, score_5, loss_2, mul_8, add_11, union_3, add_12, score_6, sub_3, score_7, loss_3, truediv_4, loss_seg_dice, loss_4], Original ATen: [aten.gt, aten._to_copy, aten.binary_cross_entropy_with_logits, aten.mul, aten.add, aten.div, aten.rsub, aten.mean]
# Source node to ATen node mapping:
#   add_1 => add_1
#   add_11 => add_13
#   add_12 => add_14
#   add_13 => add_16
#   add_2 => add_2
#   add_5 => add_5
#   add_6 => add_6
#   add_8 => add_9
#   add_9 => add_10
#   binary_cross_entropy_with_logits => abs_1, exp, full_default, log1p, mean, minimum, mul, neg, sub, sub_1, sub_2
#   binary_cross_entropy_with_logits_1 => abs_2, exp_1, full_default_1, log1p_1, mean_5, minimum_1, mul_11, neg_1, sub_7, sub_8, sub_9
#   gt => gt
#   loss => add_3
#   loss_1 => add_7
#   loss_2 => add_11
#   loss_3 => add_15
#   loss_4 => add_17
#   loss_fc => mul_1
#   loss_seg_bce => mul_12
#   loss_seg_dice => mul_10
#   mul_2 => mul_3
#   mul_4 => mul_5
#   mul_6 => mul_7
#   mul_8 => mul_9
#   score => div
#   score_1 => mean_1
#   score_2 => div_1
#   score_3 => mean_2
#   score_4 => div_2
#   score_5 => mean_3
#   score_6 => div_3
#   score_7 => mean_4
#   sub => sub_3
#   sub_1 => sub_4
#   sub_2 => sub_5
#   sub_3 => sub_6
#   targets_fc => convert_element_type
#   truediv_4 => div_4
#   union => add
#   union_1 => add_4
#   union_2 => add_8
#   union_3 => add_12
# Graph fragment:
#   %gt : [num_users=1] = call_function[target=torch.ops.aten.gt.Scalar](args = (%sum_1, 0), kwargs = {})
#   %convert_element_type : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%gt, torch.float32), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %convert_element_type), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %getitem), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %minimum : [num_users=1] = call_function[target=torch.ops.aten.minimum.default](args = (%full_default, %getitem), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%getitem,), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%abs_1,), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%neg,), kwargs = {})
#   %log1p : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%minimum, %log1p), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul, %sub_1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_2,), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean, 0.1), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_7, %arg1_1), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %minimum_1 : [num_users=1] = call_function[target=torch.ops.aten.minimum.default](args = (%full_default_1, %arg1_1), kwargs = {})
#   %abs_2 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%arg1_1,), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%abs_2,), kwargs = {})
#   %exp_1 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%neg_1,), kwargs = {})
#   %log1p_1 : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp_1,), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%minimum_1, %log1p_1), kwargs = {})
#   %sub_9 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul_11, %sub_8), kwargs = {})
#   %mean_5 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_9,), kwargs = {})
#   %mul_12 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean_5, 1), kwargs = {})
#   %add_16 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_1, %mul_12), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_2, 2), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_3, 1e-09), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_3, %sum_4), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, 1e-09), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_1, %add_2), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %div), kwargs = {})
#   %mean_1 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_3,), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mean_1, 0), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_5, 2), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_5, 1e-09), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_6, %sum_7), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_4, 1e-09), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_5, %add_6), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %div_1), kwargs = {})
#   %mean_2 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_4,), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_3, %mean_2), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_8, 2), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_7, 1e-09), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_9, %sum_10), kwargs = {})
#   %add_10 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_8, 1e-09), kwargs = {})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_9, %add_10), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %div_2), kwargs = {})
#   %mean_3 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_5,), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_7, %mean_3), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_11, 2), kwargs = {})
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_9, 1e-09), kwargs = {})
#   %add_12 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_12, %sum_13), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_12, 1e-09), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_13, %add_14), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %div_3), kwargs = {})
#   %mean_4 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_6,), kwargs = {})
#   %add_15 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_11, %mean_4), kwargs = {})
#   %div_4 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_15, 4), kwargs = {})
#   %mul_10 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div_4, 0), kwargs = {})
#   %add_17 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_16, %mul_10), kwargs = {})
triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8 = async_compile.triton('triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8', '''
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.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: '*fp32', 8: '*fp32', 9: '*fp32', 10: '*fp32', 11: '*fp32', 12: '*fp32', 13: '*fp32', 14: '*fp32', 15: 'i32', 16: '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': {15: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), equal_to_1=(15,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 14, 'num_reduction': 4, '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}
)
@triton.jit
def triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, in_ptr12, in_ptr13, 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 + (r0), None)
    tmp5 = tl.load(in_ptr1 + (r0), None)
    tmp6 = tl.load(in_ptr2 + (r0), None)
    tmp15 = tl.load(in_ptr3 + (r0), None)
    tmp18 = tl.load(in_ptr4 + (r0), None)
    tmp19 = tl.load(in_ptr5 + (r0), None)
    tmp27 = tl.load(in_ptr6 + (r0), None)
    tmp30 = tl.load(in_ptr7 + (r0), None)
    tmp31 = tl.load(in_ptr8 + (r0), None)
    tmp39 = tl.load(in_ptr9 + (r0), None)
    tmp42 = tl.load(in_ptr10 + (r0), None)
    tmp43 = tl.load(in_ptr11 + (r0), None)
    tmp51 = tl.load(in_ptr12 + (0))
    tmp52 = tl.broadcast_to(tmp51, [XBLOCK, 1])
    tmp57 = tl.load(in_ptr13 + (0))
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK, 1])
    tmp1 = 2.0
    tmp2 = tmp0 * tmp1
    tmp3 = 1e-09
    tmp4 = tmp2 + tmp3
    tmp7 = tmp5 + tmp6
    tmp8 = tmp7 + tmp3
    tmp9 = tmp4 / tmp8
    tmp10 = 1.0
    tmp11 = tmp10 - tmp9
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp14 = tl.sum(tmp12, 1)[:, None]
    tmp16 = tmp15 * tmp1
    tmp17 = tmp16 + tmp3
    tmp20 = tmp18 + tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tmp17 / tmp21
    tmp23 = tmp10 - tmp22
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
    tmp26 = tl.sum(tmp24, 1)[:, None]
    tmp28 = tmp27 * tmp1
    tmp29 = tmp28 + tmp3
    tmp32 = tmp30 + tmp31
    tmp33 = tmp32 + tmp3
    tmp34 = tmp29 / tmp33
    tmp35 = tmp10 - tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp40 = tmp39 * tmp1
    tmp41 = tmp40 + tmp3
    tmp44 = tmp42 + tmp43
    tmp45 = tmp44 + tmp3
    tmp46 = tmp41 / tmp45
    tmp47 = tmp10 - tmp46
    tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
    tmp50 = tl.sum(tmp48, 1)[:, None]
    tmp53 = 16.0
    tmp54 = tmp52 / tmp53
    tmp55 = 0.1
    tmp56 = tmp54 * tmp55
    tmp59 = 256.0
    tmp60 = tmp58 / tmp59
    tmp61 = tmp60 * tmp10
    tmp62 = tmp56 + tmp61
    tmp63 = 4.0
    tmp64 = tmp14 / tmp63
    tmp65 = 0.0
    tmp66 = tmp64 + tmp65
    tmp67 = tmp26 / tmp63
    tmp68 = tmp66 + tmp67
    tmp69 = tmp38 / tmp63
    tmp70 = tmp68 + tmp69
    tmp71 = tmp50 / tmp63
    tmp72 = tmp70 + tmp71
    tmp73 = 0.25
    tmp74 = tmp72 * tmp73
    tmp75 = tmp74 * tmp65
    tmp76 = tmp62 + tmp75
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp76, None)
''', 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, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 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: [max_1], Original ATen: [aten.max]
        stream0 = get_raw_stream(0)
        triton_per_fused_max_0.run(arg1_1, buf0, 16, 16, grid=grid(16), stream=stream0)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [summed], Original ATen: [aten.sum]
        triton_per_fused_sum_1.run(arg0_1, buf2, 16, 16, grid=grid(16), stream=stream0)
        buf3 = empty_strided_cuda((), (), torch.float32)
        # Topologically Sorted Source Nodes: [gt, targets_fc, binary_cross_entropy_with_logits], Original ATen: [aten.gt, aten._to_copy, aten.binary_cross_entropy_with_logits]
        triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2.run(buf2, buf0, buf3, 1, 16, grid=grid(1), stream=stream0)
        del buf0
        del buf2
        buf4 = empty_strided_cuda((), (), torch.float32)
        # Topologically Sorted Source Nodes: [binary_cross_entropy_with_logits_1], Original ATen: [aten.binary_cross_entropy_with_logits]
        triton_per_fused_binary_cross_entropy_with_logits_3.run(arg0_1, arg1_1, buf4, 1, 256, grid=grid(1), stream=stream0)
        buf5 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf6 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf7 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [mul_1, intersection, sum_3, sum_4], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_4.run(arg1_1, arg0_1, buf5, buf6, buf7, 4, 16, grid=grid(4), stream=stream0)
        buf9 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf10 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf11 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [mul_3, intersection_1, sum_6, sum_7], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_5.run(arg1_1, arg0_1, buf9, buf10, buf11, 4, 16, grid=grid(4), stream=stream0)
        buf13 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf14 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf15 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [mul_5, intersection_2, sum_9, sum_10], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_6.run(arg1_1, arg0_1, buf13, buf14, buf15, 4, 16, grid=grid(4), stream=stream0)
        buf17 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf18 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf19 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [mul_7, intersection_3, sum_12, sum_13], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_7.run(arg1_1, arg0_1, buf17, buf18, buf19, 4, 16, grid=grid(4), stream=stream0)
        del arg0_1
        del arg1_1
        buf12 = empty_strided_cuda((), (), torch.float32)
        buf21 = buf12; del buf12  # reuse
        # Topologically Sorted Source Nodes: [gt, targets_fc, binary_cross_entropy_with_logits, loss_fc, binary_cross_entropy_with_logits_1, loss_seg_bce, add_13, mul_2, add_1, union, add_2, score, sub, score_1, loss, mul_4, add_5, union_1, add_6, score_2, sub_1, score_3, loss_1, mul_6, add_8, union_2, add_9, score_4, sub_2, score_5, loss_2, mul_8, add_11, union_3, add_12, score_6, sub_3, score_7, loss_3, truediv_4, loss_seg_dice, loss_4], Original ATen: [aten.gt, aten._to_copy, aten.binary_cross_entropy_with_logits, aten.mul, aten.add, aten.div, aten.rsub, aten.mean]
        triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8.run(buf21, buf5, buf6, buf7, buf9, buf10, buf11, buf13, buf14, buf15, buf17, buf18, buf19, buf3, buf4, 1, 4, grid=grid(1), stream=stream0)
        del buf10
        del buf11
        del buf13
        del buf14
        del buf15
        del buf17
        del buf18
        del buf19
        del buf3
        del buf4
        del buf5
        del buf6
        del buf7
        del buf9
    return (buf21, )


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


class SoftDiceLoss(nn.Module):
    """Differentiable soft dice loss.

    Note: Sigmoid is automatically applied here!
    """

    def __init__(self):
        super(SoftDiceLoss, self).__init__()

    def forward(self, logits, targets):
        eps = 1e-09
        num = targets.size(0)
        probs = torch.sigmoid(logits)
        m1 = probs.view(num, -1)
        m2 = targets.view(num, -1).float()
        intersection = torch.sum(m1 * m2, 1)
        union = torch.sum(m1, dim=1) + torch.sum(m2, dim=1)
        score = (2 * intersection + eps) / (union + eps)
        score = (1 - score).mean()
        return score


class MultiLabelDiceLoss(nn.Module):
    """The average dice across multiple classes.

    Note: Sigmoid is automatically applied here!
    """

    def __init__(self):
        super(MultiLabelDiceLoss, self).__init__()
        self.dice_loss = SoftDiceLoss()

    def forward(self, logits, targets):
        loss = 0
        num_classes = targets.size(1)
        for class_nr in range(num_classes):
            loss += self.dice_loss(logits[:, class_nr, :, :], targets[:,
                class_nr, :, :])
        return loss / num_classes


class ComboLoss(nn.Module):
    """Weighted classification and segmentation loss.

    Attributes:
        weights (list):
        activation:
        bce: with logits loss
        dice_loss: soft dice loss (all classes)

    """

    def __init__(self, weights=[0.1, 0, 1], activation=None):
        """
        Args:
            weights (list): [image_cls, pixel_seg, pixel_cls]
            activation: One of ['sigmoid', None]
        """
        super(ComboLoss, self).__init__()
        self.weights = weights
        self.activation = activation
        assert self.activation in ['sigmoid', None
            ], "`activation` must be one of ['sigmoid', None]."
        self.bce = nn.BCEWithLogitsLoss(reduce=True)
        self.dice_loss = MultiLabelDiceLoss()

    def create_fc_tensors(self, logits, targets):
        """Creates the classification tensors from the segmentation ones.
        """
        batch_size, num_classes, _, _ = targets.shape
        summed = targets.view(batch_size, num_classes, -1).sum(-1)
        targets_fc = (summed > 0).float()
        logits_fc = logits.view(batch_size, num_classes, -1)
        logits_fc = torch.max(logits_fc, -1)[0]
        return logits_fc, targets_fc

    def forward(self, logits, targets):
        logits_fc, targets_fc = self.create_fc_tensors(logits, targets)
        p = torch.sigmoid(logits) if self.activation == 'sigmoid' else logits
        if self.weights[0]:
            loss_fc = self.weights[0] * self.bce(logits_fc, targets_fc)
        else:
            loss_fc = torch.tensor(0)
        if self.weights[1] or self.weights[2]:
            loss_seg_dice = self.weights[1] * self.dice_loss(p, targets)
            loss_seg_bce = self.weights[2] * self.bce(logits, targets)
        else:
            loss_seg_dice = torch.tensor(0)
            loss_seg_bce = torch.tensor(0)
        loss = loss_fc + loss_seg_bce + loss_seg_dice
        return loss


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


def get_init_inputs():
    return [[], {}]

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 libdevice, 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


@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, float('-inf'))
    tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_per_fused_sum_1(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2(in_ptr0,
    in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    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 + r0, None)
    tmp6 = tl.load(in_ptr1 + r0, None)
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = tmp2.to(tl.float32)
    tmp4 = 1.0
    tmp5 = tmp4 - tmp3
    tmp7 = tmp5 * tmp6
    tmp8 = triton_helpers.minimum(tmp1, tmp6)
    tmp9 = tl_math.abs(tmp6)
    tmp10 = -tmp9
    tmp11 = tl_math.exp(tmp10)
    tmp12 = libdevice.log1p(tmp11)
    tmp13 = tmp8 - tmp12
    tmp14 = tmp7 - tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp17, None)


@triton.jit
def triton_per_fused_binary_cross_entropy_with_logits_3(in_ptr0, in_ptr1,
    out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp3 = tl.load(in_ptr1 + r0, None)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tmp2 * tmp3
    tmp5 = 0.0
    tmp6 = triton_helpers.minimum(tmp5, tmp3)
    tmp7 = tl_math.abs(tmp3)
    tmp8 = -tmp7
    tmp9 = tl_math.exp(tmp8)
    tmp10 = libdevice.log1p(tmp9)
    tmp11 = tmp6 - tmp10
    tmp12 = tmp4 - tmp11
    tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
    tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp15, None)


@triton.jit
def triton_per_fused_mul_sum_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp7, xmask)
    tl.store(out_ptr1 + x0, tmp11, xmask)
    tl.store(out_ptr2 + x0, tmp15, xmask)


@triton.jit
def triton_per_fused_mul_sum_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (16 + r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp7, xmask)
    tl.store(out_ptr1 + x0, tmp11, xmask)
    tl.store(out_ptr2 + x0, tmp15, xmask)


@triton.jit
def triton_per_fused_mul_sum_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (32 + r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp7, xmask)
    tl.store(out_ptr1 + x0, tmp11, xmask)
    tl.store(out_ptr2 + x0, tmp15, xmask)


@triton.jit
def triton_per_fused_mul_sum_7(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tl.load(in_ptr1 + (48 + r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.sigmoid(tmp0)
    tmp3 = tmp1 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp14 = tl.where(xmask, tmp12, 0)
    tmp15 = tl.sum(tmp14, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp7, xmask)
    tl.store(out_ptr1 + x0, tmp11, xmask)
    tl.store(out_ptr2 + x0, tmp15, xmask)


@triton.jit
def triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5,
    in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, in_ptr12,
    in_ptr13, 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 + r0, None)
    tmp5 = tl.load(in_ptr1 + r0, None)
    tmp6 = tl.load(in_ptr2 + r0, None)
    tmp15 = tl.load(in_ptr3 + r0, None)
    tmp18 = tl.load(in_ptr4 + r0, None)
    tmp19 = tl.load(in_ptr5 + r0, None)
    tmp27 = tl.load(in_ptr6 + r0, None)
    tmp30 = tl.load(in_ptr7 + r0, None)
    tmp31 = tl.load(in_ptr8 + r0, None)
    tmp39 = tl.load(in_ptr9 + r0, None)
    tmp42 = tl.load(in_ptr10 + r0, None)
    tmp43 = tl.load(in_ptr11 + r0, None)
    tmp51 = tl.load(in_ptr12 + 0)
    tmp52 = tl.broadcast_to(tmp51, [XBLOCK, 1])
    tmp57 = tl.load(in_ptr13 + 0)
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK, 1])
    tmp1 = 2.0
    tmp2 = tmp0 * tmp1
    tmp3 = 1e-09
    tmp4 = tmp2 + tmp3
    tmp7 = tmp5 + tmp6
    tmp8 = tmp7 + tmp3
    tmp9 = tmp4 / tmp8
    tmp10 = 1.0
    tmp11 = tmp10 - tmp9
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp14 = tl.sum(tmp12, 1)[:, None]
    tmp16 = tmp15 * tmp1
    tmp17 = tmp16 + tmp3
    tmp20 = tmp18 + tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tmp17 / tmp21
    tmp23 = tmp10 - tmp22
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
    tmp26 = tl.sum(tmp24, 1)[:, None]
    tmp28 = tmp27 * tmp1
    tmp29 = tmp28 + tmp3
    tmp32 = tmp30 + tmp31
    tmp33 = tmp32 + tmp3
    tmp34 = tmp29 / tmp33
    tmp35 = tmp10 - tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp40 = tmp39 * tmp1
    tmp41 = tmp40 + tmp3
    tmp44 = tmp42 + tmp43
    tmp45 = tmp44 + tmp3
    tmp46 = tmp41 / tmp45
    tmp47 = tmp10 - tmp46
    tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
    tmp50 = tl.sum(tmp48, 1)[:, None]
    tmp53 = 16.0
    tmp54 = tmp52 / tmp53
    tmp55 = 0.1
    tmp56 = tmp54 * tmp55
    tmp59 = 256.0
    tmp60 = tmp58 / tmp59
    tmp61 = tmp60 * tmp10
    tmp62 = tmp56 + tmp61
    tmp63 = 4.0
    tmp64 = tmp14 / tmp63
    tmp65 = 0.0
    tmp66 = tmp64 + tmp65
    tmp67 = tmp26 / tmp63
    tmp68 = tmp66 + tmp67
    tmp69 = tmp38 / tmp63
    tmp70 = tmp68 + tmp69
    tmp71 = tmp50 / tmp63
    tmp72 = tmp70 + tmp71
    tmp73 = 0.25
    tmp74 = tmp72 * tmp73
    tmp75 = tmp74 * tmp65
    tmp76 = tmp62 + tmp75
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp76, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 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_per_fused_max_0[grid(16)](arg1_1, buf0, 16, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_per_fused_sum_1[grid(16)](arg0_1, buf2, 16, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf3 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused__to_copy_binary_cross_entropy_with_logits_gt_2[grid(1)
            ](buf2, buf0, buf3, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del buf0
        del buf2
        buf4 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_binary_cross_entropy_with_logits_3[grid(1)](arg0_1,
            arg1_1, buf4, 1, 256, num_warps=2, num_stages=1)
        buf5 = empty_strided_cuda((4,), (1,), torch.float32)
        buf6 = empty_strided_cuda((4,), (1,), torch.float32)
        buf7 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_per_fused_mul_sum_4[grid(4)](arg1_1, arg0_1, buf5, buf6,
            buf7, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        buf9 = empty_strided_cuda((4,), (1,), torch.float32)
        buf10 = empty_strided_cuda((4,), (1,), torch.float32)
        buf11 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_per_fused_mul_sum_5[grid(4)](arg1_1, arg0_1, buf9, buf10,
            buf11, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        buf13 = empty_strided_cuda((4,), (1,), torch.float32)
        buf14 = empty_strided_cuda((4,), (1,), torch.float32)
        buf15 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_per_fused_mul_sum_6[grid(4)](arg1_1, arg0_1, buf13, buf14,
            buf15, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        buf17 = empty_strided_cuda((4,), (1,), torch.float32)
        buf18 = empty_strided_cuda((4,), (1,), torch.float32)
        buf19 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_per_fused_mul_sum_7[grid(4)](arg1_1, arg0_1, buf17, buf18,
            buf19, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        buf12 = empty_strided_cuda((), (), torch.float32)
        buf21 = buf12
        del buf12
        triton_per_fused__to_copy_add_binary_cross_entropy_with_logits_div_gt_mean_mul_rsub_8[
            grid(1)](buf21, buf5, buf6, buf7, buf9, buf10, buf11, buf13,
            buf14, buf15, buf17, buf18, buf19, buf3, buf4, 1, 4, XBLOCK=1,
            num_warps=2, num_stages=1)
        del buf10
        del buf11
        del buf13
        del buf14
        del buf15
        del buf17
        del buf18
        del buf19
        del buf3
        del buf4
        del buf5
        del buf6
        del buf7
        del buf9
    return buf21,


class SoftDiceLoss(nn.Module):
    """Differentiable soft dice loss.

    Note: Sigmoid is automatically applied here!
    """

    def __init__(self):
        super(SoftDiceLoss, self).__init__()

    def forward(self, logits, targets):
        eps = 1e-09
        num = targets.size(0)
        probs = torch.sigmoid(logits)
        m1 = probs.view(num, -1)
        m2 = targets.view(num, -1).float()
        intersection = torch.sum(m1 * m2, 1)
        union = torch.sum(m1, dim=1) + torch.sum(m2, dim=1)
        score = (2 * intersection + eps) / (union + eps)
        score = (1 - score).mean()
        return score


class MultiLabelDiceLoss(nn.Module):
    """The average dice across multiple classes.

    Note: Sigmoid is automatically applied here!
    """

    def __init__(self):
        super(MultiLabelDiceLoss, self).__init__()
        self.dice_loss = SoftDiceLoss()

    def forward(self, logits, targets):
        loss = 0
        num_classes = targets.size(1)
        for class_nr in range(num_classes):
            loss += self.dice_loss(logits[:, class_nr, :, :], targets[:,
                class_nr, :, :])
        return loss / num_classes


class ComboLossNew(nn.Module):
    """Weighted classification and segmentation loss.

    Attributes:
        weights (list):
        activation:
        bce: with logits loss
        dice_loss: soft dice loss (all classes)

    """

    def __init__(self, weights=[0.1, 0, 1], activation=None):
        """
        Args:
            weights (list): [image_cls, pixel_seg, pixel_cls]
            activation: One of ['sigmoid', None]
        """
        super(ComboLossNew, self).__init__()
        self.weights = weights
        self.activation = activation
        assert self.activation in ['sigmoid', None
            ], "`activation` must be one of ['sigmoid', None]."
        self.bce = nn.BCEWithLogitsLoss(reduce=True)
        self.dice_loss = MultiLabelDiceLoss()

    def create_fc_tensors(self, logits, targets):
        """Creates the classification tensors from the segmentation ones.
        """
        batch_size, num_classes, _, _ = targets.shape
        summed = targets.view(batch_size, num_classes, -1).sum(-1)
        targets_fc = (summed > 0).float()
        logits_fc = logits.view(batch_size, num_classes, -1)
        logits_fc = torch.max(logits_fc, -1)[0]
        return logits_fc, targets_fc

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