# 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/td/ctdj5kazgiki6gdaadhqtp2x7tq2ee5ey5hqqdcoqmp54jyhf74f.py
# Topologically Sorted Source Nodes: [loss_xent], Original ATen: [aten._log_softmax]
# Source node to ATen node mapping:
#   loss_xent => amax, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax), kwargs = {})
triton_poi_fused__log_softmax_0 = async_compile.triton('triton_poi_fused__log_softmax_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

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


# kernel path: runs/run_shard_8/inductor_cache/dr/cdr2epffppkzs3eh4p3j3fq5zhcqts74dwq3dub3t3js7g4wcyxw.py
# Topologically Sorted Source Nodes: [loss_xent], Original ATen: [aten._log_softmax, aten.mul, aten.sum]
# Source node to ATen node mapping:
#   loss_xent => exp, log_1, mul_2, sub_1, sum_2, sum_3
# Graph fragment:
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %log_1 : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%sum_2,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub, %log_1), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, %arg1_1), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_2,), kwargs = {})
triton_per_fused__log_softmax_mul_sum_1 = async_compile.triton('triton_per_fused__log_softmax_mul_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=[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__log_softmax_mul_sum_1', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 6, '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_mul_sum_1(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)
    r3 = rindex
    r0 = rindex % 16
    r2 = (rindex // 64)
    tmp0 = tl.load(in_ptr0 + (r3), None)
    tmp1 = tl.load(in_ptr0 + (r0 + (64*r2)), None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (16 + r0 + (64*r2)), None, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (32 + r0 + (64*r2)), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (48 + r0 + (64*r2)), None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr1 + (r3), None)
    tmp2 = tl_math.exp(tmp1)
    tmp4 = tl_math.exp(tmp3)
    tmp5 = tmp2 + tmp4
    tmp7 = tl_math.exp(tmp6)
    tmp8 = tmp5 + tmp7
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp8 + tmp10
    tmp12 = tl_math.log(tmp11)
    tmp13 = tmp0 - tmp12
    tmp15 = tmp13 * tmp14
    tmp16 = tl.broadcast_to(tmp15, [RBLOCK])
    tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0))
    tl.store(out_ptr0 + (tl.full([1], 0, tl.int32)), tmp18, None)
''', device_str='cuda')


# kernel path: runs/run_shard_8/inductor_cache/xi/cxipanob2xhnypfqrsuoausp6owujrf32m7lkvfmqipnx2zixnlz.py
# Topologically Sorted Source Nodes: [loss_xent, clamp, log, mul, sum_1, entropy, mean, confidence_penalty, loss], Original ATen: [aten.neg, aten.div, aten.clamp, aten.log, aten.mul, aten.sum, aten.mean, aten.add]
# Source node to ATen node mapping:
#   clamp => clamp_max, clamp_min
#   confidence_penalty => mul_1
#   entropy => neg
#   log => log
#   loss => add
#   loss_xent => div, neg_1
#   mean => mean
#   mul => mul
#   sum_1 => sum_1
# Graph fragment:
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%sum_3,), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Scalar](args = (%neg_1, 64), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%arg0_1, 1e-08), kwargs = {})
#   %clamp_max : [num_users=1] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min, 1.0), kwargs = {})
#   %log : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%clamp_max,), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%arg0_1, %log), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [1]), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%sum_1,), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%neg, [0]), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean, -1.0), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %mul_1), kwargs = {})
triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2 = async_compile.triton('triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 17, '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_add_clamp_div_log_mean_mul_neg_sum_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (x0), xmask)
    tmp7 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp26 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp31 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp37 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp43 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp51 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp56 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp62 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp68 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp76 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp81 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp87 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp93 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp103 = tl.load(in_ptr1 + (0))
    tmp104 = tl.broadcast_to(tmp103, [XBLOCK])
    tmp1 = 1e-08
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp3 = 1.0
    tmp4 = triton_helpers.minimum(tmp2, tmp3)
    tmp5 = tl_math.log(tmp4)
    tmp6 = tmp0 * tmp5
    tmp8 = triton_helpers.maximum(tmp7, tmp1)
    tmp9 = triton_helpers.minimum(tmp8, tmp3)
    tmp10 = tl_math.log(tmp9)
    tmp11 = tmp7 * tmp10
    tmp12 = tmp6 + tmp11
    tmp14 = triton_helpers.maximum(tmp13, tmp1)
    tmp15 = triton_helpers.minimum(tmp14, tmp3)
    tmp16 = tl_math.log(tmp15)
    tmp17 = tmp13 * tmp16
    tmp18 = tmp12 + tmp17
    tmp20 = triton_helpers.maximum(tmp19, tmp1)
    tmp21 = triton_helpers.minimum(tmp20, tmp3)
    tmp22 = tl_math.log(tmp21)
    tmp23 = tmp19 * tmp22
    tmp24 = tmp18 + tmp23
    tmp25 = -tmp24
    tmp27 = triton_helpers.maximum(tmp26, tmp1)
    tmp28 = triton_helpers.minimum(tmp27, tmp3)
    tmp29 = tl_math.log(tmp28)
    tmp30 = tmp26 * tmp29
    tmp32 = triton_helpers.maximum(tmp31, tmp1)
    tmp33 = triton_helpers.minimum(tmp32, tmp3)
    tmp34 = tl_math.log(tmp33)
    tmp35 = tmp31 * tmp34
    tmp36 = tmp30 + tmp35
    tmp38 = triton_helpers.maximum(tmp37, tmp1)
    tmp39 = triton_helpers.minimum(tmp38, tmp3)
    tmp40 = tl_math.log(tmp39)
    tmp41 = tmp37 * tmp40
    tmp42 = tmp36 + tmp41
    tmp44 = triton_helpers.maximum(tmp43, tmp1)
    tmp45 = triton_helpers.minimum(tmp44, tmp3)
    tmp46 = tl_math.log(tmp45)
    tmp47 = tmp43 * tmp46
    tmp48 = tmp42 + tmp47
    tmp49 = -tmp48
    tmp50 = tmp25 + tmp49
    tmp52 = triton_helpers.maximum(tmp51, tmp1)
    tmp53 = triton_helpers.minimum(tmp52, tmp3)
    tmp54 = tl_math.log(tmp53)
    tmp55 = tmp51 * tmp54
    tmp57 = triton_helpers.maximum(tmp56, tmp1)
    tmp58 = triton_helpers.minimum(tmp57, tmp3)
    tmp59 = tl_math.log(tmp58)
    tmp60 = tmp56 * tmp59
    tmp61 = tmp55 + tmp60
    tmp63 = triton_helpers.maximum(tmp62, tmp1)
    tmp64 = triton_helpers.minimum(tmp63, tmp3)
    tmp65 = tl_math.log(tmp64)
    tmp66 = tmp62 * tmp65
    tmp67 = tmp61 + tmp66
    tmp69 = triton_helpers.maximum(tmp68, tmp1)
    tmp70 = triton_helpers.minimum(tmp69, tmp3)
    tmp71 = tl_math.log(tmp70)
    tmp72 = tmp68 * tmp71
    tmp73 = tmp67 + tmp72
    tmp74 = -tmp73
    tmp75 = tmp50 + tmp74
    tmp77 = triton_helpers.maximum(tmp76, tmp1)
    tmp78 = triton_helpers.minimum(tmp77, tmp3)
    tmp79 = tl_math.log(tmp78)
    tmp80 = tmp76 * tmp79
    tmp82 = triton_helpers.maximum(tmp81, tmp1)
    tmp83 = triton_helpers.minimum(tmp82, tmp3)
    tmp84 = tl_math.log(tmp83)
    tmp85 = tmp81 * tmp84
    tmp86 = tmp80 + tmp85
    tmp88 = triton_helpers.maximum(tmp87, tmp1)
    tmp89 = triton_helpers.minimum(tmp88, tmp3)
    tmp90 = tl_math.log(tmp89)
    tmp91 = tmp87 * tmp90
    tmp92 = tmp86 + tmp91
    tmp94 = triton_helpers.maximum(tmp93, tmp1)
    tmp95 = triton_helpers.minimum(tmp94, tmp3)
    tmp96 = tl_math.log(tmp95)
    tmp97 = tmp93 * tmp96
    tmp98 = tmp92 + tmp97
    tmp99 = -tmp98
    tmp100 = tmp75 + tmp99
    tmp101 = 4.0
    tmp102 = tmp100 / tmp101
    tmp105 = -tmp104
    tmp106 = 0.015625
    tmp107 = tmp105 * tmp106
    tmp108 = -1.0
    tmp109 = tmp102 * tmp108
    tmp110 = tmp107 + tmp109
    tl.store(in_out_ptr0 + (x0), tmp110, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 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, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [loss_xent], Original ATen: [aten._log_softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__log_softmax_0.run(arg0_1, buf0, 256, grid=grid(256), stream=stream0)
        buf1 = empty_strided_cuda((), (), torch.float32)
        # Topologically Sorted Source Nodes: [loss_xent], Original ATen: [aten._log_softmax, aten.mul, aten.sum]
        triton_per_fused__log_softmax_mul_sum_1.run(buf0, arg1_1, buf1, 1, 256, grid=grid(1), stream=stream0)
        del arg1_1
        del buf0
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = buf2; del buf2  # reuse
        # Topologically Sorted Source Nodes: [loss_xent, clamp, log, mul, sum_1, entropy, mean, confidence_penalty, loss], Original ATen: [aten.neg, aten.div, aten.clamp, aten.log, aten.mul, aten.sum, aten.mean, aten.add]
        triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2.run(buf3, arg0_1, buf1, 16, grid=grid(16), stream=stream0)
        del arg0_1
        del buf1
    return (buf3, )


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.utils.data
from torch import nn


class ConfidencePenalty(nn.Module):
    """Cross entropy loss with label smoothing regularizer.

    Reference:
    Szegedy et al. Rethinking the Inception Architecture for Computer Vision. CVPR 2016.
    Equation: y = (1 - epsilon) * y + epsilon / K.

    Args:
        num_classes (int): number of classes.
        epsilon (float): weight.
    """

    def __init__(self, epsilon=1.0, device='cpu'):
        super(ConfidencePenalty, self).__init__()
        self.epsilon = epsilon
        self.device = device
        self.logsoftmax = nn.LogSoftmax()
        self.baseloss = nn.CrossEntropyLoss()

    def forward(self, inputs, targets):
        """
        Args:
            inputs: prediction matrix (before softmax) with shape (batch_size, num_classes)
            targets: ground truth labels with shape (num_classes)
        """
        entropy = -torch.sum(inputs * torch.log(inputs.clamp(min=1e-08, max
            =1.0)), dim=1)
        confidence_penalty = -self.epsilon * entropy.mean(0)
        loss_xent = self.baseloss(inputs, targets)
        loss = loss_xent + confidence_penalty
        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 math as tl_math
import torch.utils.data
from torch import 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__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tl.store(out_ptr0 + x3, tmp8, xmask)


@triton.jit
def triton_per_fused__log_softmax_mul_sum_1(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)
    r3 = rindex
    r0 = rindex % 16
    r2 = rindex // 64
    tmp0 = tl.load(in_ptr0 + r3, None)
    tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
        )
    tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr1 + r3, None)
    tmp2 = tl_math.exp(tmp1)
    tmp4 = tl_math.exp(tmp3)
    tmp5 = tmp2 + tmp4
    tmp7 = tl_math.exp(tmp6)
    tmp8 = tmp5 + tmp7
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp8 + tmp10
    tmp12 = tl_math.log(tmp11)
    tmp13 = tmp0 - tmp12
    tmp15 = tmp13 * tmp14
    tmp16 = tl.broadcast_to(tmp15, [RBLOCK])
    tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0))
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None)


@triton.jit
def triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2(in_out_ptr0,
    in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp7 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp26 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp31 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp37 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp43 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp51 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp56 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp62 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp68 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp76 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp81 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp87 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp93 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp103 = tl.load(in_ptr1 + 0)
    tmp104 = tl.broadcast_to(tmp103, [XBLOCK])
    tmp1 = 1e-08
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp3 = 1.0
    tmp4 = triton_helpers.minimum(tmp2, tmp3)
    tmp5 = tl_math.log(tmp4)
    tmp6 = tmp0 * tmp5
    tmp8 = triton_helpers.maximum(tmp7, tmp1)
    tmp9 = triton_helpers.minimum(tmp8, tmp3)
    tmp10 = tl_math.log(tmp9)
    tmp11 = tmp7 * tmp10
    tmp12 = tmp6 + tmp11
    tmp14 = triton_helpers.maximum(tmp13, tmp1)
    tmp15 = triton_helpers.minimum(tmp14, tmp3)
    tmp16 = tl_math.log(tmp15)
    tmp17 = tmp13 * tmp16
    tmp18 = tmp12 + tmp17
    tmp20 = triton_helpers.maximum(tmp19, tmp1)
    tmp21 = triton_helpers.minimum(tmp20, tmp3)
    tmp22 = tl_math.log(tmp21)
    tmp23 = tmp19 * tmp22
    tmp24 = tmp18 + tmp23
    tmp25 = -tmp24
    tmp27 = triton_helpers.maximum(tmp26, tmp1)
    tmp28 = triton_helpers.minimum(tmp27, tmp3)
    tmp29 = tl_math.log(tmp28)
    tmp30 = tmp26 * tmp29
    tmp32 = triton_helpers.maximum(tmp31, tmp1)
    tmp33 = triton_helpers.minimum(tmp32, tmp3)
    tmp34 = tl_math.log(tmp33)
    tmp35 = tmp31 * tmp34
    tmp36 = tmp30 + tmp35
    tmp38 = triton_helpers.maximum(tmp37, tmp1)
    tmp39 = triton_helpers.minimum(tmp38, tmp3)
    tmp40 = tl_math.log(tmp39)
    tmp41 = tmp37 * tmp40
    tmp42 = tmp36 + tmp41
    tmp44 = triton_helpers.maximum(tmp43, tmp1)
    tmp45 = triton_helpers.minimum(tmp44, tmp3)
    tmp46 = tl_math.log(tmp45)
    tmp47 = tmp43 * tmp46
    tmp48 = tmp42 + tmp47
    tmp49 = -tmp48
    tmp50 = tmp25 + tmp49
    tmp52 = triton_helpers.maximum(tmp51, tmp1)
    tmp53 = triton_helpers.minimum(tmp52, tmp3)
    tmp54 = tl_math.log(tmp53)
    tmp55 = tmp51 * tmp54
    tmp57 = triton_helpers.maximum(tmp56, tmp1)
    tmp58 = triton_helpers.minimum(tmp57, tmp3)
    tmp59 = tl_math.log(tmp58)
    tmp60 = tmp56 * tmp59
    tmp61 = tmp55 + tmp60
    tmp63 = triton_helpers.maximum(tmp62, tmp1)
    tmp64 = triton_helpers.minimum(tmp63, tmp3)
    tmp65 = tl_math.log(tmp64)
    tmp66 = tmp62 * tmp65
    tmp67 = tmp61 + tmp66
    tmp69 = triton_helpers.maximum(tmp68, tmp1)
    tmp70 = triton_helpers.minimum(tmp69, tmp3)
    tmp71 = tl_math.log(tmp70)
    tmp72 = tmp68 * tmp71
    tmp73 = tmp67 + tmp72
    tmp74 = -tmp73
    tmp75 = tmp50 + tmp74
    tmp77 = triton_helpers.maximum(tmp76, tmp1)
    tmp78 = triton_helpers.minimum(tmp77, tmp3)
    tmp79 = tl_math.log(tmp78)
    tmp80 = tmp76 * tmp79
    tmp82 = triton_helpers.maximum(tmp81, tmp1)
    tmp83 = triton_helpers.minimum(tmp82, tmp3)
    tmp84 = tl_math.log(tmp83)
    tmp85 = tmp81 * tmp84
    tmp86 = tmp80 + tmp85
    tmp88 = triton_helpers.maximum(tmp87, tmp1)
    tmp89 = triton_helpers.minimum(tmp88, tmp3)
    tmp90 = tl_math.log(tmp89)
    tmp91 = tmp87 * tmp90
    tmp92 = tmp86 + tmp91
    tmp94 = triton_helpers.maximum(tmp93, tmp1)
    tmp95 = triton_helpers.minimum(tmp94, tmp3)
    tmp96 = tl_math.log(tmp95)
    tmp97 = tmp93 * tmp96
    tmp98 = tmp92 + tmp97
    tmp99 = -tmp98
    tmp100 = tmp75 + tmp99
    tmp101 = 4.0
    tmp102 = tmp100 / tmp101
    tmp105 = -tmp104
    tmp106 = 0.015625
    tmp107 = tmp105 * tmp106
    tmp108 = -1.0
    tmp109 = tmp102 * tmp108
    tmp110 = tmp107 + tmp109
    tl.store(in_out_ptr0 + x0, tmp110, xmask)


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, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused__log_softmax_mul_sum_1[grid(1)](buf0, arg1_1, buf1,
            1, 256, num_warps=2, num_stages=1)
        del arg1_1
        del buf0
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = buf2
        del buf2
        triton_poi_fused_add_clamp_div_log_mean_mul_neg_sum_2[grid(16)](buf3,
            arg0_1, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del arg0_1
        del buf1
    return buf3,


class ConfidencePenaltyNew(nn.Module):
    """Cross entropy loss with label smoothing regularizer.

    Reference:
    Szegedy et al. Rethinking the Inception Architecture for Computer Vision. CVPR 2016.
    Equation: y = (1 - epsilon) * y + epsilon / K.

    Args:
        num_classes (int): number of classes.
        epsilon (float): weight.
    """

    def __init__(self, epsilon=1.0, device='cpu'):
        super(ConfidencePenaltyNew, self).__init__()
        self.epsilon = epsilon
        self.device = device
        self.logsoftmax = nn.LogSoftmax()
        self.baseloss = nn.CrossEntropyLoss()

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