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
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_mean_mul_sub_sum_1(in_ptr0, in_ptr1,
    in_ptr2, out_ptr1, 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
    r0 = rindex % 16
    tmp0 = tl.load(in_ptr0 + r2, None)
    tmp1 = tl.load(in_ptr1 + r2, None)
    tmp4 = tl.load(in_ptr2 + r2, None)
    tmp5 = tl.load(in_ptr2 + r0, None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr2 + (16 + r0), None, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr2 + (32 + r0), None, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr2 + (48 + r0), None, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (64 + r2), None)
    tmp21 = tl.load(in_ptr1 + (64 + r2), None)
    tmp23 = tl.load(in_ptr2 + (64 + r2), None)
    tmp24 = tl.load(in_ptr2 + (64 + r0), None, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr2 + (80 + r0), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr2 + (96 + r0), None, eviction_policy='evict_last')
    tmp32 = tl.load(in_ptr2 + (112 + r0), None, eviction_policy='evict_last')
    tmp40 = tl.load(in_ptr0 + (128 + r2), None)
    tmp41 = tl.load(in_ptr1 + (128 + r2), None)
    tmp43 = tl.load(in_ptr2 + (128 + r2), None)
    tmp44 = tl.load(in_ptr2 + (128 + r0), None, eviction_policy='evict_last')
    tmp46 = tl.load(in_ptr2 + (144 + r0), None, eviction_policy='evict_last')
    tmp49 = tl.load(in_ptr2 + (160 + r0), None, eviction_policy='evict_last')
    tmp52 = tl.load(in_ptr2 + (176 + r0), None, eviction_policy='evict_last')
    tmp60 = tl.load(in_ptr0 + (192 + r2), None)
    tmp61 = tl.load(in_ptr1 + (192 + r2), None)
    tmp63 = tl.load(in_ptr2 + (192 + r2), None)
    tmp64 = tl.load(in_ptr2 + (192 + r0), None, eviction_policy='evict_last')
    tmp66 = tl.load(in_ptr2 + (208 + r0), None, eviction_policy='evict_last')
    tmp69 = tl.load(in_ptr2 + (224 + r0), None, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr2 + (240 + r0), None, eviction_policy='evict_last')
    tmp2 = 4.0
    tmp3 = tmp1 * tmp2
    tmp6 = tl_math.exp(tmp5)
    tmp8 = tl_math.exp(tmp7)
    tmp9 = tmp6 + tmp8
    tmp11 = tl_math.exp(tmp10)
    tmp12 = tmp9 + tmp11
    tmp14 = tl_math.exp(tmp13)
    tmp15 = tmp12 + tmp14
    tmp16 = tl_math.log(tmp15)
    tmp17 = tmp4 - tmp16
    tmp18 = tmp3 - tmp17
    tmp19 = tmp0 * tmp18
    tmp22 = tmp21 * tmp2
    tmp25 = tl_math.exp(tmp24)
    tmp27 = tl_math.exp(tmp26)
    tmp28 = tmp25 + tmp27
    tmp30 = tl_math.exp(tmp29)
    tmp31 = tmp28 + tmp30
    tmp33 = tl_math.exp(tmp32)
    tmp34 = tmp31 + tmp33
    tmp35 = tl_math.log(tmp34)
    tmp36 = tmp23 - tmp35
    tmp37 = tmp22 - tmp36
    tmp38 = tmp20 * tmp37
    tmp39 = tmp19 + tmp38
    tmp42 = tmp41 * tmp2
    tmp45 = tl_math.exp(tmp44)
    tmp47 = tl_math.exp(tmp46)
    tmp48 = tmp45 + tmp47
    tmp50 = tl_math.exp(tmp49)
    tmp51 = tmp48 + tmp50
    tmp53 = tl_math.exp(tmp52)
    tmp54 = tmp51 + tmp53
    tmp55 = tl_math.log(tmp54)
    tmp56 = tmp43 - tmp55
    tmp57 = tmp42 - tmp56
    tmp58 = tmp40 * tmp57
    tmp59 = tmp39 + tmp58
    tmp62 = tmp61 * tmp2
    tmp65 = tl_math.exp(tmp64)
    tmp67 = tl_math.exp(tmp66)
    tmp68 = tmp65 + tmp67
    tmp70 = tl_math.exp(tmp69)
    tmp71 = tmp68 + tmp70
    tmp73 = tl_math.exp(tmp72)
    tmp74 = tmp71 + tmp73
    tmp75 = tl_math.log(tmp74)
    tmp76 = tmp63 - tmp75
    tmp77 = tmp62 - tmp76
    tmp78 = tmp60 * tmp77
    tmp79 = tmp59 + tmp78
    tmp80 = tmp79 / tmp2
    tmp81 = tl.broadcast_to(tmp80, [XBLOCK, RBLOCK])
    tmp83 = tl.sum(tmp81, 1)[:, None]
    tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp83, None)


def call(args):
    arg0_1, arg1_1, arg2_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))
    assert_size_stride(arg2_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)](arg1_1, buf0, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        del arg1_1
        buf2 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused__log_softmax_mean_mul_sub_sum_1[grid(1)](arg2_1,
            arg0_1, buf0, buf2, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg2_1
        del buf0
    return buf2,


class LossNew(nn.Module):

    def __init__(self, lambd):
        super(LossNew, self).__init__()
        self.lambd = lambd
        self.lsm = nn.LogSoftmax(dim=1)

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


Measured latency_ms: 0.02835