# 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_8/inductor_cache/ft/cftz5ja4wgrkcx5pv7d7j6lunvnnmz6djadit33a2463r447sayy.py
# Topologically Sorted Source Nodes: [setitem_1], Original ATen: [aten.lift_fresh, aten.fill]
# Source node to ATen node mapping:
#   setitem_1 => copy_1, full_default_2
# Graph fragment:
#   %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})
#   %copy_1 : [num_users=1] = call_function[target=torch.ops.aten.copy.default](args = (%select_2, %full_default_2), kwargs = {})
#   %copy__default : [num_users=0] = call_function[target=torch.ops.aten.copy_.default](args = (%select_int, %copy_1), kwargs = {})
triton_poi_fused_fill_lift_fresh_0 = async_compile.triton('triton_poi_fused_fill_lift_fresh_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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_fill_lift_fresh_0', 'mutated_arg_names': ['out_ptr0'], 'no_x_dim': False, 'num_load': 0, '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_fill_lift_fresh_0(out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = (xindex // 16)
    tmp0 = 0.0
    tl.store(out_ptr0 + (x0 + (64*x1)), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_8/inductor_cache/cn/ccnjm2dqpzcrnbuww2omqd3latcfln56427nk6wxia5xlnc6b5c5.py
# Topologically Sorted Source Nodes: [th_label, setitem, p_mask, sub_1, mul, logit1, log_softmax, n_mask, sub_3, mul_2, logit2, log_softmax_1], Original ATen: [aten.zeros_like, aten.lift_fresh, aten.fill, aten.add, aten.rsub, aten.mul, aten.sub, aten._log_softmax]
# Source node to ATen node mapping:
#   log_softmax => amax, exp, sub_3, sum_1
#   log_softmax_1 => amax_1, exp_1, sub_7, sum_3
#   logit1 => sub_2
#   logit2 => sub_6
#   mul => mul
#   mul_2 => mul_2
#   n_mask => sub
#   p_mask => add
#   setitem => copy, full_default_1
#   sub_1 => sub_1
#   sub_3 => sub_5
#   th_label => full_default
# Graph fragment:
#   %full_default : [num_users=2] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4, 4], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 1.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %copy : [num_users=1] = call_function[target=torch.ops.aten.copy.default](args = (%select, %full_default_1), kwargs = {})
#   %select_scatter_default : [num_users=2] = call_function[target=torch.ops.aten.select_scatter.default](args = (%full_default, %copy, 1, 0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%arg0_1, %select_scatter_default), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %add), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, 1e+30), kwargs = {})
#   %sub_2 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg1_1, %mul), kwargs = {})
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%sub_2, [-1], True), kwargs = {})
#   %sub_3 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_2, %amax), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_3,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [-1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %sub), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, 1e+30), kwargs = {})
#   %sub_6 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg1_1, %mul_2), kwargs = {})
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%sub_6, [-1], True), kwargs = {})
#   %sub_7 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_6, %amax_1), kwargs = {})
#   %exp_1 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_7,), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_1, [-1], True), kwargs = {})
triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1 = async_compile.triton('triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 8, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = (xindex // 4) % 4
    tmp0 = tl.load(in_ptr0 + (4*x3), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (4*x3), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr0 + (1 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr1 + (1 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (2 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp21 = tl.load(in_ptr1 + (2 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr0 + (3 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr1 + (3 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp2 = x1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = tmp2 == tmp3
    tmp5 = 1.0
    tmp6 = 0.0
    tmp7 = tl.where(tmp4, tmp5, tmp6)
    tmp8 = tmp1 + tmp7
    tmp9 = tmp5 - tmp8
    tmp10 = 1e+30
    tmp11 = tmp9 * tmp10
    tmp12 = tmp0 - tmp11
    tmp15 = tmp14 + tmp7
    tmp16 = tmp5 - tmp15
    tmp17 = tmp16 * tmp10
    tmp18 = tmp13 - tmp17
    tmp19 = triton_helpers.maximum(tmp12, tmp18)
    tmp22 = tmp21 + tmp7
    tmp23 = tmp5 - tmp22
    tmp24 = tmp23 * tmp10
    tmp25 = tmp20 - tmp24
    tmp26 = triton_helpers.maximum(tmp19, tmp25)
    tmp29 = tmp28 + tmp7
    tmp30 = tmp5 - tmp29
    tmp31 = tmp30 * tmp10
    tmp32 = tmp27 - tmp31
    tmp33 = triton_helpers.maximum(tmp26, tmp32)
    tmp34 = tmp12 - tmp33
    tmp35 = tl_math.exp(tmp34)
    tmp36 = tmp18 - tmp33
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp25 - tmp33
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tmp42 = tmp32 - tmp33
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp41 + tmp43
    tmp45 = tmp5 - tmp1
    tmp46 = tmp5 - tmp45
    tmp47 = tmp46 * tmp10
    tmp48 = tmp0 - tmp47
    tmp49 = tmp5 - tmp14
    tmp50 = tmp5 - tmp49
    tmp51 = tmp50 * tmp10
    tmp52 = tmp13 - tmp51
    tmp53 = triton_helpers.maximum(tmp48, tmp52)
    tmp54 = tmp5 - tmp21
    tmp55 = tmp5 - tmp54
    tmp56 = tmp55 * tmp10
    tmp57 = tmp20 - tmp56
    tmp58 = triton_helpers.maximum(tmp53, tmp57)
    tmp59 = tmp5 - tmp28
    tmp60 = tmp5 - tmp59
    tmp61 = tmp60 * tmp10
    tmp62 = tmp27 - tmp61
    tmp63 = triton_helpers.maximum(tmp58, tmp62)
    tmp64 = tmp48 - tmp63
    tmp65 = tl_math.exp(tmp64)
    tmp66 = tmp52 - tmp63
    tmp67 = tl_math.exp(tmp66)
    tmp68 = tmp65 + tmp67
    tmp69 = tmp57 - tmp63
    tmp70 = tl_math.exp(tmp69)
    tmp71 = tmp68 + tmp70
    tmp72 = tmp62 - tmp63
    tmp73 = tl_math.exp(tmp72)
    tmp74 = tmp71 + tmp73
    tl.store(out_ptr0 + (x3), tmp33, xmask)
    tl.store(out_ptr1 + (x3), tmp44, xmask)
    tl.store(out_ptr2 + (x3), tmp63, xmask)
    tl.store(out_ptr3 + (x3), tmp74, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_8/inductor_cache/uj/cuj4drsaoeeafppqq56jc2dqbimn76sbovf5a42dyfiev4rt56n7.py
# Topologically Sorted Source Nodes: [th_label, setitem, p_mask, sub_1, mul, logit1, log_softmax, mul_1, sum_1, loss1, n_mask, sub_3, mul_2, logit2, log_softmax_1, mul_3, sum_2, loss2, loss, loss_1], Original ATen: [aten.zeros_like, aten.lift_fresh, aten.fill, aten.add, aten.rsub, aten.mul, aten.sub, aten._log_softmax, aten.sum, aten.neg, aten.mean]
# Source node to ATen node mapping:
#   log_softmax => log, sub_3, sub_4
#   log_softmax_1 => amax_1, log_1, sub_7, sub_8
#   logit1 => sub_2
#   logit2 => sub_6
#   loss => add_1
#   loss1 => neg
#   loss2 => neg_1
#   loss_1 => mean
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   mul_3 => mul_3
#   n_mask => sub
#   p_mask => add
#   setitem => copy, full_default_1
#   sub_1 => sub_1
#   sub_3 => sub_5
#   sum_1 => sum_2
#   sum_2 => sum_4
#   th_label => full_default
# Graph fragment:
#   %full_default : [num_users=2] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4, 4], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 1.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %copy : [num_users=1] = call_function[target=torch.ops.aten.copy.default](args = (%select, %full_default_1), kwargs = {})
#   %select_scatter_default : [num_users=2] = call_function[target=torch.ops.aten.select_scatter.default](args = (%full_default, %copy, 1, 0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%arg0_1, %select_scatter_default), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %add), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, 1e+30), kwargs = {})
#   %sub_2 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg1_1, %mul), kwargs = {})
#   %sub_3 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_2, %amax), kwargs = {})
#   %log : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_1,), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_3, %log), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_4, %arg0_1), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_1, [1]), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%sum_2,), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %sub), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, 1e+30), kwargs = {})
#   %sub_6 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg1_1, %mul_2), kwargs = {})
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%sub_6, [-1], True), kwargs = {})
#   %sub_7 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_6, %amax_1), kwargs = {})
#   %log_1 : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_3,), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_7, %log_1), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_8, %select_scatter_default), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_3, [1]), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%sum_4,), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%neg, %neg_1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%add_1,), kwargs = {})
triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2 = async_compile.triton('triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_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, 64],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: 'i32', 8: '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': {7: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 8), equal_to_1=(7,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 24, '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__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 64
    RBLOCK: tl.constexpr = 64
    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)
    r2 = (rindex // 16)
    r4 = rindex % 16
    r1 = (rindex // 4) % 4
    r3 = rindex
    tmp0 = tl.load(in_ptr0 + (r4 + (64*r2)), None)
    tmp1 = tl.load(in_ptr1 + (r4 + (64*r2)), None)
    tmp12 = tl.load(in_ptr2 + (r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr3 + (r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (16 + r4 + (64*r2)), None)
    tmp19 = tl.load(in_ptr1 + (16 + r4 + (64*r2)), None)
    tmp27 = tl.load(in_ptr2 + (4 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr3 + (4 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp34 = tl.load(in_ptr0 + (32 + r4 + (64*r2)), None)
    tmp35 = tl.load(in_ptr1 + (32 + r4 + (64*r2)), None)
    tmp43 = tl.load(in_ptr2 + (8 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp45 = tl.load(in_ptr3 + (8 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp50 = tl.load(in_ptr0 + (48 + r4 + (64*r2)), None)
    tmp51 = tl.load(in_ptr1 + (48 + r4 + (64*r2)), None)
    tmp59 = tl.load(in_ptr2 + (12 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp61 = tl.load(in_ptr3 + (12 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp70 = tl.load(in_ptr4 + (r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr5 + (r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp80 = tl.load(in_ptr4 + (4 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp82 = tl.load(in_ptr5 + (4 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp91 = tl.load(in_ptr4 + (8 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp93 = tl.load(in_ptr5 + (8 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp102 = tl.load(in_ptr4 + (12 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp104 = tl.load(in_ptr5 + (12 + r1 + (16*r2)), None, eviction_policy='evict_last')
    tmp2 = tl.full([1, 1], 0, tl.int32)
    tmp3 = tmp2 == tmp2
    tmp4 = 1.0
    tmp5 = 0.0
    tmp6 = tl.where(tmp3, tmp4, tmp5)
    tmp7 = tmp1 + tmp6
    tmp8 = tmp4 - tmp7
    tmp9 = 1e+30
    tmp10 = tmp8 * tmp9
    tmp11 = tmp0 - tmp10
    tmp13 = tmp11 - tmp12
    tmp15 = tl_math.log(tmp14)
    tmp16 = tmp13 - tmp15
    tmp17 = tmp16 * tmp1
    tmp20 = tl.full([1, 1], 1, tl.int32)
    tmp21 = tmp20 == tmp2
    tmp22 = tl.where(tmp21, tmp4, tmp5)
    tmp23 = tmp19 + tmp22
    tmp24 = tmp4 - tmp23
    tmp25 = tmp24 * tmp9
    tmp26 = tmp18 - tmp25
    tmp28 = tmp26 - tmp27
    tmp30 = tl_math.log(tmp29)
    tmp31 = tmp28 - tmp30
    tmp32 = tmp31 * tmp19
    tmp33 = tmp17 + tmp32
    tmp36 = tl.full([1, 1], 2, tl.int32)
    tmp37 = tmp36 == tmp2
    tmp38 = tl.where(tmp37, tmp4, tmp5)
    tmp39 = tmp35 + tmp38
    tmp40 = tmp4 - tmp39
    tmp41 = tmp40 * tmp9
    tmp42 = tmp34 - tmp41
    tmp44 = tmp42 - tmp43
    tmp46 = tl_math.log(tmp45)
    tmp47 = tmp44 - tmp46
    tmp48 = tmp47 * tmp35
    tmp49 = tmp33 + tmp48
    tmp52 = tl.full([1, 1], 3, tl.int32)
    tmp53 = tmp52 == tmp2
    tmp54 = tl.where(tmp53, tmp4, tmp5)
    tmp55 = tmp51 + tmp54
    tmp56 = tmp4 - tmp55
    tmp57 = tmp56 * tmp9
    tmp58 = tmp50 - tmp57
    tmp60 = tmp58 - tmp59
    tmp62 = tl_math.log(tmp61)
    tmp63 = tmp60 - tmp62
    tmp64 = tmp63 * tmp51
    tmp65 = tmp49 + tmp64
    tmp66 = tmp4 - tmp1
    tmp67 = tmp4 - tmp66
    tmp68 = tmp67 * tmp9
    tmp69 = tmp0 - tmp68
    tmp71 = tmp69 - tmp70
    tmp73 = tl_math.log(tmp72)
    tmp74 = tmp71 - tmp73
    tmp75 = tmp74 * tmp6
    tmp76 = tmp4 - tmp19
    tmp77 = tmp4 - tmp76
    tmp78 = tmp77 * tmp9
    tmp79 = tmp18 - tmp78
    tmp81 = tmp79 - tmp80
    tmp83 = tl_math.log(tmp82)
    tmp84 = tmp81 - tmp83
    tmp85 = tmp84 * tmp22
    tmp86 = tmp75 + tmp85
    tmp87 = tmp4 - tmp35
    tmp88 = tmp4 - tmp87
    tmp89 = tmp88 * tmp9
    tmp90 = tmp34 - tmp89
    tmp92 = tmp90 - tmp91
    tmp94 = tl_math.log(tmp93)
    tmp95 = tmp92 - tmp94
    tmp96 = tmp95 * tmp38
    tmp97 = tmp86 + tmp96
    tmp98 = tmp4 - tmp51
    tmp99 = tmp4 - tmp98
    tmp100 = tmp99 * tmp9
    tmp101 = tmp50 - tmp100
    tmp103 = tmp101 - tmp102
    tmp105 = tl_math.log(tmp104)
    tmp106 = tmp103 - tmp105
    tmp107 = tmp106 * tmp54
    tmp108 = tmp97 + tmp107
    tmp109 = -tmp65
    tmp110 = -tmp108
    tmp111 = tmp109 + tmp110
    tmp112 = tl.broadcast_to(tmp111, [XBLOCK, RBLOCK])
    tmp114 = tl.sum(tmp112, 1)[:, None]
    tmp115 = 64.0
    tmp116 = tmp114 / tmp115
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp116, 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)
        # Topologically Sorted Source Nodes: [setitem_1], Original ATen: [aten.lift_fresh, aten.fill]
        stream0 = get_raw_stream(0)
        triton_poi_fused_fill_lift_fresh_0.run(arg0_1, 64, grid=grid(64), stream=stream0)
        buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        # Topologically Sorted Source Nodes: [th_label, setitem, p_mask, sub_1, mul, logit1, log_softmax, n_mask, sub_3, mul_2, logit2, log_softmax_1], Original ATen: [aten.zeros_like, aten.lift_fresh, aten.fill, aten.add, aten.rsub, aten.mul, aten.sub, aten._log_softmax]
        triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1.run(arg1_1, arg0_1, buf1, buf2, buf4, buf5, 64, grid=grid(64), stream=stream0)
        buf7 = empty_strided_cuda((), (), torch.float32)
        buf8 = buf7; del buf7  # reuse
        # Topologically Sorted Source Nodes: [th_label, setitem, p_mask, sub_1, mul, logit1, log_softmax, mul_1, sum_1, loss1, n_mask, sub_3, mul_2, logit2, log_softmax_1, mul_3, sum_2, loss2, loss, loss_1], Original ATen: [aten.zeros_like, aten.lift_fresh, aten.fill, aten.add, aten.rsub, aten.mul, aten.sub, aten._log_softmax, aten.sum, aten.neg, aten.mean]
        triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2.run(buf8, arg1_1, arg0_1, buf1, buf2, buf4, buf5, 1, 64, grid=grid(1), stream=stream0)
        del arg0_1
        del arg1_1
        del buf1
        del buf2
        del buf4
        del buf5
    return (buf8, )


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
from torch import Tensor
import torch.nn as nn
import torch.nn.functional as F


class ATLoss(nn.Module):

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

    def forward(self, logits: 'Tensor', labels: 'Tensor') ->float:
        """
        Args:
            logits: predicted probabilities (shape: batch size x num classes)
            labels: one-hot encoded true labels (shape: batch size x num classes)
        """
        th_label = torch.zeros_like(labels, dtype=torch.float)
        th_label[:, 0] = 1.0
        labels[:, 0] = 0.0
        p_mask = labels + th_label
        n_mask = 1 - labels
        logit1 = logits - (1 - p_mask) * 1e+30
        loss1 = -(F.log_softmax(logit1, dim=-1) * labels).sum(1)
        logit2 = logits - (1 - n_mask) * 1e+30
        loss2 = -(F.log_softmax(logit2, dim=-1) * th_label).sum(1)
        loss = loss1 + loss2
        loss = loss.mean()
        return loss

    def get_label(self, logits: 'Tensor', num_labels: 'int'=-1, threshold:
        'float'=None) ->Tensor:
        """ Calculated the labels """
        if threshold:
            th_logit = torch.full((len(logits), 1), threshold)
        else:
            th_logit = logits[:, 0].unsqueeze(1)
        output = torch.zeros_like(logits)
        mask = logits > th_logit
        if num_labels > 0:
            top_v, _ = torch.topk(logits, num_labels, dim=1)
            top_v = top_v[:, -1]
            mask = (logits >= top_v.unsqueeze(1)) & mask
        output[mask] = 1.0
        output[:, 0] = output.sum(1) == 0.0
        return output


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 math as tl_math
from torch import Tensor
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_poi_fused_fill_lift_fresh_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    tmp0 = 0.0
    tl.store(out_ptr0 + (x0 + 64 * x1), tmp0, xmask)


@triton.jit
def triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1(
    in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 4 % 4
    tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x3, xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr1 + (1 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp20 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (2 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp28 = tl.load(in_ptr1 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp2 = x1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = tmp2 == tmp3
    tmp5 = 1.0
    tmp6 = 0.0
    tmp7 = tl.where(tmp4, tmp5, tmp6)
    tmp8 = tmp1 + tmp7
    tmp9 = tmp5 - tmp8
    tmp10 = 1e+30
    tmp11 = tmp9 * tmp10
    tmp12 = tmp0 - tmp11
    tmp15 = tmp14 + tmp7
    tmp16 = tmp5 - tmp15
    tmp17 = tmp16 * tmp10
    tmp18 = tmp13 - tmp17
    tmp19 = triton_helpers.maximum(tmp12, tmp18)
    tmp22 = tmp21 + tmp7
    tmp23 = tmp5 - tmp22
    tmp24 = tmp23 * tmp10
    tmp25 = tmp20 - tmp24
    tmp26 = triton_helpers.maximum(tmp19, tmp25)
    tmp29 = tmp28 + tmp7
    tmp30 = tmp5 - tmp29
    tmp31 = tmp30 * tmp10
    tmp32 = tmp27 - tmp31
    tmp33 = triton_helpers.maximum(tmp26, tmp32)
    tmp34 = tmp12 - tmp33
    tmp35 = tl_math.exp(tmp34)
    tmp36 = tmp18 - tmp33
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp25 - tmp33
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tmp42 = tmp32 - tmp33
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp41 + tmp43
    tmp45 = tmp5 - tmp1
    tmp46 = tmp5 - tmp45
    tmp47 = tmp46 * tmp10
    tmp48 = tmp0 - tmp47
    tmp49 = tmp5 - tmp14
    tmp50 = tmp5 - tmp49
    tmp51 = tmp50 * tmp10
    tmp52 = tmp13 - tmp51
    tmp53 = triton_helpers.maximum(tmp48, tmp52)
    tmp54 = tmp5 - tmp21
    tmp55 = tmp5 - tmp54
    tmp56 = tmp55 * tmp10
    tmp57 = tmp20 - tmp56
    tmp58 = triton_helpers.maximum(tmp53, tmp57)
    tmp59 = tmp5 - tmp28
    tmp60 = tmp5 - tmp59
    tmp61 = tmp60 * tmp10
    tmp62 = tmp27 - tmp61
    tmp63 = triton_helpers.maximum(tmp58, tmp62)
    tmp64 = tmp48 - tmp63
    tmp65 = tl_math.exp(tmp64)
    tmp66 = tmp52 - tmp63
    tmp67 = tl_math.exp(tmp66)
    tmp68 = tmp65 + tmp67
    tmp69 = tmp57 - tmp63
    tmp70 = tl_math.exp(tmp69)
    tmp71 = tmp68 + tmp70
    tmp72 = tmp62 - tmp63
    tmp73 = tl_math.exp(tmp72)
    tmp74 = tmp71 + tmp73
    tl.store(out_ptr0 + x3, tmp33, xmask)
    tl.store(out_ptr1 + x3, tmp44, xmask)
    tl.store(out_ptr2 + x3, tmp63, xmask)
    tl.store(out_ptr3 + x3, tmp74, xmask)


@triton.jit
def triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    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)
    r2 = rindex // 16
    r4 = rindex % 16
    r1 = rindex // 4 % 4
    tmp0 = tl.load(in_ptr0 + (r4 + 64 * r2), None)
    tmp1 = tl.load(in_ptr1 + (r4 + 64 * r2), None)
    tmp12 = tl.load(in_ptr2 + (r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr3 + (r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp18 = tl.load(in_ptr0 + (16 + r4 + 64 * r2), None)
    tmp19 = tl.load(in_ptr1 + (16 + r4 + 64 * r2), None)
    tmp27 = tl.load(in_ptr2 + (4 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp29 = tl.load(in_ptr3 + (4 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp34 = tl.load(in_ptr0 + (32 + r4 + 64 * r2), None)
    tmp35 = tl.load(in_ptr1 + (32 + r4 + 64 * r2), None)
    tmp43 = tl.load(in_ptr2 + (8 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp45 = tl.load(in_ptr3 + (8 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (48 + r4 + 64 * r2), None)
    tmp51 = tl.load(in_ptr1 + (48 + r4 + 64 * r2), None)
    tmp59 = tl.load(in_ptr2 + (12 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp61 = tl.load(in_ptr3 + (12 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp70 = tl.load(in_ptr4 + (r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp72 = tl.load(in_ptr5 + (r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp80 = tl.load(in_ptr4 + (4 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp82 = tl.load(in_ptr5 + (4 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp91 = tl.load(in_ptr4 + (8 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp93 = tl.load(in_ptr5 + (8 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp102 = tl.load(in_ptr4 + (12 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp104 = tl.load(in_ptr5 + (12 + r1 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp2 = tl.full([1, 1], 0, tl.int32)
    tmp3 = tmp2 == tmp2
    tmp4 = 1.0
    tmp5 = 0.0
    tmp6 = tl.where(tmp3, tmp4, tmp5)
    tmp7 = tmp1 + tmp6
    tmp8 = tmp4 - tmp7
    tmp9 = 1e+30
    tmp10 = tmp8 * tmp9
    tmp11 = tmp0 - tmp10
    tmp13 = tmp11 - tmp12
    tmp15 = tl_math.log(tmp14)
    tmp16 = tmp13 - tmp15
    tmp17 = tmp16 * tmp1
    tmp20 = tl.full([1, 1], 1, tl.int32)
    tmp21 = tmp20 == tmp2
    tmp22 = tl.where(tmp21, tmp4, tmp5)
    tmp23 = tmp19 + tmp22
    tmp24 = tmp4 - tmp23
    tmp25 = tmp24 * tmp9
    tmp26 = tmp18 - tmp25
    tmp28 = tmp26 - tmp27
    tmp30 = tl_math.log(tmp29)
    tmp31 = tmp28 - tmp30
    tmp32 = tmp31 * tmp19
    tmp33 = tmp17 + tmp32
    tmp36 = tl.full([1, 1], 2, tl.int32)
    tmp37 = tmp36 == tmp2
    tmp38 = tl.where(tmp37, tmp4, tmp5)
    tmp39 = tmp35 + tmp38
    tmp40 = tmp4 - tmp39
    tmp41 = tmp40 * tmp9
    tmp42 = tmp34 - tmp41
    tmp44 = tmp42 - tmp43
    tmp46 = tl_math.log(tmp45)
    tmp47 = tmp44 - tmp46
    tmp48 = tmp47 * tmp35
    tmp49 = tmp33 + tmp48
    tmp52 = tl.full([1, 1], 3, tl.int32)
    tmp53 = tmp52 == tmp2
    tmp54 = tl.where(tmp53, tmp4, tmp5)
    tmp55 = tmp51 + tmp54
    tmp56 = tmp4 - tmp55
    tmp57 = tmp56 * tmp9
    tmp58 = tmp50 - tmp57
    tmp60 = tmp58 - tmp59
    tmp62 = tl_math.log(tmp61)
    tmp63 = tmp60 - tmp62
    tmp64 = tmp63 * tmp51
    tmp65 = tmp49 + tmp64
    tmp66 = tmp4 - tmp1
    tmp67 = tmp4 - tmp66
    tmp68 = tmp67 * tmp9
    tmp69 = tmp0 - tmp68
    tmp71 = tmp69 - tmp70
    tmp73 = tl_math.log(tmp72)
    tmp74 = tmp71 - tmp73
    tmp75 = tmp74 * tmp6
    tmp76 = tmp4 - tmp19
    tmp77 = tmp4 - tmp76
    tmp78 = tmp77 * tmp9
    tmp79 = tmp18 - tmp78
    tmp81 = tmp79 - tmp80
    tmp83 = tl_math.log(tmp82)
    tmp84 = tmp81 - tmp83
    tmp85 = tmp84 * tmp22
    tmp86 = tmp75 + tmp85
    tmp87 = tmp4 - tmp35
    tmp88 = tmp4 - tmp87
    tmp89 = tmp88 * tmp9
    tmp90 = tmp34 - tmp89
    tmp92 = tmp90 - tmp91
    tmp94 = tl_math.log(tmp93)
    tmp95 = tmp92 - tmp94
    tmp96 = tmp95 * tmp38
    tmp97 = tmp86 + tmp96
    tmp98 = tmp4 - tmp51
    tmp99 = tmp4 - tmp98
    tmp100 = tmp99 * tmp9
    tmp101 = tmp50 - tmp100
    tmp103 = tmp101 - tmp102
    tmp105 = tl_math.log(tmp104)
    tmp106 = tmp103 - tmp105
    tmp107 = tmp106 * tmp54
    tmp108 = tmp97 + tmp107
    tmp109 = -tmp65
    tmp110 = -tmp108
    tmp111 = tmp109 + tmp110
    tmp112 = tl.broadcast_to(tmp111, [XBLOCK, RBLOCK])
    tmp114 = tl.sum(tmp112, 1)[:, None]
    tmp115 = 64.0
    tmp116 = tmp114 / tmp115
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp116, 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)
        get_raw_stream(0)
        triton_poi_fused_fill_lift_fresh_0[grid(64)](arg0_1, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        triton_poi_fused__log_softmax_add_fill_lift_fresh_mul_rsub_sub_zeros_like_1[
            grid(64)](arg1_1, arg0_1, buf1, buf2, buf4, buf5, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf7 = empty_strided_cuda((), (), torch.float32)
        buf8 = buf7
        del buf7
        triton_per_fused__log_softmax_add_fill_lift_fresh_mean_mul_neg_rsub_sub_sum_zeros_like_2[
            grid(1)](buf8, arg1_1, arg0_1, buf1, buf2, buf4, buf5, 1, 64,
            XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del buf1
        del buf2
        del buf4
        del buf5
    return buf8,


class ATLossNew(nn.Module):

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

    def get_label(self, logits: 'Tensor', num_labels: 'int'=-1, threshold:
        'float'=None) ->Tensor:
        """ Calculated the labels """
        if threshold:
            th_logit = torch.full((len(logits), 1), threshold)
        else:
            th_logit = logits[:, 0].unsqueeze(1)
        output = torch.zeros_like(logits)
        mask = logits > th_logit
        if num_labels > 0:
            top_v, _ = torch.topk(logits, num_labels, dim=1)
            top_v = top_v[:, -1]
            mask = (logits >= top_v.unsqueeze(1)) & mask
        output[mask] = 1.0
        output[:, 0] = output.sum(1) == 0.0
        return output

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