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]


Measured latency_ms: 0.016792