# 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/fn/cfnbjifotifsbkjqwcrjvmwysi2u65kyzrt5izbv7n7pgfrnvakl.py
# Topologically Sorted Source Nodes: [mask, sub, positive_weighting, mul, sub_2, mul_1, sub_1, add, negative_weighting, mul_2, sub_3, sub_4, mul_3, logits, loss], Original ATen: [aten.scatter, aten.rsub, aten.clamp, aten.mul, aten.sub, aten.add, aten.where, aten._log_softmax]
# Source node to ATen node mapping:
#   add => add
#   logits => where
#   loss => amax, exp, sub_5, sum_1
#   mask => scatter_upon_const_tensor
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   mul_3 => mul_3
#   negative_weighting => clamp_min_1
#   positive_weighting => clamp_min
#   sub => sub
#   sub_1 => sub_1
#   sub_2 => sub_2
#   sub_3 => sub_3
#   sub_4 => sub_4
# Graph fragment:
#   %scatter_upon_const_tensor : [num_users=1] = call_function[target=torch._inductor.fx_passes.post_grad.scatter_upon_const_tensor](args = (), kwargs = {shape: [4, 4], background_val: False, dtype: torch.bool, dim: 1, selector: %unsqueeze, val: 1})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.25, %arg0_1), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub, 0), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%clamp_min, 256.0), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0.75), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %sub_2), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_1, 0.25), kwargs = {})
#   %clamp_min_1 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add, 0), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%clamp_min_1, 256.0), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_3, 0.25), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_2, %sub_4), kwargs = {})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%scatter_upon_const_tensor, %mul_1, %mul_3), kwargs = {})
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%where, [1], True), kwargs = {})
#   %sub_5 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%where, %amax), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_5,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_0 = async_compile.triton('triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_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=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*i64', 1: '*i64', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_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__log_softmax_add_clamp_mul_rsub_scatter_sub_where_0(in_ptr0, in_ptr1, out_ptr0, out_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 + (x0), xmask)
    tmp6 = tl.load(in_ptr1 + (4*x0), xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr1 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp48 = tl.load(in_ptr1 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp67 = tl.load(in_ptr1 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 == tmp1
    tmp3 = tl.full([1], True, tl.int1)
    tmp4 = tl.full([1], False, tl.int1)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 1.25
    tmp9 = tmp8 - tmp7
    tmp10 = 0.0
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = 256.0
    tmp13 = tmp11 * tmp12
    tmp14 = 0.75
    tmp15 = tmp7 - tmp14
    tmp16 = tmp13 * tmp15
    tmp17 = tmp6 - tmp1
    tmp18 = tmp17.to(tl.float32)
    tmp19 = 0.25
    tmp20 = tmp18 + tmp19
    tmp21 = triton_helpers.maximum(tmp20, tmp10)
    tmp22 = tmp21 * tmp12
    tmp23 = tmp18 - tmp19
    tmp24 = tmp22 * tmp23
    tmp25 = tl.where(tmp5, tmp16, tmp24)
    tmp26 = tl.full([1], 1, tl.int64)
    tmp27 = tmp0 == tmp26
    tmp28 = tl.where(tmp27, tmp3, tmp4)
    tmp30 = tmp29.to(tl.float32)
    tmp31 = tmp8 - tmp30
    tmp32 = triton_helpers.maximum(tmp31, tmp10)
    tmp33 = tmp32 * tmp12
    tmp34 = tmp30 - tmp14
    tmp35 = tmp33 * tmp34
    tmp36 = tmp29 - tmp1
    tmp37 = tmp36.to(tl.float32)
    tmp38 = tmp37 + tmp19
    tmp39 = triton_helpers.maximum(tmp38, tmp10)
    tmp40 = tmp39 * tmp12
    tmp41 = tmp37 - tmp19
    tmp42 = tmp40 * tmp41
    tmp43 = tl.where(tmp28, tmp35, tmp42)
    tmp44 = triton_helpers.maximum(tmp25, tmp43)
    tmp45 = tl.full([1], 2, tl.int64)
    tmp46 = tmp0 == tmp45
    tmp47 = tl.where(tmp46, tmp3, tmp4)
    tmp49 = tmp48.to(tl.float32)
    tmp50 = tmp8 - tmp49
    tmp51 = triton_helpers.maximum(tmp50, tmp10)
    tmp52 = tmp51 * tmp12
    tmp53 = tmp49 - tmp14
    tmp54 = tmp52 * tmp53
    tmp55 = tmp48 - tmp1
    tmp56 = tmp55.to(tl.float32)
    tmp57 = tmp56 + tmp19
    tmp58 = triton_helpers.maximum(tmp57, tmp10)
    tmp59 = tmp58 * tmp12
    tmp60 = tmp56 - tmp19
    tmp61 = tmp59 * tmp60
    tmp62 = tl.where(tmp47, tmp54, tmp61)
    tmp63 = triton_helpers.maximum(tmp44, tmp62)
    tmp64 = tl.full([1], 3, tl.int64)
    tmp65 = tmp0 == tmp64
    tmp66 = tl.where(tmp65, tmp3, tmp4)
    tmp68 = tmp67.to(tl.float32)
    tmp69 = tmp8 - tmp68
    tmp70 = triton_helpers.maximum(tmp69, tmp10)
    tmp71 = tmp70 * tmp12
    tmp72 = tmp68 - tmp14
    tmp73 = tmp71 * tmp72
    tmp74 = tmp67 - tmp1
    tmp75 = tmp74.to(tl.float32)
    tmp76 = tmp75 + tmp19
    tmp77 = triton_helpers.maximum(tmp76, tmp10)
    tmp78 = tmp77 * tmp12
    tmp79 = tmp75 - tmp19
    tmp80 = tmp78 * tmp79
    tmp81 = tl.where(tmp66, tmp73, tmp80)
    tmp82 = triton_helpers.maximum(tmp63, tmp81)
    tmp83 = tmp25 - tmp82
    tmp84 = tl_math.exp(tmp83)
    tmp85 = tmp43 - tmp82
    tmp86 = tl_math.exp(tmp85)
    tmp87 = tmp84 + tmp86
    tmp88 = tmp62 - tmp82
    tmp89 = tl_math.exp(tmp88)
    tmp90 = tmp87 + tmp89
    tmp91 = tmp81 - tmp82
    tmp92 = tl_math.exp(tmp91)
    tmp93 = tmp90 + tmp92
    tl.store(out_ptr0 + (x0), tmp82, xmask)
    tl.store(out_ptr1 + (x0), tmp93, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/f7/cf76gdye3s6mqx3jjsxgcjijmfytmkiiff5dl6dyksihxbvh3muu.py
# Topologically Sorted Source Nodes: [mask, sub, positive_weighting, mul, sub_2, mul_1, sub_1, add, negative_weighting, mul_2, sub_3, sub_4, mul_3, logits, loss], Original ATen: [aten.scatter, aten.rsub, aten.clamp, aten.mul, aten.sub, aten.add, aten.where, aten._log_softmax]
# Source node to ATen node mapping:
#   add => add
#   logits => where
#   loss => log, sub_5, sub_6
#   mask => scatter_upon_const_tensor
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   mul_3 => mul_3
#   negative_weighting => clamp_min_1
#   positive_weighting => clamp_min
#   sub => sub
#   sub_1 => sub_1
#   sub_2 => sub_2
#   sub_3 => sub_3
#   sub_4 => sub_4
# Graph fragment:
#   %scatter_upon_const_tensor : [num_users=1] = call_function[target=torch._inductor.fx_passes.post_grad.scatter_upon_const_tensor](args = (), kwargs = {shape: [4, 4], background_val: False, dtype: torch.bool, dim: 1, selector: %unsqueeze, val: 1})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.25, %arg0_1), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub, 0), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%clamp_min, 256.0), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0.75), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %sub_2), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_1, 0.25), kwargs = {})
#   %clamp_min_1 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add, 0), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%clamp_min_1, 256.0), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, 0), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_3, 0.25), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_2, %sub_4), kwargs = {})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%scatter_upon_const_tensor, %mul_1, %mul_3), kwargs = {})
#   %sub_5 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%where, %amax), kwargs = {})
#   %log : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_1,), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_5, %log), kwargs = {})
triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1 = async_compile.triton('triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_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: '*i64', 1: '*i64', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, '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__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (x2), xmask)
    tmp27 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr3 + (x1), xmask, eviction_policy='evict_last')
    tmp1 = x0
    tmp2 = tmp0 == tmp1
    tmp3 = tl.full([1], True, tl.int1)
    tmp4 = tl.full([1], False, tl.int1)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 1.25
    tmp9 = tmp8 - tmp7
    tmp10 = 0.0
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = 256.0
    tmp13 = tmp11 * tmp12
    tmp14 = 0.75
    tmp15 = tmp7 - tmp14
    tmp16 = tmp13 * tmp15
    tmp17 = tl.full([1], 0, tl.int64)
    tmp18 = tmp6 - tmp17
    tmp19 = tmp18.to(tl.float32)
    tmp20 = 0.25
    tmp21 = tmp19 + tmp20
    tmp22 = triton_helpers.maximum(tmp21, tmp10)
    tmp23 = tmp22 * tmp12
    tmp24 = tmp19 - tmp20
    tmp25 = tmp23 * tmp24
    tmp26 = tl.where(tmp5, tmp16, tmp25)
    tmp28 = tmp26 - tmp27
    tmp30 = tl_math.log(tmp29)
    tmp31 = tmp28 - tmp30
    tl.store(out_ptr0 + (x2), tmp31, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/bz/cbzq7t26pihe3ec3rnmx4wscu3agefng6kzj2qs5lh462cc5t6ij.py
# Topologically Sorted Source Nodes: [loss], Original ATen: [aten.nll_loss_forward]
# Source node to ATen node mapping:
#   loss => convert_element_type, div, full_default_2, ne_1, ne_2, neg, sum_2, sum_3, where_2
# Graph fragment:
#   %ne_1 : [num_users=1] = call_function[target=torch.ops.aten.ne.Scalar](args = (%arg1_1, -100), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%squeeze,), kwargs = {})
#   %full_default_2 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where_2 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%ne_1, %neg, %full_default_2), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%where_2,), kwargs = {})
#   %ne_2 : [num_users=1] = call_function[target=torch.ops.aten.ne.Scalar](args = (%arg1_1, -100), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%ne_2,), kwargs = {})
#   %convert_element_type : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%sum_2, torch.float32), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_3, %convert_element_type), kwargs = {})
triton_per_fused_nll_loss_forward_2 = async_compile.triton('triton_per_fused_nll_loss_forward_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, 4],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i64', 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), equal_to_1=(3,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_nll_loss_forward_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 2, '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_nll_loss_forward_2(in_out_ptr0, in_ptr0, in_ptr1, 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)
    tmp1 = tl.full([1, 1], -100, tl.int64)
    tmp2 = tmp0 != tmp1
    tmp3 = tl.full([1, 1], 0, tl.int64)
    tmp4 = tl.where(tmp2, tmp0, tmp3)
    tmp5 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp6 = tmp4 + tmp5
    tmp7 = tmp4 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp4)
    tl.device_assert((0 <= tmp8) & (tmp8 < 4), "index out of bounds: 0 <= tmp8 < 4")
    tmp10 = tl.load(in_ptr1 + (tmp8 + (4*r0)), None, eviction_policy='evict_last')
    tmp11 = -tmp10
    tmp12 = 0.0
    tmp13 = tl.where(tmp2, tmp11, tmp12)
    tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp16 = tl.sum(tmp14, 1)[:, None]
    tmp17 = tmp2.to(tl.int64)
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
    tmp20 = tl.sum(tmp18, 1)[:, None]
    tmp21 = tmp20.to(tl.float32)
    tmp22 = tmp16 / tmp21
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp22, 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, 1))
    assert_size_stride(arg1_1, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        # Topologically Sorted Source Nodes: [mask, sub, positive_weighting, mul, sub_2, mul_1, sub_1, add, negative_weighting, mul_2, sub_3, sub_4, mul_3, logits, loss], Original ATen: [aten.scatter, aten.rsub, aten.clamp, aten.mul, aten.sub, aten.add, aten.where, aten._log_softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_0.run(arg1_1, arg0_1, buf0, buf1, 4, grid=grid(4), stream=stream0)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mask, sub, positive_weighting, mul, sub_2, mul_1, sub_1, add, negative_weighting, mul_2, sub_3, sub_4, mul_3, logits, loss], Original ATen: [aten.scatter, aten.rsub, aten.clamp, aten.mul, aten.sub, aten.add, aten.where, aten._log_softmax]
        triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1.run(arg1_1, arg0_1, buf0, buf1, buf2, 16, grid=grid(16), stream=stream0)
        del arg0_1
        del buf0
        del buf1
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf3; del buf3  # reuse
        # Topologically Sorted Source Nodes: [loss], Original ATen: [aten.nll_loss_forward]
        triton_per_fused_nll_loss_forward_2.run(buf5, arg1_1, buf2, 1, 4, grid=grid(1), stream=stream0)
        del arg1_1
        del buf2
    return (buf5, )


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.int64)
    arg1_1 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.int64)
    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
import torch.utils.data
from typing import Tuple
from torch.nn.functional import cross_entropy
from itertools import product as product
from math import sqrt as sqrt


class ClassificationCircleLoss(nn.Module):
    """Circle loss for class-level labels as described in the paper
    `"Circle Loss: A Unified Perspective of Pair Similarity Optimization" <#>`_

    Args:
        scale (float): the scale factor. Default: 256.0
        margin (float): the relax margin value. Default: 0.25
        circle_center (tuple[float]): the center of the circle (logit_ap, logit_an). Default: (1, 0)
        reduction (string, optional): Specifies the reduction to apply to the output:
            ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction will be applied,
            ``'mean'``: the sum of the output will be divided by the number of
            elements in the output, ``'sum'``: the output will be summed. Default: ``'mean'``
    """

    def __init__(self, scale: 'float'=256.0, margin: 'float'=0.25,
        circle_center: 'Tuple[float, float]'=(1, 0), reduction: 'str'='mean'
        ) ->None:
        super(ClassificationCircleLoss, self).__init__()
        self.scale = scale
        self.margin = margin
        self.circle_center = circle_center
        self.reduction = reduction

    def forward(self, logits: 'torch.Tensor', targets: 'torch.LongTensor'
        ) ->torch.Tensor:
        """

        Args:
            logits (torch.Tensor): The predicted logits before softmax,
                namely :math:`\\cos \\theta` in the above equation, with shape of :math:`(N, C)`
            targets (torch.LongTensor): The ground-truth label long vector,
                namely :math:`y` in the above equation, with shape of :math:`(N,)`

        Returns:
            torch.Tensor: loss
                the computed loss
        """
        mask = torch.zeros(logits.shape, dtype=torch.bool, device=logits.device
            ).scatter_(dim=1, index=targets.unsqueeze(1), value=1)
        positive_weighting = torch.clamp(self.circle_center[0] + self.
            margin - logits.detach(), min=0)
        negative_weighting = torch.clamp(logits.detach() - self.
            circle_center[1] + self.margin, min=0)
        logits = torch.where(mask, self.scale * positive_weighting * (
            logits - (self.circle_center[0] - self.margin)), self.scale *
            negative_weighting * (logits - self.circle_center[1] - self.margin)
            )
        loss = cross_entropy(input=logits, target=targets, reduction=self.
            reduction)
        return loss


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


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 math as tl_math
import torch.nn as nn
import torch.utils.data
from typing import Tuple
from itertools import product as product
from math import sqrt as sqrt
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__log_softmax_add_clamp_mul_rsub_scatter_sub_where_0(
    in_ptr0, in_ptr1, out_ptr0, out_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 + x0, xmask)
    tmp6 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp48 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp67 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 == tmp1
    tmp3 = tl.full([1], True, tl.int1)
    tmp4 = tl.full([1], False, tl.int1)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 1.25
    tmp9 = tmp8 - tmp7
    tmp10 = 0.0
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = 256.0
    tmp13 = tmp11 * tmp12
    tmp14 = 0.75
    tmp15 = tmp7 - tmp14
    tmp16 = tmp13 * tmp15
    tmp17 = tmp6 - tmp1
    tmp18 = tmp17.to(tl.float32)
    tmp19 = 0.25
    tmp20 = tmp18 + tmp19
    tmp21 = triton_helpers.maximum(tmp20, tmp10)
    tmp22 = tmp21 * tmp12
    tmp23 = tmp18 - tmp19
    tmp24 = tmp22 * tmp23
    tmp25 = tl.where(tmp5, tmp16, tmp24)
    tmp26 = tl.full([1], 1, tl.int64)
    tmp27 = tmp0 == tmp26
    tmp28 = tl.where(tmp27, tmp3, tmp4)
    tmp30 = tmp29.to(tl.float32)
    tmp31 = tmp8 - tmp30
    tmp32 = triton_helpers.maximum(tmp31, tmp10)
    tmp33 = tmp32 * tmp12
    tmp34 = tmp30 - tmp14
    tmp35 = tmp33 * tmp34
    tmp36 = tmp29 - tmp1
    tmp37 = tmp36.to(tl.float32)
    tmp38 = tmp37 + tmp19
    tmp39 = triton_helpers.maximum(tmp38, tmp10)
    tmp40 = tmp39 * tmp12
    tmp41 = tmp37 - tmp19
    tmp42 = tmp40 * tmp41
    tmp43 = tl.where(tmp28, tmp35, tmp42)
    tmp44 = triton_helpers.maximum(tmp25, tmp43)
    tmp45 = tl.full([1], 2, tl.int64)
    tmp46 = tmp0 == tmp45
    tmp47 = tl.where(tmp46, tmp3, tmp4)
    tmp49 = tmp48.to(tl.float32)
    tmp50 = tmp8 - tmp49
    tmp51 = triton_helpers.maximum(tmp50, tmp10)
    tmp52 = tmp51 * tmp12
    tmp53 = tmp49 - tmp14
    tmp54 = tmp52 * tmp53
    tmp55 = tmp48 - tmp1
    tmp56 = tmp55.to(tl.float32)
    tmp57 = tmp56 + tmp19
    tmp58 = triton_helpers.maximum(tmp57, tmp10)
    tmp59 = tmp58 * tmp12
    tmp60 = tmp56 - tmp19
    tmp61 = tmp59 * tmp60
    tmp62 = tl.where(tmp47, tmp54, tmp61)
    tmp63 = triton_helpers.maximum(tmp44, tmp62)
    tmp64 = tl.full([1], 3, tl.int64)
    tmp65 = tmp0 == tmp64
    tmp66 = tl.where(tmp65, tmp3, tmp4)
    tmp68 = tmp67.to(tl.float32)
    tmp69 = tmp8 - tmp68
    tmp70 = triton_helpers.maximum(tmp69, tmp10)
    tmp71 = tmp70 * tmp12
    tmp72 = tmp68 - tmp14
    tmp73 = tmp71 * tmp72
    tmp74 = tmp67 - tmp1
    tmp75 = tmp74.to(tl.float32)
    tmp76 = tmp75 + tmp19
    tmp77 = triton_helpers.maximum(tmp76, tmp10)
    tmp78 = tmp77 * tmp12
    tmp79 = tmp75 - tmp19
    tmp80 = tmp78 * tmp79
    tmp81 = tl.where(tmp66, tmp73, tmp80)
    tmp82 = triton_helpers.maximum(tmp63, tmp81)
    tmp83 = tmp25 - tmp82
    tmp84 = tl_math.exp(tmp83)
    tmp85 = tmp43 - tmp82
    tmp86 = tl_math.exp(tmp85)
    tmp87 = tmp84 + tmp86
    tmp88 = tmp62 - tmp82
    tmp89 = tl_math.exp(tmp88)
    tmp90 = tmp87 + tmp89
    tmp91 = tmp81 - tmp82
    tmp92 = tl_math.exp(tmp91)
    tmp93 = tmp90 + tmp92
    tl.store(out_ptr0 + x0, tmp82, xmask)
    tl.store(out_ptr1 + x0, tmp93, xmask)


@triton.jit
def triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1(
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + x2, xmask)
    tmp27 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp1 = x0
    tmp2 = tmp0 == tmp1
    tmp3 = tl.full([1], True, tl.int1)
    tmp4 = tl.full([1], False, tl.int1)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 1.25
    tmp9 = tmp8 - tmp7
    tmp10 = 0.0
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = 256.0
    tmp13 = tmp11 * tmp12
    tmp14 = 0.75
    tmp15 = tmp7 - tmp14
    tmp16 = tmp13 * tmp15
    tmp17 = tl.full([1], 0, tl.int64)
    tmp18 = tmp6 - tmp17
    tmp19 = tmp18.to(tl.float32)
    tmp20 = 0.25
    tmp21 = tmp19 + tmp20
    tmp22 = triton_helpers.maximum(tmp21, tmp10)
    tmp23 = tmp22 * tmp12
    tmp24 = tmp19 - tmp20
    tmp25 = tmp23 * tmp24
    tmp26 = tl.where(tmp5, tmp16, tmp25)
    tmp28 = tmp26 - tmp27
    tmp30 = tl_math.log(tmp29)
    tmp31 = tmp28 - tmp30
    tl.store(out_ptr0 + x2, tmp31, xmask)


@triton.jit
def triton_per_fused_nll_loss_forward_2(in_out_ptr0, in_ptr0, in_ptr1,
    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)
    tmp1 = tl.full([1, 1], -100, tl.int64)
    tmp2 = tmp0 != tmp1
    tmp3 = tl.full([1, 1], 0, tl.int64)
    tmp4 = tl.where(tmp2, tmp0, tmp3)
    tmp5 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp6 = tmp4 + tmp5
    tmp7 = tmp4 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp4)
    tl.device_assert((0 <= tmp8) & (tmp8 < 4),
        'index out of bounds: 0 <= tmp8 < 4')
    tmp10 = tl.load(in_ptr1 + (tmp8 + 4 * r0), None, eviction_policy=
        'evict_last')
    tmp11 = -tmp10
    tmp12 = 0.0
    tmp13 = tl.where(tmp2, tmp11, tmp12)
    tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp16 = tl.sum(tmp14, 1)[:, None]
    tmp17 = tmp2.to(tl.int64)
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
    tmp20 = tl.sum(tmp18, 1)[:, None]
    tmp21 = tmp20.to(tl.float32)
    tmp22 = tmp16 / tmp21
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp22, None)


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,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_0[
            grid(4)](arg1_1, arg0_1, buf0, buf1, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__log_softmax_add_clamp_mul_rsub_scatter_sub_where_1[
            grid(16)](arg1_1, arg0_1, buf0, buf1, buf2, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del arg0_1
        del buf0
        del buf1
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf3
        del buf3
        triton_per_fused_nll_loss_forward_2[grid(1)](buf5, arg1_1, buf2, 1,
            4, XBLOCK=1, num_warps=2, num_stages=1)
        del arg1_1
        del buf2
    return buf5,


class ClassificationCircleLossNew(nn.Module):
    """Circle loss for class-level labels as described in the paper
    `"Circle Loss: A Unified Perspective of Pair Similarity Optimization" <#>`_

    Args:
        scale (float): the scale factor. Default: 256.0
        margin (float): the relax margin value. Default: 0.25
        circle_center (tuple[float]): the center of the circle (logit_ap, logit_an). Default: (1, 0)
        reduction (string, optional): Specifies the reduction to apply to the output:
            ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction will be applied,
            ``'mean'``: the sum of the output will be divided by the number of
            elements in the output, ``'sum'``: the output will be summed. Default: ``'mean'``
    """

    def __init__(self, scale: 'float'=256.0, margin: 'float'=0.25,
        circle_center: 'Tuple[float, float]'=(1, 0), reduction: 'str'='mean'
        ) ->None:
        super(ClassificationCircleLossNew, self).__init__()
        self.scale = scale
        self.margin = margin
        self.circle_center = circle_center
        self.reduction = reduction

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